Skip to content

Use Utc.now to avoid test failures in certain timezones #147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net6.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@
<ProjectReference Include="..\..\src\Auth0.AspNetCore.Authentication\Auth0.AspNetCore.Authentication.csproj" />
</ItemGroup>

</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
{
Expand Down Expand Up @@ -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 =>
{
Expand Down Expand Up @@ -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 =>
Expand Down Expand Up @@ -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 =>
Expand Down Expand Up @@ -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 =>
{
Expand Down Expand Up @@ -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 =>
{
Expand Down Expand Up @@ -1482,7 +1482,7 @@ public async void Should_Call_On_Access_Token_Missing()
new KeyValuePair<string, string>("nonce", nonce),
new KeyValuePair<string, string>("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) };
Expand All @@ -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 =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
Loading