From e935add5028d490dc9f38ec45fb47fc33ac966e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9rald=20Barr=C3=A9?= Date: Mon, 5 Aug 2024 14:54:00 -0400 Subject: [PATCH] More formatting --- .../AuthorizationExtensionsTest.cs | 2 +- .../IntegrationTests.cs | 4 ++-- .../OpenAPI/OpenApiSecurityDescriptionTests.cs | 8 ++++---- .../RequireClientCredentialsAttributeTests.cs | 4 ++-- ...reClientCredentialsRequirementHandlerTests.cs | 16 ++++++++-------- .../Endpoints/ClientCredentialsController.cs | 2 +- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Workleap.Authentication.ClientCredentialsGrant.Tests/AuthorizationExtensionsTest.cs b/src/Workleap.Authentication.ClientCredentialsGrant.Tests/AuthorizationExtensionsTest.cs index 993fc12..20e3370 100644 --- a/src/Workleap.Authentication.ClientCredentialsGrant.Tests/AuthorizationExtensionsTest.cs +++ b/src/Workleap.Authentication.ClientCredentialsGrant.Tests/AuthorizationExtensionsTest.cs @@ -91,7 +91,7 @@ private static void ValidateClassicPolicy(AuthorizationPolicy? policy, ClientCre Assert.Equal($"{DefaultAudience}:{AuthorizationExtensions.ScopeClaimMapping[scope]}", allowedScope); }); } - + private static void ValidateRequireClientCredentialsPolicy(AuthorizationPolicy? policy) { Assert.NotNull(policy); diff --git a/src/Workleap.Authentication.ClientCredentialsGrant.Tests/IntegrationTests.cs b/src/Workleap.Authentication.ClientCredentialsGrant.Tests/IntegrationTests.cs index c769522..bae511c 100644 --- a/src/Workleap.Authentication.ClientCredentialsGrant.Tests/IntegrationTests.cs +++ b/src/Workleap.Authentication.ClientCredentialsGrant.Tests/IntegrationTests.cs @@ -1,4 +1,4 @@ -using System.Collections.Concurrent; +using System.Collections.Concurrent; using System.Net; using Duende.IdentityServer.Models; using Duende.IdentityServer.Stores; @@ -152,7 +152,7 @@ public async Task Real_Client_Server_Communication() // Using the classic policy, reading invoices should be successful because we're authenticated with a JWT that has the "invoices" audience and "invoices.read" scope var readInvoicesResponse = await invoicesReadHttpClient.GetStringAsync("https://invoice-app.local/read-invoices", cts.Token); Assert.Equal("This protected endpoint is for reading invoices", readInvoicesResponse); - + // Using the granular policy, reading invoices should be successful because we're authenticated with a JWT that has the "invoices" audience and "invoices.read" scope var readInvoicesGranularResponse = await invoicesReadHttpClient.GetStringAsync("https://invoice-app.local/read-invoices-granular", cts.Token); Assert.Equal("This protected endpoint is for reading invoices", readInvoicesGranularResponse); diff --git a/src/Workleap.Authentication.ClientCredentialsGrant.Tests/OpenAPI/OpenApiSecurityDescriptionTests.cs b/src/Workleap.Authentication.ClientCredentialsGrant.Tests/OpenAPI/OpenApiSecurityDescriptionTests.cs index 45738d0..3cceb3e 100644 --- a/src/Workleap.Authentication.ClientCredentialsGrant.Tests/OpenAPI/OpenApiSecurityDescriptionTests.cs +++ b/src/Workleap.Authentication.ClientCredentialsGrant.Tests/OpenAPI/OpenApiSecurityDescriptionTests.cs @@ -1,4 +1,4 @@ -using CliWrap; +using CliWrap; using Meziantou.Framework; namespace Workleap.Authentication.ClientCredentialsGrant.Tests.OpenAPI; @@ -9,7 +9,7 @@ public class OpenApiSecurityDescriptionTests public async Task Given_API_With_Client_Credentials_Attribute_When_Generating_OpenAPI_Then_Equal_Expected_Document() { var solutionPath = GetSolutionPath(); - + var testsFolder = Path.Combine(solutionPath, "tests"); var projectFolder = Path.Combine(testsFolder, "WebApi.OpenAPI.SystemTest"); var generatedFilePath = Path.Combine(projectFolder, "openapi-v1.yaml"); @@ -31,12 +31,12 @@ public async Task Given_API_With_Client_Credentials_Attribute_When_Generating_Op Assert.Equal(expectedFileContent, generatedFileContent, ignoreLineEndingDifferences: true); } - + private static string GetSolutionPath() { return GetGitRoot() / "src"; } - + private static FullPath GetGitRoot() { if (FullPath.CurrentDirectory().TryFindFirstAncestorOrSelf(current => Directory.Exists(current / ".git"), out var root)) diff --git a/src/Workleap.Authentication.ClientCredentialsGrant.Tests/RequireClientCredentialsAttributeTests.cs b/src/Workleap.Authentication.ClientCredentialsGrant.Tests/RequireClientCredentialsAttributeTests.cs index 3a8d626..8f91f45 100644 --- a/src/Workleap.Authentication.ClientCredentialsGrant.Tests/RequireClientCredentialsAttributeTests.cs +++ b/src/Workleap.Authentication.ClientCredentialsGrant.Tests/RequireClientCredentialsAttributeTests.cs @@ -1,4 +1,4 @@ -using System.Collections; +using System.Collections; using Microsoft.AspNetCore.Authorization; using Workleap.AspNetCore.Authentication.ClientCredentialsGrant; @@ -20,7 +20,7 @@ public void GivenInvalidClassicScope_WhenCreate_ThenThrowArgumentException() var scope = (ClientCredentialsScope)999; Assert.Throws(() => new RequireClientCredentialsAttribute(scope)); } - + [Fact] public void GivenSinglePermission_WhenCreate_ThenSamePermission() { diff --git a/src/Workleap.Authentication.ClientCredentialsGrant.Tests/RequireClientCredentialsRequirementHandlerTests.cs b/src/Workleap.Authentication.ClientCredentialsGrant.Tests/RequireClientCredentialsRequirementHandlerTests.cs index bed3881..76c3c65 100644 --- a/src/Workleap.Authentication.ClientCredentialsGrant.Tests/RequireClientCredentialsRequirementHandlerTests.cs +++ b/src/Workleap.Authentication.ClientCredentialsGrant.Tests/RequireClientCredentialsRequirementHandlerTests.cs @@ -1,4 +1,4 @@ -using System.Security.Claims; +using System.Security.Claims; using FakeItEasy; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authorization; @@ -35,7 +35,7 @@ public async Task GivenUserHaveTheRequiredScopesInOneOfClaimType_WhenHandleRequi // Then Assert.True(context.HasSucceeded); } - + [Theory] [InlineData(true)] [InlineData(false)] @@ -43,13 +43,13 @@ public async Task GivenUserHaveOneOfTheRequiredScopes_WhenHandleRequirement_Then { // Given var expectedAudience = "invoices"; - + var userClaims = new List { new("scope", usePrefixAudienceFormat ? $"{expectedAudience}:requiredPermission" : "requiredPermission"), new("scope", "otherPermission"), }; - + var requiredPermission = "requiredPermission"; var context = ConfigureHandlerContext(userClaims, requiredPermission); @@ -64,7 +64,7 @@ public async Task GivenUserHaveOneOfTheRequiredScopes_WhenHandleRequirement_Then // Then Assert.True(context.HasSucceeded); } - + [Fact] public async Task GivenUserDoNotHaveTheRequiredScopes_WhenHandleRequirement_ThenNotSucceeded() { @@ -86,12 +86,12 @@ public async Task GivenUserDoNotHaveTheRequiredScopes_WhenHandleRequirement_Then // Then Assert.False(context.HasSucceeded); } - + private static RequireClientCredentialsRequirementHandler ConfigureHandler(JwtBearerOptions jwtOptions) { var jwtOptionsMonitor = A.Fake>(); A.CallTo(() => jwtOptionsMonitor.Get(ClientCredentialsDefaults.AuthenticationScheme)).Returns(jwtOptions); - + return new RequireClientCredentialsRequirementHandler(jwtOptionsMonitor); } @@ -108,7 +108,7 @@ private static AuthorizationHandlerContext ConfigureHandlerContext(List c return new AuthorizationHandlerContext(new[] { new RequireClientCredentialsRequirement() }, user, httpContext); } - + private sealed class EndpointFeature : IEndpointFeature { public Endpoint? Endpoint { get; set; } diff --git a/src/tests/WebApi.OpenAPI.SystemTest/Endpoints/ClientCredentialsController.cs b/src/tests/WebApi.OpenAPI.SystemTest/Endpoints/ClientCredentialsController.cs index 0f1fa84..f36e2da 100644 --- a/src/tests/WebApi.OpenAPI.SystemTest/Endpoints/ClientCredentialsController.cs +++ b/src/tests/WebApi.OpenAPI.SystemTest/Endpoints/ClientCredentialsController.cs @@ -17,7 +17,7 @@ public IActionResult SeeCocktail(int id) { return this.Ok("Hello World!"); } - + [HttpPost] [Route("/controller-requires-permission")] [SwaggerOperation(Summary = "This controller method should require the cocktail.buy permission.")]