Skip to content

Commit

Permalink
Update test to account for bug fix in AzureAD/azure-activedirectory-i…
Browse files Browse the repository at this point in the history
  • Loading branch information
eerhardt committed Sep 6, 2023
1 parent 20d73ea commit f8b011a
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/Security/Authentication/test/JwtBearerTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Globalization;
using System.IdentityModel.Tokens.Jwt;
using System.Net;
using System.Net.Http;
Expand Down Expand Up @@ -958,15 +959,15 @@ public async Task ExpirationAndIssuedSetOnAuthenticateResult()
}

[Fact]
public async Task ExpirationAndIssuedNullWhenMinOrMaxValue()
public async Task ExpirationAndIssuedWhenMinOrMaxValue()
{
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(new string('a', 128)));
var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);

var claims = new[]
{
new Claim(ClaimTypes.NameIdentifier, "Bob")
};
new Claim(ClaimTypes.NameIdentifier, "Bob")
};

var token = new JwtSecurityToken(
issuer: "issuer.contoso.com",
Expand Down Expand Up @@ -995,8 +996,18 @@ public async Task ExpirationAndIssuedNullWhenMinOrMaxValue()
Assert.Equal(HttpStatusCode.OK, response.Response.StatusCode);
var responseBody = await response.Response.Content.ReadAsStringAsync();
using var dom = JsonDocument.Parse(responseBody);
Assert.Equal(JsonValueKind.Null, dom.RootElement.GetProperty("expires").ValueKind);
Assert.Equal(JsonValueKind.Null, dom.RootElement.GetProperty("issued").ValueKind);

var expiresElement = dom.RootElement.GetProperty("expires");
Assert.Equal(JsonValueKind.String, expiresElement.ValueKind);

var elementValue = DateTime.Parse(expiresElement.GetString(), CultureInfo.InvariantCulture);
var elementValueUtc = elementValue.ToUniversalTime();
// roundtrip DateTime.MaxValue through parsing because it is lossy and we
// need equivalent values to compare against.
var max = DateTime.Parse(DateTime.MaxValue.ToString(CultureInfo.InvariantCulture), CultureInfo.InvariantCulture);

Assert.Equal(max, elementValueUtc);
}

[Fact]
Expand Down

0 comments on commit f8b011a

Please sign in to comment.