From 15cbce6872a5fc26b25a29b8ea849821d7fdfe47 Mon Sep 17 00:00:00 2001 From: Warren Parad Date: Tue, 8 Oct 2024 14:43:49 +0200 Subject: [PATCH] Fix xunit tests. --- .../Api/ResourcePermissionsApi.cs | 112 +++++++++--------- .../Api/UserPermissions/AuthorizeUserTests.cs | 2 +- tests/Authress.SDK/TestData.cs | 20 ++-- .../AuthressClientTokenProviderTests.cs | 53 +++++++++ 4 files changed, 120 insertions(+), 67 deletions(-) create mode 100644 testsIntegration/AuthressClientTokenProviderTests.cs diff --git a/src/Authress.SDK/Api/ResourcePermissionsApi.cs b/src/Authress.SDK/Api/ResourcePermissionsApi.cs index fce6704..3748a11 100644 --- a/src/Authress.SDK/Api/ResourcePermissionsApi.cs +++ b/src/Authress.SDK/Api/ResourcePermissionsApi.cs @@ -9,66 +9,66 @@ namespace Authress.SDK { - /// - /// Represents a collection of functions to interact with the API endpoints - /// - internal partial class AuthressClient : IResourcePermissionsApi - { - /// - /// List resource configurations Permissions can be set globally at a resource level. Lists any resources with a globally set resource policy - /// - /// ResourcePermissionCollection - public async Task GetResources () - { + // /// + // /// Represents a collection of functions to interact with the API endpoints + // /// + // internal partial class AuthressClient : IResourcePermissionsApi + // { + // /// + // /// List resource configurations Permissions can be set globally at a resource level. Lists any resources with a globally set resource policy + // /// + // /// ResourcePermissionCollection + // public async Task GetResources () + // { - var path = "/v1/resources"; - var client = await authressHttpClientProvider.GetHttpClientAsync(); - using (var response = await client.GetAsync(path)) - { - await response.ThrowIfNotSuccessStatusCode(); - return await response.Content.ReadAsAsync(); - } - } + // var path = "/v1/resources"; + // var client = await authressHttpClientProvider.GetHttpClientAsync(); + // using (var response = await client.GetAsync(path)) + // { + // await response.ThrowIfNotSuccessStatusCode(); + // return await response.Content.ReadAsAsync(); + // } + // } - /// - /// Get a resource permissions object. Permissions can be set globally at a resource level. This will apply to all users in an account. - /// - /// The uri path of a resource to validate, uri segments are allowed. - /// ResourcePermission - public async Task GetResourcePermissions (string resourceUri) - { - // verify the required parameter 'resourceUri' is set - if (resourceUri == null) throw new ArgumentNullException("Missing required parameter 'resourceUri'."); + // /// + // /// Get a resource permissions object. Permissions can be set globally at a resource level. This will apply to all users in an account. + // /// + // /// The uri path of a resource to validate, uri segments are allowed. + // /// ResourcePermission + // public async Task GetResourcePermissions (string resourceUri) + // { + // // verify the required parameter 'resourceUri' is set + // if (resourceUri == null) throw new ArgumentNullException("Missing required parameter 'resourceUri'."); - var path = $"/v1/resources/{System.Web.HttpUtility.UrlEncode(resourceUri)}"; - var client = await authressHttpClientProvider.GetHttpClientAsync(); - using (var response = await client.GetAsync(path)) - { - await response.ThrowIfNotSuccessStatusCode(); - return await response.Content.ReadAsAsync(); - } - } + // var path = $"/v1/resources/{System.Web.HttpUtility.UrlEncode(resourceUri)}"; + // var client = await authressHttpClientProvider.GetHttpClientAsync(); + // using (var response = await client.GetAsync(path)) + // { + // await response.ThrowIfNotSuccessStatusCode(); + // return await response.Content.ReadAsAsync(); + // } + // } - /// - /// Update a resource permissions object. Updates the global permissions on a resource. This applies to all users in an account. - /// - /// The contents of the permission to set on the resource. Overwrites existing data. - /// The uri path of a resource to validate, uri segments are allowed. - /// Object - public async Task SetResourcePermissions (string resourceUri, ResourcePermission body) - { - // verify the required parameter 'body' is set - if (body == null) throw new ArgumentNullException("Missing required parameter 'body'."); - // verify the required parameter 'resourceUri' is set - if (resourceUri == null) throw new ArgumentNullException("Missing required parameter 'resourceUri'."); + // /// + // /// Update a resource permissions object. Updates the global permissions on a resource. This applies to all users in an account. + // /// + // /// The contents of the permission to set on the resource. Overwrites existing data. + // /// The uri path of a resource to validate, uri segments are allowed. + // /// Object + // public async Task SetResourcePermissions (string resourceUri, ResourcePermission body) + // { + // // verify the required parameter 'body' is set + // if (body == null) throw new ArgumentNullException("Missing required parameter 'body'."); + // // verify the required parameter 'resourceUri' is set + // if (resourceUri == null) throw new ArgumentNullException("Missing required parameter 'resourceUri'."); - var path = $"/v1/resources/{System.Web.HttpUtility.UrlEncode(resourceUri)}"; - var client = await authressHttpClientProvider.GetHttpClientAsync(); - using (var response = await client.PutAsync(path, body.ToHttpContent())) - { - await response.ThrowIfNotSuccessStatusCode(); - } - } + // var path = $"/v1/resources/{System.Web.HttpUtility.UrlEncode(resourceUri)}"; + // var client = await authressHttpClientProvider.GetHttpClientAsync(); + // using (var response = await client.PutAsync(path, body.ToHttpContent())) + // { + // await response.ThrowIfNotSuccessStatusCode(); + // } + // } - } + // } } diff --git a/tests/Authress.SDK/Api/UserPermissions/AuthorizeUserTests.cs b/tests/Authress.SDK/Api/UserPermissions/AuthorizeUserTests.cs index eded50e..7d3f0ca 100644 --- a/tests/Authress.SDK/Api/UserPermissions/AuthorizeUserTests.cs +++ b/tests/Authress.SDK/Api/UserPermissions/AuthorizeUserTests.cs @@ -27,7 +27,7 @@ public class TestCase public string Permission { get; set; } } - public static TestData TestCases = new TestData + public static TestData TestCases => new TestData { { "Expect cached value to be returned", diff --git a/tests/Authress.SDK/TestData.cs b/tests/Authress.SDK/TestData.cs index f2df05c..0ddd8e7 100644 --- a/tests/Authress.SDK/TestData.cs +++ b/tests/Authress.SDK/TestData.cs @@ -6,16 +6,16 @@ namespace Authress.SDK.UnitTests /// Represents a set of data for a theory. Data can be added to the data set using the collection initializer syntax. /// /// - public class TestData : TheoryData + public class TestData : TheoryData { - /// - /// Adds a theory to the Test - /// - /// Name of the Test - /// Data used in the Test - public void Add(string testName, T testObject) - { - AddRow(testName, testObject); - } + // /// + // /// Adds a theory to the Test + // /// + // /// Name of the Test + // /// Data used in the Test + // public void Add(string testName, T testObject) + // { + // AddRow(testName, testObject); + // } } } diff --git a/testsIntegration/AuthressClientTokenProviderTests.cs b/testsIntegration/AuthressClientTokenProviderTests.cs new file mode 100644 index 0000000..33a7154 --- /dev/null +++ b/testsIntegration/AuthressClientTokenProviderTests.cs @@ -0,0 +1,53 @@ +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Threading.Tasks; +using FluentAssertions; +using Moq; +using Xunit; +using Authress.SDK; +using Authress.SDK.Client; + +namespace Authress.SDK.UnitTests +{ + public class AuthressClientTokenProviderTests + { + private const string userId = "unit-test-user-id"; + + public class TestCase + { + public string AccessKey { get; set; } + } + + public static TestData TestCases = new TestData + { + { + "EdDSA", + new TestCase{ AccessKey = "KEY" } + } + }; + + [Theory, MemberData(nameof(TestCases))] + public async Task GetBearerToken(string testName, TestCase testCase) + { + var tokenProvider = new AuthressClientTokenProvider(testCase.AccessKey); + var token = await tokenProvider.GetBearerToken(); + System.Console.WriteLine(token); + + tokenProvider.Should().NotBeNull(testName, testCase); + + var authressSettings = new AuthressSettings { AuthressApiUrl = "DOMAIN", }; + var authressClient = new AuthressClient(tokenProvider, authressSettings); + var result = await authressClient.GetUserResources("user_001", "resources/*/sub", "edit", DTO.CollectionConfigurationEnum.INCLUDE_NESTED); + await authressClient.GetUserResources("user_001", "resources/*/sub", "edit", DTO.CollectionConfigurationEnum.INCLUDE_NESTED); + await authressClient.GetUserResources("user_001", "resources/*/sub", "edit", DTO.CollectionConfigurationEnum.INCLUDE_NESTED); + await authressClient.GetUserResources("user_001", "resources/*/sub", "edit", DTO.CollectionConfigurationEnum.INCLUDE_NESTED); + await authressClient.GetUserResources("user_001", "resources/*/sub", "edit", DTO.CollectionConfigurationEnum.INCLUDE_NESTED); + await authressClient.GetUserResources("user_001", "resources/*/sub", "edit", DTO.CollectionConfigurationEnum.INCLUDE_NESTED); + System.Console.WriteLine(string.Join(", ", result.Resources.Select(s => s.ResourceUri))); + + var token2 = await tokenProvider.GetBearerToken(); + System.Console.WriteLine(token2); + } + } +}