Skip to content

Commit d395c62

Browse files
authored
Use Utc.now to avoid test failures in certain timezones (#147)
2 parents 370ba0a + 49ee4cb commit d395c62

5 files changed

Lines changed: 23 additions & 20 deletions

File tree

.github/workflows/build.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,20 @@ jobs:
1313

1414
strategy:
1515
matrix:
16-
dotnet-version: ['6.0.x', '7.0.x', '8.0.x']
16+
dotnet-version: ['net6.0', 'net7.0', 'net8.0']
1717

1818
steps:
1919
- uses: actions/checkout@v3
2020
- name: Setup .NET
2121
uses: actions/setup-dotnet@v3
2222
with:
23-
dotnet-version: ${{ matrix.dotnet-version }}
23+
dotnet-version: |
24+
6.0.x
25+
7.0.x
26+
8.0.x
2427
- name: Restore dependencies
2528
run: dotnet restore
2629
- name: Build
27-
run: dotnet build --no-restore
30+
run: dotnet build --no-restore --framework ${{ matrix.dotnet-version }} src/Auth0.AspNetCore.Authentication/Auth0.AspNetCore.Authentication.csproj
2831
- name: Test
29-
run: dotnet test --no-build --verbosity normal
32+
run: dotnet test --verbosity normal

playground/Auth0.AspNetCore.Authentication.Playground/Auth0.AspNetCore.Authentication.Playground.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFrameworks>net6.0</TargetFrameworks>
55
</PropertyGroup>
66

77
<ItemGroup>

tests/Auth0.AspNetCore.Authentication.IntegrationTests/Auth0.AspNetCore.Authentication.IntegrationTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@
4545
<ProjectReference Include="..\..\src\Auth0.AspNetCore.Authentication\Auth0.AspNetCore.Authentication.csproj" />
4646
</ItemGroup>
4747

48-
</Project>
48+
</Project>

tests/Auth0.AspNetCore.Authentication.IntegrationTests/Auth0MiddlewareTests.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,8 +1092,8 @@ public async void Should_Refresh_Access_Token_When_Expired()
10921092
var mockHandler = new OidcMockBuilder()
10931093
.MockOpenIdConfig()
10941094
.MockJwks()
1095-
.MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, nonce, DateTime.Now.AddSeconds(20)), (me) => me.HasGrantType("authorization_code"), 20)
1096-
.MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, null, DateTime.Now.AddSeconds(20)), (me) => me.HasGrantType("refresh_token") && me.HasClientSecret(), 20)
1095+
.MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, nonce, DateTime.UtcNow.AddSeconds(20)), (me) => me.HasGrantType("authorization_code"), 20)
1096+
.MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, null, DateTime.UtcNow.AddSeconds(20)), (me) => me.HasGrantType("refresh_token") && me.HasClientSecret(), 20)
10971097
.Build();
10981098
using (var server = TestServerBuilder.CreateServer(opts =>
10991099
{
@@ -1148,8 +1148,8 @@ public async void Should_Refresh_Access_Token_When_Expired_Using_Client_Assertio
11481148
var mockHandler = new OidcMockBuilder()
11491149
.MockOpenIdConfig()
11501150
.MockJwks()
1151-
.MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, nonce, DateTime.Now.AddSeconds(20)), (me) => me.HasGrantType("authorization_code"), 20)
1152-
.MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, null, DateTime.Now.AddSeconds(20)), (me) => me.HasGrantType("refresh_token") && me.HasClientAssertion(), 20)
1151+
.MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, nonce, DateTime.UtcNow.AddSeconds(20)), (me) => me.HasGrantType("authorization_code"), 20)
1152+
.MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, null, DateTime.UtcNow.AddSeconds(20)), (me) => me.HasGrantType("refresh_token") && me.HasClientAssertion(), 20)
11531153
.Build();
11541154
using (var server = TestServerBuilder.CreateServer(opts =>
11551155
{
@@ -1205,8 +1205,8 @@ public async void Should_Update_Refresh_Token_When_Used()
12051205
var mockHandler = new OidcMockBuilder()
12061206
.MockOpenIdConfig()
12071207
.MockJwks()
1208-
.MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, nonce, DateTime.Now.AddSeconds(20)), (me) => me.HasGrantType("authorization_code"), 20)
1209-
.MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, null, DateTime.Now.AddSeconds(20)), (me) => me.HasGrantType("refresh_token"), 20, true, HttpStatusCode.OK, "456_ROTATED")
1208+
.MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, nonce, DateTime.UtcNow.AddSeconds(20)), (me) => me.HasGrantType("authorization_code"), 20)
1209+
.MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, null, DateTime.UtcNow.AddSeconds(20)), (me) => me.HasGrantType("refresh_token"), 20, true, HttpStatusCode.OK, "456_ROTATED")
12101210
.Build();
12111211

12121212
using (var server = TestServerBuilder.CreateServer(opts =>
@@ -1265,8 +1265,8 @@ public async void Should_Not_Update_Refresh_Token_When_Used_But_Not_Returned()
12651265
var mockHandler = new OidcMockBuilder()
12661266
.MockOpenIdConfig()
12671267
.MockJwks()
1268-
.MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, nonce, DateTime.Now.AddSeconds(20)), (me) => me.HasGrantType("authorization_code"), 20)
1269-
.MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, null, DateTime.Now.AddSeconds(20)), (me) => me.HasGrantType("refresh_token"), 20, true, HttpStatusCode.OK, null)
1268+
.MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, nonce, DateTime.UtcNow.AddSeconds(20)), (me) => me.HasGrantType("authorization_code"), 20)
1269+
.MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, null, DateTime.UtcNow.AddSeconds(20)), (me) => me.HasGrantType("refresh_token"), 20, true, HttpStatusCode.OK, null)
12701270
.Build();
12711271

12721272
using (var server = TestServerBuilder.CreateServer(opts =>
@@ -1325,8 +1325,8 @@ public async void Should_Clear_Refresh_Token_When_Refresh_fails()
13251325
var mockHandler = new OidcMockBuilder()
13261326
.MockOpenIdConfig()
13271327
.MockJwks()
1328-
.MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, nonce, DateTime.Now.AddSeconds(20)), (me) => me.HasGrantType("authorization_code"), 20)
1329-
.MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, null, DateTime.Now.AddSeconds(20)), (me) => me.HasGrantType("refresh_token"), 20, true, HttpStatusCode.BadRequest)
1328+
.MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, nonce, DateTime.UtcNow.AddSeconds(20)), (me) => me.HasGrantType("authorization_code"), 20)
1329+
.MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, null, DateTime.UtcNow.AddSeconds(20)), (me) => me.HasGrantType("refresh_token"), 20, true, HttpStatusCode.BadRequest)
13301330
.Build();
13311331
using (var server = TestServerBuilder.CreateServer(opts =>
13321332
{
@@ -1384,7 +1384,7 @@ public async void Should_Not_Refresh_Access_Token_When_Not_Expired()
13841384
var mockHandler = new OidcMockBuilder()
13851385
.MockOpenIdConfig()
13861386
.MockJwks()
1387-
.MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, nonce, DateTime.Now.AddSeconds(70)), (me) => me.HasGrantType("authorization_code"))
1387+
.MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, nonce, DateTime.UtcNow.AddSeconds(70)), (me) => me.HasGrantType("authorization_code"))
13881388
.Build();
13891389
using (var server = TestServerBuilder.CreateServer(opts =>
13901390
{
@@ -1482,7 +1482,7 @@ public async void Should_Call_On_Access_Token_Missing()
14821482
new KeyValuePair<string, string>("nonce", nonce),
14831483
new KeyValuePair<string, string>("id_token",
14841484
JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, nonce,
1485-
DateTime.Now.AddSeconds(20)))
1485+
DateTime.UtcNow.AddSeconds(20)))
14861486
};
14871487

14881488
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()
15081508
var mockHandler = new OidcMockBuilder()
15091509
.MockOpenIdConfig()
15101510
.MockJwks()
1511-
.MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, nonce, DateTime.Now.AddSeconds(20)), (me) => me.HasGrantType("authorization_code"), 20, true, HttpStatusCode.OK, null)
1511+
.MockToken(() => JwtUtils.GenerateToken(1, $"https://{domain}/", clientId, null, nonce, DateTime.UtcNow.AddSeconds(20)), (me) => me.HasGrantType("authorization_code"), 20, true, HttpStatusCode.OK, null)
15121512
.Build();
15131513

15141514
using (var server = TestServerBuilder.CreateServer(opts =>

tests/Auth0.AspNetCore.Authentication.IntegrationTests/TokenValidationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ public async Task Should_Throw_When_Max_Age_Exists_And_Auth_Time_Is_Invalid()
526526
var mockHandler = new OidcMockBuilder()
527527
.MockOpenIdConfig()
528528
.MockJwks()
529-
.MockToken(() => GenerateToken(1, $"https://{domain}/", clientId, nonce, "1", null, false, null, null, DateTime.Now.Subtract(TimeSpan.FromHours(3))), (me) => me.HasAuth0ClientHeader())
529+
.MockToken(() => GenerateToken(1, $"https://{domain}/", clientId, nonce, "1", null, false, null, null, DateTime.UtcNow.Subtract(TimeSpan.FromHours(3))), (me) => me.HasAuth0ClientHeader())
530530
.Build();
531531

532532
using (var server = TestServerBuilder.CreateServer(opt =>

0 commit comments

Comments
 (0)