From 95256b9db77365fba9b90f57870076f5d5c746ef Mon Sep 17 00:00:00 2001 From: kailash-b Date: Mon, 17 Mar 2025 17:57:35 +0530 Subject: [PATCH 1/2] Use Utc.now to avoid test failures in certain timezones --- .../Auth0MiddlewareTests.cs | 26 +++++++++---------- .../TokenValidationTests.cs | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/Auth0.AspNetCore.Authentication.IntegrationTests/Auth0MiddlewareTests.cs b/tests/Auth0.AspNetCore.Authentication.IntegrationTests/Auth0MiddlewareTests.cs index 025542c..52e3593 100644 --- a/tests/Auth0.AspNetCore.Authentication.IntegrationTests/Auth0MiddlewareTests.cs +++ b/tests/Auth0.AspNetCore.Authentication.IntegrationTests/Auth0MiddlewareTests.cs @@ -1092,8 +1092,8 @@ public async void Should_Refresh_Access_Token_When_Expired() var mockHandler = new OidcMockBuilder() .MockOpenIdConfig() .MockJwks() - .MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, nonce, DateTime.Now.AddSeconds(20)), (me) => me.HasGrantType("authorization_code"), 20) - .MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, null, DateTime.Now.AddSeconds(20)), (me) => me.HasGrantType("refresh_token") && me.HasClientSecret(), 20) + .MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, nonce, DateTime.UtcNow.AddSeconds(20)), (me) => me.HasGrantType("authorization_code"), 20) + .MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, null, DateTime.UtcNow.AddSeconds(20)), (me) => me.HasGrantType("refresh_token") && me.HasClientSecret(), 20) .Build(); using (var server = TestServerBuilder.CreateServer(opts => { @@ -1148,8 +1148,8 @@ public async void Should_Refresh_Access_Token_When_Expired_Using_Client_Assertio var mockHandler = new OidcMockBuilder() .MockOpenIdConfig() .MockJwks() - .MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, nonce, DateTime.Now.AddSeconds(20)), (me) => me.HasGrantType("authorization_code"), 20) - .MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, null, DateTime.Now.AddSeconds(20)), (me) => me.HasGrantType("refresh_token") && me.HasClientAssertion(), 20) + .MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, nonce, DateTime.UtcNow.AddSeconds(20)), (me) => me.HasGrantType("authorization_code"), 20) + .MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, null, DateTime.UtcNow.AddSeconds(20)), (me) => me.HasGrantType("refresh_token") && me.HasClientAssertion(), 20) .Build(); using (var server = TestServerBuilder.CreateServer(opts => { @@ -1205,8 +1205,8 @@ public async void Should_Update_Refresh_Token_When_Used() var mockHandler = new OidcMockBuilder() .MockOpenIdConfig() .MockJwks() - .MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, nonce, DateTime.Now.AddSeconds(20)), (me) => me.HasGrantType("authorization_code"), 20) - .MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, null, DateTime.Now.AddSeconds(20)), (me) => me.HasGrantType("refresh_token"), 20, true, HttpStatusCode.OK, "456_ROTATED") + .MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, nonce, DateTime.UtcNow.AddSeconds(20)), (me) => me.HasGrantType("authorization_code"), 20) + .MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, null, DateTime.UtcNow.AddSeconds(20)), (me) => me.HasGrantType("refresh_token"), 20, true, HttpStatusCode.OK, "456_ROTATED") .Build(); using (var server = TestServerBuilder.CreateServer(opts => @@ -1265,8 +1265,8 @@ public async void Should_Not_Update_Refresh_Token_When_Used_But_Not_Returned() var mockHandler = new OidcMockBuilder() .MockOpenIdConfig() .MockJwks() - .MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, nonce, DateTime.Now.AddSeconds(20)), (me) => me.HasGrantType("authorization_code"), 20) - .MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, null, DateTime.Now.AddSeconds(20)), (me) => me.HasGrantType("refresh_token"), 20, true, HttpStatusCode.OK, null) + .MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, nonce, DateTime.UtcNow.AddSeconds(20)), (me) => me.HasGrantType("authorization_code"), 20) + .MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, null, DateTime.UtcNow.AddSeconds(20)), (me) => me.HasGrantType("refresh_token"), 20, true, HttpStatusCode.OK, null) .Build(); using (var server = TestServerBuilder.CreateServer(opts => @@ -1325,8 +1325,8 @@ public async void Should_Clear_Refresh_Token_When_Refresh_fails() var mockHandler = new OidcMockBuilder() .MockOpenIdConfig() .MockJwks() - .MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, nonce, DateTime.Now.AddSeconds(20)), (me) => me.HasGrantType("authorization_code"), 20) - .MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, null, DateTime.Now.AddSeconds(20)), (me) => me.HasGrantType("refresh_token"), 20, true, HttpStatusCode.BadRequest) + .MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, nonce, DateTime.UtcNow.AddSeconds(20)), (me) => me.HasGrantType("authorization_code"), 20) + .MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, null, DateTime.UtcNow.AddSeconds(20)), (me) => me.HasGrantType("refresh_token"), 20, true, HttpStatusCode.BadRequest) .Build(); using (var server = TestServerBuilder.CreateServer(opts => { @@ -1384,7 +1384,7 @@ public async void Should_Not_Refresh_Access_Token_When_Not_Expired() var mockHandler = new OidcMockBuilder() .MockOpenIdConfig() .MockJwks() - .MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, nonce, DateTime.Now.AddSeconds(70)), (me) => me.HasGrantType("authorization_code")) + .MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, nonce, DateTime.UtcNow.AddSeconds(70)), (me) => me.HasGrantType("authorization_code")) .Build(); using (var server = TestServerBuilder.CreateServer(opts => { @@ -1482,7 +1482,7 @@ public async void Should_Call_On_Access_Token_Missing() new KeyValuePair("nonce", nonce), new KeyValuePair("id_token", JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, nonce, - DateTime.Now.AddSeconds(20))) + DateTime.UtcNow.AddSeconds(20))) }; var message = new HttpRequestMessage(HttpMethod.Post, $"{TestServerBuilder.Host}/{TestServerBuilder.Callback}") { Content = new FormUrlEncodedContent(nvc) }; @@ -1508,7 +1508,7 @@ public async void Should_Call_On_Refresh_Token_Missing() var mockHandler = new OidcMockBuilder() .MockOpenIdConfig() .MockJwks() - .MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, nonce, DateTime.Now.AddSeconds(20)), (me) => me.HasGrantType("authorization_code"), 20, true, HttpStatusCode.OK, null) + .MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, nonce, DateTime.UtcNow.AddSeconds(20)), (me) => me.HasGrantType("authorization_code"), 20, true, HttpStatusCode.OK, null) .Build(); using (var server = TestServerBuilder.CreateServer(opts => diff --git a/tests/Auth0.AspNetCore.Authentication.IntegrationTests/TokenValidationTests.cs b/tests/Auth0.AspNetCore.Authentication.IntegrationTests/TokenValidationTests.cs index 6a7249b..706d01b 100644 --- a/tests/Auth0.AspNetCore.Authentication.IntegrationTests/TokenValidationTests.cs +++ b/tests/Auth0.AspNetCore.Authentication.IntegrationTests/TokenValidationTests.cs @@ -526,7 +526,7 @@ public async Task Should_Throw_When_Max_Age_Exists_And_Auth_Time_Is_Invalid() var mockHandler = new OidcMockBuilder() .MockOpenIdConfig() .MockJwks() - .MockToken(() => GenerateToken(1, $"https://{domain}/", clientId, nonce, "1", null, false, null, null, DateTime.Now.Subtract(TimeSpan.FromHours(3))), (me) => me.HasAuth0ClientHeader()) + .MockToken(() => GenerateToken(1, $"https://{domain}/", clientId, nonce, "1", null, false, null, null, DateTime.UtcNow.Subtract(TimeSpan.FromHours(3))), (me) => me.HasAuth0ClientHeader()) .Build(); using (var server = TestServerBuilder.CreateServer(opt => From 49ee4cb4cb4d139dd572c6db92326eb1a0a7b37e Mon Sep 17 00:00:00 2001 From: kailash-b Date: Tue, 18 Mar 2025 14:41:56 +0530 Subject: [PATCH 2/2] Modify .yml files to build against multiple targets --- .github/workflows/build.yml | 11 +++++++---- .../Auth0.AspNetCore.Authentication.Playground.csproj | 2 +- ....AspNetCore.Authentication.IntegrationTests.csproj | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 397c2bb..59e4dc4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,17 +13,20 @@ jobs: strategy: matrix: - dotnet-version: ['6.0.x', '7.0.x', '8.0.x'] + dotnet-version: ['net6.0', 'net7.0', 'net8.0'] steps: - uses: actions/checkout@v3 - name: Setup .NET uses: actions/setup-dotnet@v3 with: - dotnet-version: ${{ matrix.dotnet-version }} + dotnet-version: | + 6.0.x + 7.0.x + 8.0.x - name: Restore dependencies run: dotnet restore - name: Build - run: dotnet build --no-restore + run: dotnet build --no-restore --framework ${{ matrix.dotnet-version }} src/Auth0.AspNetCore.Authentication/Auth0.AspNetCore.Authentication.csproj - name: Test - run: dotnet test --no-build --verbosity normal + run: dotnet test --verbosity normal diff --git a/playground/Auth0.AspNetCore.Authentication.Playground/Auth0.AspNetCore.Authentication.Playground.csproj b/playground/Auth0.AspNetCore.Authentication.Playground/Auth0.AspNetCore.Authentication.Playground.csproj index 63c5f41..d1fcdd0 100644 --- a/playground/Auth0.AspNetCore.Authentication.Playground/Auth0.AspNetCore.Authentication.Playground.csproj +++ b/playground/Auth0.AspNetCore.Authentication.Playground/Auth0.AspNetCore.Authentication.Playground.csproj @@ -1,7 +1,7 @@  - net6.0 + net6.0 diff --git a/tests/Auth0.AspNetCore.Authentication.IntegrationTests/Auth0.AspNetCore.Authentication.IntegrationTests.csproj b/tests/Auth0.AspNetCore.Authentication.IntegrationTests/Auth0.AspNetCore.Authentication.IntegrationTests.csproj index 8307b82..c71bce8 100644 --- a/tests/Auth0.AspNetCore.Authentication.IntegrationTests/Auth0.AspNetCore.Authentication.IntegrationTests.csproj +++ b/tests/Auth0.AspNetCore.Authentication.IntegrationTests/Auth0.AspNetCore.Authentication.IntegrationTests.csproj @@ -45,4 +45,4 @@ - + \ No newline at end of file