Skip to content

Commit

Permalink
Fix and rename.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmaytak committed Oct 11, 2024
1 parent 36d32e0 commit 01f090d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
36 changes: 18 additions & 18 deletions benchmark/Microsoft.IdentityModel.Benchmarks/ClaimsIdentityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Microsoft.IdentityModel.Benchmarks
public class ClaimsIdentityTests
{
private ClaimsIdentity _claimsIdentity;
private NewClaimsIdentity _jwtClaimsIdentity;
private NewClaimsIdentity _newClaimsIdentity;
private string _claimTypeToFind;
private string _claimValueToFind;
private Predicate<Claim> _findPredicate;
Expand All @@ -25,7 +25,7 @@ public class ClaimsIdentityTests
private JsonWebTokenHandler _jsonWebTokenHandler;
private string _jwsWithExtendedClaims;
private TokenValidationParameters _tokenValidationParameters;
private TokenValidationParameters _jwtTokenValidationParameters;
private TokenValidationParameters _newTokenValidationParameters;

[GlobalSetup]
public async Task SetupAsync()
Expand All @@ -43,7 +43,7 @@ public async Task SetupAsync()
ValidIssuer = BenchmarkUtils.Issuer,
IssuerSigningKey = BenchmarkUtils.SigningCredentialsRsaSha256.Key,
};
_jwtTokenValidationParameters = new TokenValidationParameters()
_newTokenValidationParameters = new TokenValidationParameters()
{
ValidAudience = BenchmarkUtils.Audience,
ValidateLifetime = true,
Expand All @@ -58,7 +58,7 @@ public async Task SetupAsync()
_hasClaimPredicate = claim => claim.Type == _claimTypeToFind && claim.Value == _claimValueToFind;

_claimsIdentity = (await _jsonWebTokenHandler.ValidateTokenAsync(_jwsWithExtendedClaims, _tokenValidationParameters).ConfigureAwait(false)).ClaimsIdentity;
_jwtClaimsIdentity = (await _jsonWebTokenHandler.ValidateTokenAsync(_jwsWithExtendedClaims, _jwtTokenValidationParameters).ConfigureAwait(false)).ClaimsIdentity as NewClaimsIdentity;
_newClaimsIdentity = (await _jsonWebTokenHandler.ValidateTokenAsync(_jwsWithExtendedClaims, _newTokenValidationParameters).ConfigureAwait(false)).ClaimsIdentity as NewClaimsIdentity;
}

[Benchmark(Baseline = true), BenchmarkCategory("FindFirst")]
Expand Down Expand Up @@ -104,44 +104,44 @@ public bool ClaimsIdentity_HasClaim_WithPredicate()
}

[Benchmark, BenchmarkCategory("FindFirst")]
public Claim JwtClaimsIdentity_FindFirst()
public Claim NewClaimsIdentity_FindFirst()
{
var temp = _jwtClaimsIdentity.FindFirst(_claimTypeToFind);
var temp = _newClaimsIdentity.FindFirst(_claimTypeToFind);
return temp;
}

[Benchmark, BenchmarkCategory("FindFirstPredicate")]
public Claim JwtClaimsIdentity_FindFirst_WithPredicate()
public Claim NewClaimsIdentity_FindFirst_WithPredicate()
{
var temp = _jwtClaimsIdentity.FindFirst(_findPredicate);
var temp = _newClaimsIdentity.FindFirst(_findPredicate);
return temp;
}

[Benchmark, BenchmarkCategory("FindAll")]
public List<Claim> JwtClaimsIdentity_FindAll()
public List<Claim> NewClaimsIdentity_FindAll()
{
var temp = _jwtClaimsIdentity.FindAll(_claimTypeToFind).ToList();
var temp = _newClaimsIdentity.FindAll(_claimTypeToFind).ToList();
return temp;
}

[Benchmark, BenchmarkCategory("FindAllPredicate")]
public List<Claim> JwtClaimsIdentity_FindAll_WithPredicate()
public List<Claim> NewClaimsIdentity_FindAll_WithPredicate()
{
var temp = _jwtClaimsIdentity.FindAll(_findPredicate).ToList();
var temp = _newClaimsIdentity.FindAll(_findPredicate).ToList();
return temp;
}

[Benchmark, BenchmarkCategory("HasClaim")]
public bool JwtClaimsIdentity_HasClaim()
public bool NewClaimsIdentity_HasClaim()
{
var temp = _jwtClaimsIdentity.HasClaim(_claimTypeToFind, _claimValueToFind);
var temp = _newClaimsIdentity.HasClaim(_claimTypeToFind, _claimValueToFind);
return temp;
}

[Benchmark, BenchmarkCategory("HasClaimPredicate")]
public bool JwtClaimsIdentity_HasClaim_WithPredicate()
public bool NewClaimsIdentity_HasClaim_WithPredicate()
{
var temp = _jwtClaimsIdentity.HasClaim(_hasClaimPredicate);
var temp = _newClaimsIdentity.HasClaim(_hasClaimPredicate);
return temp;
}

Expand All @@ -155,9 +155,9 @@ public async Task<IList<Claim>> ClaimsIdentity_ValidateTokenAndGetClaims()
}

[Benchmark, BenchmarkCategory("ValidateAndGetClaims")]
public async Task<IList<Claim>> JwtClaimsIdentity_ValidateTokenAndGetClaims()
public async Task<IList<Claim>> NewClaimsIdentity_ValidateTokenAndGetClaims()
{
var result = await _jsonWebTokenHandler.ValidateTokenAsync(_jwsWithExtendedClaims, _jwtTokenValidationParameters).ConfigureAwait(false);
var result = await _jsonWebTokenHandler.ValidateTokenAsync(_jwsWithExtendedClaims, _newTokenValidationParameters).ConfigureAwait(false);
var claimsIdentity = result.ClaimsIdentity;
var claims = claimsIdentity.Claims;
return claims.ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ public virtual ClaimsIdentity CreateClaimsIdentity(SecurityToken securityToken,
authenticationType: AuthenticationType ?? DefaultAuthenticationType,
nameType: nameClaimType ?? ClaimsIdentity.DefaultNameClaimType,
roleType: roleClaimType ?? ClaimsIdentity.DefaultRoleClaimType,
securityToken);
securityToken,
this);
}

/// <summary>
Expand Down

0 comments on commit 01f090d

Please sign in to comment.