Skip to content

Commit

Permalink
Updated class naming to be more explicit and added benchmark using clone
Browse files Browse the repository at this point in the history
  • Loading branch information
Franco Fung committed Aug 14, 2024
1 parent ea1c1be commit a7d2680
Showing 1 changed file with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@

namespace Microsoft.IdentityModel.Benchmarks
{
// dotnet run -c release -f net8.0 --filter Microsoft.IdentityModel.Benchmarks.ValidateTokenAsyncWithVPTests*
// dotnet run -c release -f net8.0 --filter Microsoft.IdentityModel.Benchmarks.ValidateTokenAsyncWithValidationParametersTests*

public class ValidateTokenAsyncWithVPTests
public class ValidateTokenAsyncWithValidationParametersTests
{
private CallContext _callContext;
private JsonWebTokenHandler _jsonWebTokenHandler;
private SecurityTokenDescriptor _tokenDescriptor;
private SecurityTokenDescriptor _tokenDescriptorExtendedClaims;
private string _jws;
private string _jwsExtendedClaims;
private TokenValidationParameters _tokenValidationParameters; //TODO:Add additional test to compare with ValidationParameters also use clone for perf.
private TokenValidationParameters _tokenValidationParameters;
private ValidationParameters _validationParameters;

[GlobalSetup]
Expand Down Expand Up @@ -60,7 +60,7 @@ public void Setup()
}

[Benchmark]
public async Task<List<Claim>> JsonWebTokenHandler_ValidateTokenAsyncWithVP_CreateClaims()
public async Task<List<Claim>> JsonWebTokenHandler_ValidateTokenAsyncWithValidationParameters_CreateClaims()
{
var result = await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, _validationParameters, _callContext, null).ConfigureAwait(false);
var claimsIdentity = result.ClaimsIdentity;
Expand All @@ -69,7 +69,7 @@ public async Task<List<Claim>> JsonWebTokenHandler_ValidateTokenAsyncWithVP_Crea
}

[Benchmark]
public async Task<List<Claim>> JsonWebTokenHandler_ValidateTokenAsync_CreateClaims()
public async Task<List<Claim>> JsonWebTokenHandler_ValidateTokenAsyncWithTokenValidationParameters_CreateClaims()
{
var result = await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, _tokenValidationParameters).ConfigureAwait(false);
var claimsIdentity = result.ClaimsIdentity;
Expand All @@ -78,9 +78,19 @@ public async Task<List<Claim>> JsonWebTokenHandler_ValidateTokenAsync_CreateClai
}

[Benchmark]
public async Task<TokenValidationResult> JsonWebTokenHandler_ValidateTokenAsyncWithVP() => await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, _validationParameters, _callContext, null).ConfigureAwait(false);
public async Task<TokenValidationResult> JsonWebTokenHandler_ValidateTokenAsyncWithValidationParameters() => await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, _validationParameters, _callContext, null).ConfigureAwait(false);

[Benchmark]
public async Task<TokenValidationResult> JsonWebTokenHandler_ValidateTokenAsync() => await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, _tokenValidationParameters).ConfigureAwait(false);
public async Task<TokenValidationResult> JsonWebTokenHandler_ValidateTokenAsyncWithTokenValidationParameters() => await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, _tokenValidationParameters).ConfigureAwait(false);

[Benchmark]
public async Task<TokenValidationResult> JsonWebTokenHandler_ValidateTokenAsyncWithTokenValidationParametersUsingClone()
{
var tokenValidationParameters = _tokenValidationParameters.Clone();
tokenValidationParameters.ValidIssuer = "different-issuer";
tokenValidationParameters.ValidAudience = "different-audience";
tokenValidationParameters.ValidateLifetime = false;
return await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, tokenValidationParameters).ConfigureAwait(false);
}
}
}

0 comments on commit a7d2680

Please sign in to comment.