diff --git a/build/dependenciesTest.props b/build/dependenciesTest.props index b36f2b6ac0..3753cdfbd3 100644 --- a/build/dependenciesTest.props +++ b/build/dependenciesTest.props @@ -7,6 +7,15 @@ 13.0.3 4.3.0 2.4.0 + + + 8.0.4 + + + 4.7.2 + 4.7.2 + + diff --git a/test/Microsoft.IdentityModel.Tokens.Tests/CaseSensitiveClaimsIdentityTests.cs b/test/Microsoft.IdentityModel.Tokens.Tests/CaseSensitiveClaimsIdentityTests.cs index 68b008ea01..b8da8f54f3 100644 --- a/test/Microsoft.IdentityModel.Tokens.Tests/CaseSensitiveClaimsIdentityTests.cs +++ b/test/Microsoft.IdentityModel.Tokens.Tests/CaseSensitiveClaimsIdentityTests.cs @@ -225,13 +225,13 @@ public class CaseSensitiveClaimsIdentityTheoryData(string testId) : TheoryDataBa internal List ExpectedClaims { get; set; } } - private static ClaimsIdentity CreateCaseSensitiveClaimsIdentity(JObject claims, TokenValidationParameters validationParameters = null) + private static CaseSensitiveClaimsIdentity CreateCaseSensitiveClaimsIdentity(JObject claims, TokenValidationParameters validationParameters = null) { - AppContext.SetSwitch(AppContextSwitches.UseCaseSensitiveClaimsIdentityTypeSwitch, true); - var handler = new JsonWebTokenHandler(); - var claimsIdentity = handler.CreateClaimsIdentityInternal(new JsonWebToken(CreateUnsignedToken(claims)), validationParameters ?? new TokenValidationParameters(), Default.Issuer); - AppContext.SetSwitch(AppContextSwitches.UseCaseSensitiveClaimsIdentityTypeSwitch, false); - return claimsIdentity; + JsonWebToken jsonWebToken = new JsonWebToken(CreateUnsignedToken(claims)); + if (validationParameters == null) + return new CaseSensitiveClaimsIdentity(jsonWebToken.Claims); + else + return new CaseSensitiveClaimsIdentity(jsonWebToken.Claims, validationParameters.AuthenticationType, validationParameters.NameClaimType, validationParameters.RoleClaimType); } private static string CreateUnsignedToken(JObject payload) diff --git a/test/Microsoft.IdentityModel.Tokens.Tests/ClaimsIdentityFactoryTests.cs b/test/Microsoft.IdentityModel.Tokens.Tests/ClaimsIdentityFactoryTests.cs index 357493d019..421e28ab10 100644 --- a/test/Microsoft.IdentityModel.Tokens.Tests/ClaimsIdentityFactoryTests.cs +++ b/test/Microsoft.IdentityModel.Tokens.Tests/ClaimsIdentityFactoryTests.cs @@ -9,7 +9,7 @@ namespace Microsoft.IdentityModel.Tokens.Tests { - [Collection(nameof(ClaimsIdentityFactoryTests))] + [Collection(nameof(CaseSensitiveClaimsIdentityTests))] public class ClaimsIdentityFactoryTests { [Theory] @@ -17,6 +17,8 @@ public class ClaimsIdentityFactoryTests [InlineData(false)] public void Create_FromTokenValidationParameters_ReturnsCorrectClaimsIdentity(bool useCaseSensitiveClaimsIdentity) { + AppContextSwitches.ResetAllSwitches(); + AppContext.SetSwitch(AppContextSwitches.UseCaseSensitiveClaimsIdentityTypeSwitch, useCaseSensitiveClaimsIdentity); var jsonWebToken = new JsonWebToken(Default.Jwt(Default.SecurityTokenDescriptor())); @@ -51,6 +53,8 @@ public void Create_FromTokenValidationParameters_ReturnsCorrectClaimsIdentity(bo [InlineData(false, false)] public void Create_FromDerivedTokenValidationParameters_ReturnsCorrectClaimsIdentity(bool tvpReturnsCaseSensitiveClaimsIdentity, bool tvpReturnsCaseSensitiveClaimsIdentityWithToken) { + AppContextSwitches.ResetAllSwitches(); + AppContext.SetSwitch(AppContextSwitches.UseCaseSensitiveClaimsIdentityTypeSwitch, true); var jsonWebToken = new JsonWebToken(Default.Jwt(Default.SecurityTokenDescriptor())); @@ -85,11 +89,9 @@ public void Create_FromDerivedTokenValidationParameters_ReturnsCorrectClaimsIden Assert.Equal(tokenValidationParameters.NameClaimType, actualClaimsIdentity.NameClaimType); Assert.Equal(tokenValidationParameters.RoleClaimType, actualClaimsIdentity.RoleClaimType); - AppContext.SetSwitch(AppContextSwitches.UseCaseSensitiveClaimsIdentityTypeSwitch, false); + AppContextSwitches.ResetAllSwitches(); } - - private class DerivedTokenValidationParameters : TokenValidationParameters { private bool _returnCaseSensitiveClaimsIdentity;