From a7d26802576d2d11c0f3481199f6c583a4ea25aa Mon Sep 17 00:00:00 2001 From: Franco Fung Date: Wed, 14 Aug 2024 11:39:44 -0700 Subject: [PATCH] Updated class naming to be more explicit and added benchmark using clone --- ...okenAsyncWithValidationParametersTests.cs} | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) rename benchmark/Microsoft.IdentityModel.Benchmarks/{ValidateTokenAsyncWithVPTests.cs => ValidateTokenAsyncWithValidationParametersTests.cs} (73%) diff --git a/benchmark/Microsoft.IdentityModel.Benchmarks/ValidateTokenAsyncWithVPTests.cs b/benchmark/Microsoft.IdentityModel.Benchmarks/ValidateTokenAsyncWithValidationParametersTests.cs similarity index 73% rename from benchmark/Microsoft.IdentityModel.Benchmarks/ValidateTokenAsyncWithVPTests.cs rename to benchmark/Microsoft.IdentityModel.Benchmarks/ValidateTokenAsyncWithValidationParametersTests.cs index 129f83f665..7bd5e999cf 100644 --- a/benchmark/Microsoft.IdentityModel.Benchmarks/ValidateTokenAsyncWithVPTests.cs +++ b/benchmark/Microsoft.IdentityModel.Benchmarks/ValidateTokenAsyncWithValidationParametersTests.cs @@ -11,9 +11,9 @@ 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; @@ -21,7 +21,7 @@ public class ValidateTokenAsyncWithVPTests 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] @@ -60,7 +60,7 @@ public void Setup() } [Benchmark] - public async Task> JsonWebTokenHandler_ValidateTokenAsyncWithVP_CreateClaims() + public async Task> JsonWebTokenHandler_ValidateTokenAsyncWithValidationParameters_CreateClaims() { var result = await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, _validationParameters, _callContext, null).ConfigureAwait(false); var claimsIdentity = result.ClaimsIdentity; @@ -69,7 +69,7 @@ public async Task> JsonWebTokenHandler_ValidateTokenAsyncWithVP_Crea } [Benchmark] - public async Task> JsonWebTokenHandler_ValidateTokenAsync_CreateClaims() + public async Task> JsonWebTokenHandler_ValidateTokenAsyncWithTokenValidationParameters_CreateClaims() { var result = await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, _tokenValidationParameters).ConfigureAwait(false); var claimsIdentity = result.ClaimsIdentity; @@ -78,9 +78,19 @@ public async Task> JsonWebTokenHandler_ValidateTokenAsync_CreateClai } [Benchmark] - public async Task JsonWebTokenHandler_ValidateTokenAsyncWithVP() => await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, _validationParameters, _callContext, null).ConfigureAwait(false); + public async Task JsonWebTokenHandler_ValidateTokenAsyncWithValidationParameters() => await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, _validationParameters, _callContext, null).ConfigureAwait(false); [Benchmark] - public async Task JsonWebTokenHandler_ValidateTokenAsync() => await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, _tokenValidationParameters).ConfigureAwait(false); + public async Task JsonWebTokenHandler_ValidateTokenAsyncWithTokenValidationParameters() => await _jsonWebTokenHandler.ValidateTokenAsync(_jwsExtendedClaims, _tokenValidationParameters).ConfigureAwait(false); + + [Benchmark] + public async Task 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); + } } }