From 5e5a4583a172e43486657a6bde9522de67343e13 Mon Sep 17 00:00:00 2001 From: Ignacio Inglese Date: Thu, 8 Aug 2024 15:14:49 +0100 Subject: [PATCH 1/3] Enabled AOT compatibility checks at build time. Refactored ExceptionDetail to not rely on reflection. --- build/common.props | 4 + .../JsonWebTokenHandler.DecryptToken.cs | 6 +- .../JsonWebTokenHandler.ReadToken.cs | 4 +- .../JsonWebTokenHandler.ValidateSignature.cs | 20 ++-- .../JwtTokenUtilities.DecryptTokenResult.cs | 6 +- .../JwtTokenUtilities.cs | 6 +- .../Validation/ExceptionDetail.cs | 92 ++++++++++++++++--- .../Validation/Validators.Algorithm.cs | 4 +- .../Validation/Validators.Audience.cs | 8 +- .../Validation/Validators.Issuer.cs | 11 +-- .../Validation/Validators.IssuerSigningKey.cs | 10 +- .../Validation/Validators.Lifetime.cs | 10 +- .../Validation/Validators.TokenReplay.cs | 10 +- .../Validation/Validators.TokenType.cs | 8 +- .../JsonWebTokenHandler.DecryptTokenTests.cs | 8 +- .../JsonWebTokenHandler.ReadTokenTests.cs | 6 +- ...nWebTokenHandler.ValidateSignatureTests.cs | 12 +-- .../AlgorithmValidationResultTests.cs | 4 +- .../AudienceValidationResultTests.cs | 36 ++++---- .../Validation/IssuerValidationResultTests.cs | 8 +- .../LifetimeValidationResultTests.cs | 14 +-- .../Validation/ReplayValidationResultTests.cs | 12 +-- .../SigningKeyValidationResultTests.cs | 12 +-- .../TokenTypeValidationResultTests.cs | 10 +- 24 files changed, 196 insertions(+), 125 deletions(-) diff --git a/build/common.props b/build/common.props index 8d402d23a1..3c9d249dfb 100644 --- a/build/common.props +++ b/build/common.props @@ -73,4 +73,8 @@ + + true + + diff --git a/src/Microsoft.IdentityModel.JsonWebTokens/JsonWebTokenHandler.DecryptToken.cs b/src/Microsoft.IdentityModel.JsonWebTokens/JsonWebTokenHandler.DecryptToken.cs index f51e78edab..437d0d692a 100644 --- a/src/Microsoft.IdentityModel.JsonWebTokens/JsonWebTokenHandler.DecryptToken.cs +++ b/src/Microsoft.IdentityModel.JsonWebTokens/JsonWebTokenHandler.DecryptToken.cs @@ -47,7 +47,7 @@ internal TokenDecryptionResult DecryptToken( ValidationFailureType.TokenDecryptionFailed, new ExceptionDetail( new MessageDetail(TokenLogMessages.IDX10612), - typeof(SecurityTokenException), + ExceptionDetail.ExceptionType.SecurityToken, new System.Diagnostics.StackFrame())); var keysOrExceptionDetail = GetContentEncryptionKeys(jwtToken, validationParameters, configuration, callContext); @@ -66,7 +66,7 @@ internal TokenDecryptionResult DecryptToken( new MessageDetail( TokenLogMessages.IDX10609, LogHelper.MarkAsSecurityArtifact(jwtToken, JwtTokenUtilities.SafeLogJwtToken)), - typeof(SecurityTokenDecryptionFailedException), + ExceptionDetail.ExceptionType.SecurityTokenDecryptionFailed, new System.Diagnostics.StackFrame())); return JwtTokenUtilities.DecryptJwtToken( @@ -202,7 +202,7 @@ internal TokenDecryptionResult DecryptToken( keysAttempted?.ToString() ?? "", exceptionStrings?.ToString() ?? "", LogHelper.MarkAsSecurityArtifact(jwtToken, JwtTokenUtilities.SafeLogJwtToken)), - typeof(SecurityTokenKeyWrapException), + ExceptionDetail.ExceptionType.SecurityTokenKeyWrap, new System.Diagnostics.StackFrame()); return (null, exceptionDetail); } diff --git a/src/Microsoft.IdentityModel.JsonWebTokens/JsonWebTokenHandler.ReadToken.cs b/src/Microsoft.IdentityModel.JsonWebTokens/JsonWebTokenHandler.ReadToken.cs index 66c9b194f9..f18ce31dcf 100644 --- a/src/Microsoft.IdentityModel.JsonWebTokens/JsonWebTokenHandler.ReadToken.cs +++ b/src/Microsoft.IdentityModel.JsonWebTokens/JsonWebTokenHandler.ReadToken.cs @@ -36,7 +36,7 @@ internal static TokenReadingResult ReadToken( new MessageDetail( TokenLogMessages.IDX10000, LogHelper.MarkAsNonPII(nameof(token))), - typeof(ArgumentNullException), + ExceptionDetail.ExceptionType.ArgumentNull, new System.Diagnostics.StackFrame())); } @@ -54,7 +54,7 @@ internal static TokenReadingResult ReadToken( ValidationFailureType.TokenReadingFailed, new ExceptionDetail( new MessageDetail(LogMessages.IDX14107), - ex.GetType(), + ExceptionDetail.ExceptionType.SecurityTokenMalformed, new System.Diagnostics.StackFrame(), ex)); } diff --git a/src/Microsoft.IdentityModel.JsonWebTokens/JsonWebTokenHandler.ValidateSignature.cs b/src/Microsoft.IdentityModel.JsonWebTokens/JsonWebTokenHandler.ValidateSignature.cs index 1dbd60bdb5..6b5f36436e 100644 --- a/src/Microsoft.IdentityModel.JsonWebTokens/JsonWebTokenHandler.ValidateSignature.cs +++ b/src/Microsoft.IdentityModel.JsonWebTokens/JsonWebTokenHandler.ValidateSignature.cs @@ -55,7 +55,7 @@ internal static SignatureValidationResult ValidateSignature( jwtToken.EncodedToken, JwtTokenUtilities.SafeLogJwtToken) ), - typeof(SecurityTokenInvalidSignatureException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidSignature, new StackFrame())); SecurityKey? key = null; @@ -93,7 +93,7 @@ internal static SignatureValidationResult ValidateSignature( ValidationFailureType.SignatureValidationFailed, new ExceptionDetail( new MessageDetail(TokenLogMessages.IDX10500), - typeof(SecurityTokenSignatureKeyNotFoundException), + ExceptionDetail.ExceptionType.SecurityTokenSignatureKeyNotFound, new StackFrame())); } @@ -130,7 +130,7 @@ private static SignatureValidationResult ValidateSignatureUsingAllKeys( ValidationFailureType.SignatureValidationFailed, new ExceptionDetail( new MessageDetail(TokenLogMessages.IDX10500), - typeof(SecurityTokenSignatureKeyNotFoundException), + ExceptionDetail.ExceptionType.SecurityTokenSignatureKeyNotFound, new StackFrame())); StringBuilder exceptionStrings = new(); @@ -215,7 +215,7 @@ private static SignatureValidationResult ValidateSignatureWithKey( LogMessages.IDX14000, LogHelper.MarkAsNonPII(jsonWebToken.Alg), key), - typeof(SecurityTokenInvalidAlgorithmException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidAlgorithm, new StackFrame())); } @@ -240,7 +240,7 @@ private static SignatureValidationResult ValidateSignatureWithKey( new MessageDetail(TokenLogMessages.IDX10636, key?.ToString() ?? "Null", LogHelper.MarkAsNonPII(jsonWebToken.Alg)), - typeof(InvalidOperationException), + ExceptionDetail.ExceptionType.InvalidOperation, new StackFrame())); bool valid = EncodingUtils.PerformEncodingDependentOperation( @@ -260,7 +260,7 @@ private static SignatureValidationResult ValidateSignatureWithKey( ValidationFailureType.SignatureValidationFailed, new ExceptionDetail( new MessageDetail(TokenLogMessages.IDX10504), - typeof(SecurityTokenInvalidSignatureException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidSignature, new StackFrame())); } #pragma warning disable CA1031 // Do not catch general exception types @@ -271,7 +271,7 @@ private static SignatureValidationResult ValidateSignatureWithKey( ValidationFailureType.SignatureValidationFailed, new ExceptionDetail( new MessageDetail(TokenLogMessages.IDX10504, ex.ToString()), - ex.GetType(), + ExceptionDetail.ExceptionType.SecurityTokenInvalidSignature, new StackFrame(), ex)); } @@ -311,7 +311,7 @@ private static ExceptionDetail GetSignatureValidationFailureExceptionDetails( LogHelper.MarkAsNonPII(jwtToken.Kid), exceptionStrings.ToString(), LogHelper.MarkAsSecurityArtifact(jwtToken.EncodedToken, JwtTokenUtilities.SafeLogJwtToken)), - typeof(SecurityTokenSignatureKeyNotFoundException), + ExceptionDetail.ExceptionType.SecurityTokenSignatureKeyNotFound, new StackFrame()); } @@ -325,7 +325,7 @@ private static ExceptionDetail GetSignatureValidationFailureExceptionDetails( LogHelper.MarkAsNonPII(numKeysInConfiguration), exceptionStrings.ToString(), LogHelper.MarkAsSecurityArtifact(jwtToken.EncodedToken, JwtTokenUtilities.SafeLogJwtToken)), - typeof(SecurityTokenSignatureKeyNotFoundException), + ExceptionDetail.ExceptionType.SecurityTokenSignatureKeyNotFound, new StackFrame()); return new ExceptionDetail( @@ -336,7 +336,7 @@ private static ExceptionDetail GetSignatureValidationFailureExceptionDetails( LogHelper.MarkAsNonPII(numKeysInConfiguration), exceptionStrings.ToString(), LogHelper.MarkAsSecurityArtifact(jwtToken.EncodedToken, JwtTokenUtilities.SafeLogJwtToken)), - typeof(SecurityTokenSignatureKeyNotFoundException), + ExceptionDetail.ExceptionType.SecurityTokenSignatureKeyNotFound, new StackFrame()); } diff --git a/src/Microsoft.IdentityModel.JsonWebTokens/JwtTokenUtilities.DecryptTokenResult.cs b/src/Microsoft.IdentityModel.JsonWebTokens/JwtTokenUtilities.DecryptTokenResult.cs index ab098857d8..4b300e8aa2 100644 --- a/src/Microsoft.IdentityModel.JsonWebTokens/JwtTokenUtilities.DecryptTokenResult.cs +++ b/src/Microsoft.IdentityModel.JsonWebTokens/JwtTokenUtilities.DecryptTokenResult.cs @@ -35,7 +35,7 @@ internal static TokenDecryptionResult DecryptJwtToken( new MessageDetail( TokenLogMessages.IDX10000, nameof(validationParameters)), - typeof(ArgumentNullException), + ExceptionDetail.ExceptionType.ArgumentNull, new System.Diagnostics.StackFrame())); if (decryptionParameters == null) @@ -46,7 +46,7 @@ internal static TokenDecryptionResult DecryptJwtToken( new MessageDetail( TokenLogMessages.IDX10000, nameof(decryptionParameters)), - typeof(ArgumentNullException), + ExceptionDetail.ExceptionType.ArgumentNull, new System.Diagnostics.StackFrame())); bool decryptionSucceeded = false; @@ -142,7 +142,7 @@ internal static TokenDecryptionResult DecryptJwtToken( new MessageDetail( TokenLogMessages.IDX10679, zipAlgorithm), - typeof(SecurityTokenDecompressionFailedException), + ExceptionDetail.ExceptionType.SecurityTokenDecompressionFailed, new StackFrame(), ex)); } diff --git a/src/Microsoft.IdentityModel.JsonWebTokens/JwtTokenUtilities.cs b/src/Microsoft.IdentityModel.JsonWebTokens/JwtTokenUtilities.cs index 0587d380f1..dfcd751d5f 100644 --- a/src/Microsoft.IdentityModel.JsonWebTokens/JwtTokenUtilities.cs +++ b/src/Microsoft.IdentityModel.JsonWebTokens/JwtTokenUtilities.cs @@ -367,7 +367,7 @@ private static ExceptionDetail GetDecryptionExceptionDetail( keysAttempted.ToString(), exceptionStrings?.ToString() ?? string.Empty, LogHelper.MarkAsSecurityArtifact(decryptionParameters.EncodedToken, SafeLogJwtToken)), - typeof(SecurityTokenDecryptionFailedException), + ExceptionDetail.ExceptionType.SecurityTokenDecryptionFailed, new StackFrame(true), null); else if (algorithmNotSupportedByCryptoProvider) @@ -376,7 +376,7 @@ private static ExceptionDetail GetDecryptionExceptionDetail( TokenLogMessages.IDX10619, LogHelper.MarkAsNonPII(decryptionParameters.Alg), LogHelper.MarkAsNonPII(decryptionParameters.Enc)), - typeof(SecurityTokenDecryptionFailedException), + ExceptionDetail.ExceptionType.SecurityTokenDecryptionFailed, new StackFrame(true), null); else @@ -384,7 +384,7 @@ private static ExceptionDetail GetDecryptionExceptionDetail( new MessageDetail( TokenLogMessages.IDX10609, LogHelper.MarkAsSecurityArtifact(decryptionParameters.EncodedToken, SafeLogJwtToken)), - typeof(SecurityTokenDecryptionFailedException), + ExceptionDetail.ExceptionType.SecurityTokenDecryptionFailed, new StackFrame(true), null); } diff --git a/src/Microsoft.IdentityModel.Tokens/Validation/ExceptionDetail.cs b/src/Microsoft.IdentityModel.Tokens/Validation/ExceptionDetail.cs index a8da23d694..fa048a5f08 100644 --- a/src/Microsoft.IdentityModel.Tokens/Validation/ExceptionDetail.cs +++ b/src/Microsoft.IdentityModel.Tokens/Validation/ExceptionDetail.cs @@ -19,7 +19,7 @@ internal class ExceptionDetail /// contains information about the exception that is used to generate the exception message. /// is the type of exception that occurred. /// contains information about the stack frame where the exception occurred. - public ExceptionDetail(MessageDetail messageDetail, Type exceptionType, StackFrame stackFrame) + public ExceptionDetail(MessageDetail messageDetail, ExceptionType exceptionType, StackFrame stackFrame) : this(messageDetail, exceptionType, stackFrame, null) { } @@ -31,9 +31,9 @@ public ExceptionDetail(MessageDetail messageDetail, Type exceptionType, StackFra /// is the type of exception that occurred. /// contains information about the stack frame where the exception occurred. /// is the inner exception that occurred. - public ExceptionDetail(MessageDetail messageDetail, Type exceptionType, StackFrame stackFrame, Exception innerException) + public ExceptionDetail(MessageDetail messageDetail, ExceptionType exceptionType, StackFrame stackFrame, Exception innerException) { - ExceptionType = exceptionType; + Type = exceptionType; InnerException = innerException; MessageDetail = messageDetail; StackFrames.Add(stackFrame); @@ -43,25 +43,19 @@ public ExceptionDetail(MessageDetail messageDetail, Type exceptionType, StackFra /// Creates an instance of an using /// /// An instantance of an Exception. - public Exception GetException() - { - if (InnerException != null) - return Activator.CreateInstance(ExceptionType, MessageDetail.Message, InnerException) as Exception; - - return Activator.CreateInstance(ExceptionType, MessageDetail.Message) as Exception; - } + public Exception GetException() => ExceptionFromType(Type, InnerException); internal static ExceptionDetail NullParameter(string parameterName) => new ExceptionDetail( new MessageDetail( LogMessages.IDX10000, LogHelper.MarkAsNonPII(parameterName)), - typeof(ArgumentNullException), + ExceptionType.ArgumentNull, new StackFrame()); /// /// Gets the type of exception that occurred. /// - public Type ExceptionType { get; } + public ExceptionType Type { get; } /// /// Gets the inner exception that occurred. @@ -77,5 +71,79 @@ public Exception GetException() /// Gets the stack frames where the exception occurred. /// public IList StackFrames { get; } = []; + + public enum ExceptionType + { + Unknown = -1, + ArgumentNull, + InvalidOperation, + SecurityToken, + SecurityTokenDecompressionFailed, + SecurityTokenDecryptionFailed, + SecurityTokenExpired, + SecurityTokenInvalidAudience, + SecurityTokenInvalidAlgorithm, + SecurityTokenInvalidIssuer, + SecurityTokenInvalidLifetime, + SecurityTokenInvalidSigningKey, + SecurityTokenInvalidSignature, + SecurityTokenInvalidType, + SecurityTokenKeyWrap, + SecurityTokenMalformed, + SecurityTokenNoExpiration, + SecurityTokenNotYetValid, + SecurityTokenReplayDetected, + SecurityTokenReplayAddFailed, + SecurityTokenSignatureKeyNotFound, + } + + private Exception ExceptionFromType(ExceptionType exceptionType, Exception innerException) + { + switch (exceptionType) + { + case ExceptionType.ArgumentNull: + return new ArgumentNullException(MessageDetail.Message, innerException); + case ExceptionType.InvalidOperation: + return new InvalidOperationException(MessageDetail.Message, innerException); + case ExceptionType.SecurityToken: + return new SecurityTokenException(MessageDetail.Message, innerException); + case ExceptionType.SecurityTokenDecompressionFailed: + return new SecurityTokenDecompressionFailedException(MessageDetail.Message, innerException); + case ExceptionType.SecurityTokenDecryptionFailed: + return new SecurityTokenDecryptionFailedException(MessageDetail.Message, innerException); + case ExceptionType.SecurityTokenExpired: + return new SecurityTokenExpiredException(MessageDetail.Message, innerException); + case ExceptionType.SecurityTokenInvalidAudience: + return new SecurityTokenInvalidAudienceException(MessageDetail.Message, innerException); + case ExceptionType.SecurityTokenInvalidAlgorithm: + return new SecurityTokenInvalidAlgorithmException(MessageDetail.Message, innerException); + case ExceptionType.SecurityTokenInvalidIssuer: + return new SecurityTokenInvalidIssuerException(MessageDetail.Message, innerException); + case ExceptionType.SecurityTokenInvalidLifetime: + return new SecurityTokenInvalidLifetimeException(MessageDetail.Message, innerException); + case ExceptionType.SecurityTokenInvalidSignature: + return new SecurityTokenInvalidSignatureException(MessageDetail.Message, innerException); + case ExceptionType.SecurityTokenInvalidSigningKey: + return new SecurityTokenInvalidSigningKeyException(MessageDetail.Message, innerException); + case ExceptionType.SecurityTokenInvalidType: + return new SecurityTokenInvalidTypeException(MessageDetail.Message, innerException); + case ExceptionType.SecurityTokenKeyWrap: + return new SecurityTokenKeyWrapException(MessageDetail.Message, innerException); + case ExceptionType.SecurityTokenMalformed: + return new SecurityTokenMalformedException(MessageDetail.Message, innerException); + case ExceptionType.SecurityTokenNoExpiration: + return new SecurityTokenNoExpirationException(MessageDetail.Message, innerException); + case ExceptionType.SecurityTokenNotYetValid: + return new SecurityTokenNotYetValidException(MessageDetail.Message, innerException); + case ExceptionType.SecurityTokenReplayDetected: + return new SecurityTokenReplayDetectedException(MessageDetail.Message, innerException); + case ExceptionType.SecurityTokenReplayAddFailed: + return new SecurityTokenReplayAddFailedException(MessageDetail.Message, innerException); + case ExceptionType.SecurityTokenSignatureKeyNotFound: + return new SecurityTokenSignatureKeyNotFoundException(MessageDetail.Message, innerException); + default: + throw new ArgumentException("Invalid ExceptionType."); + } + } } } diff --git a/src/Microsoft.IdentityModel.Tokens/Validation/Validators.Algorithm.cs b/src/Microsoft.IdentityModel.Tokens/Validation/Validators.Algorithm.cs index 7770374b0f..684d339c80 100644 --- a/src/Microsoft.IdentityModel.Tokens/Validation/Validators.Algorithm.cs +++ b/src/Microsoft.IdentityModel.Tokens/Validation/Validators.Algorithm.cs @@ -54,7 +54,7 @@ internal static AlgorithmValidationResult ValidateAlgorithm( new MessageDetail( LogMessages.IDX10000, LogHelper.MarkAsNonPII(nameof(validationParameters))), - typeof(ArgumentNullException), + ExceptionDetail.ExceptionType.ArgumentNull, new StackFrame(true))); } @@ -67,7 +67,7 @@ internal static AlgorithmValidationResult ValidateAlgorithm( new MessageDetail( LogMessages.IDX10696, LogHelper.MarkAsNonPII(algorithm)), - typeof(SecurityTokenInvalidAlgorithmException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidAlgorithm, new StackFrame(true))); } diff --git a/src/Microsoft.IdentityModel.Tokens/Validation/Validators.Audience.cs b/src/Microsoft.IdentityModel.Tokens/Validation/Validators.Audience.cs index 4841063c51..26ee826da2 100644 --- a/src/Microsoft.IdentityModel.Tokens/Validation/Validators.Audience.cs +++ b/src/Microsoft.IdentityModel.Tokens/Validation/Validators.Audience.cs @@ -54,7 +54,7 @@ internal static AudienceValidationResult ValidateAudience(IList tokenAud new MessageDetail( LogMessages.IDX10000, LogHelper.MarkAsNonPII(nameof(validationParameters))), - typeof(ArgumentNullException), + ExceptionDetail.ExceptionType.ArgumentNull, new StackFrame(true))); if (tokenAudiences == null) @@ -65,7 +65,7 @@ internal static AudienceValidationResult ValidateAudience(IList tokenAud new MessageDetail( LogMessages.IDX10207, null), - typeof(SecurityTokenInvalidAudienceException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidAudience, new StackFrame(true))); if (tokenAudiences.Count == 0) @@ -76,7 +76,7 @@ internal static AudienceValidationResult ValidateAudience(IList tokenAud new MessageDetail( LogMessages.IDX10206, null), - typeof(SecurityTokenInvalidAudienceException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidAudience, new StackFrame(true))); string? validAudience = ValidTokenAudience(tokenAudiences, validationParameters.ValidAudiences, validationParameters.IgnoreTrailingSlashWhenValidatingAudience); @@ -91,7 +91,7 @@ internal static AudienceValidationResult ValidateAudience(IList tokenAud LogMessages.IDX10215, LogHelper.MarkAsNonPII(Utility.SerializeAsSingleCommaDelimitedString(tokenAudiences)), LogHelper.MarkAsNonPII(Utility.SerializeAsSingleCommaDelimitedString(validationParameters.ValidAudiences))), - typeof(SecurityTokenInvalidAudienceException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidAudience, new StackFrame(true))); } diff --git a/src/Microsoft.IdentityModel.Tokens/Validation/Validators.Issuer.cs b/src/Microsoft.IdentityModel.Tokens/Validation/Validators.Issuer.cs index 602721ea21..46803152ab 100644 --- a/src/Microsoft.IdentityModel.Tokens/Validation/Validators.Issuer.cs +++ b/src/Microsoft.IdentityModel.Tokens/Validation/Validators.Issuer.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; using System.Diagnostics; using System.Threading; using System.Threading.Tasks; @@ -58,7 +57,7 @@ internal static async Task ValidateIssuerAsync( new MessageDetail( LogMessages.IDX10211, null), - typeof(SecurityTokenInvalidIssuerException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidIssuer, new StackFrame(true), null)); } @@ -71,7 +70,7 @@ internal static async Task ValidateIssuerAsync( new MessageDetail( LogMessages.IDX10000, LogHelper.MarkAsNonPII(nameof(validationParameters))), - typeof(ArgumentNullException), + ExceptionDetail.ExceptionType.ArgumentNull, new StackFrame(true), null)); @@ -83,7 +82,7 @@ internal static async Task ValidateIssuerAsync( new MessageDetail( LogMessages.IDX10000, LogHelper.MarkAsNonPII(nameof(securityToken))), - typeof(ArgumentNullException), + ExceptionDetail.ExceptionType.ArgumentNull, new StackFrame(true), null)); @@ -101,7 +100,7 @@ internal static async Task ValidateIssuerAsync( new MessageDetail( LogMessages.IDX10211, null), - typeof(SecurityTokenInvalidIssuerException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidIssuer, new StackFrame(true))); } @@ -152,7 +151,7 @@ internal static async Task ValidateIssuerAsync( LogHelper.MarkAsNonPII(issuer), LogHelper.MarkAsNonPII(Utility.SerializeAsSingleCommaDelimitedString(validationParameters.ValidIssuers)), LogHelper.MarkAsNonPII(configuration?.Issuer)), - typeof(SecurityTokenInvalidIssuerException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidIssuer, new StackFrame(true))); } } diff --git a/src/Microsoft.IdentityModel.Tokens/Validation/Validators.IssuerSigningKey.cs b/src/Microsoft.IdentityModel.Tokens/Validation/Validators.IssuerSigningKey.cs index 2051556d66..ea688998e3 100644 --- a/src/Microsoft.IdentityModel.Tokens/Validation/Validators.IssuerSigningKey.cs +++ b/src/Microsoft.IdentityModel.Tokens/Validation/Validators.IssuerSigningKey.cs @@ -61,7 +61,7 @@ internal static SigningKeyValidationResult ValidateIssuerSigningKey( new MessageDetail( LogMessages.IDX10000, LogHelper.MarkAsNonPII(nameof(validationParameters))), - typeof(ArgumentNullException), + ExceptionDetail.ExceptionType.ArgumentNull, new StackFrame(true))); if (securityKey == null) @@ -73,7 +73,7 @@ internal static SigningKeyValidationResult ValidateIssuerSigningKey( new MessageDetail( LogMessages.IDX10253, LogHelper.MarkAsNonPII(nameof(securityKey))), - typeof(ArgumentNullException), + ExceptionDetail.ExceptionType.ArgumentNull, new StackFrame(true))); } @@ -85,7 +85,7 @@ internal static SigningKeyValidationResult ValidateIssuerSigningKey( new MessageDetail( LogMessages.IDX10000, LogHelper.MarkAsNonPII(nameof(securityToken))), - typeof(ArgumentNullException), + ExceptionDetail.ExceptionType.ArgumentNull, new StackFrame(true))); return ValidateIssuerSigningKeyLifeTime(securityKey, validationParameters, callContext); @@ -121,7 +121,7 @@ internal static SigningKeyValidationResult ValidateIssuerSigningKeyLifeTime( LogMessages.IDX10248, LogHelper.MarkAsNonPII(notBeforeUtc), LogHelper.MarkAsNonPII(utcNow))), - typeof(SecurityTokenInvalidSigningKeyException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidSigningKey, new StackFrame(true))); if (LogHelper.IsEnabled(EventLogLevel.Informational)) @@ -137,7 +137,7 @@ internal static SigningKeyValidationResult ValidateIssuerSigningKeyLifeTime( LogMessages.IDX10249, LogHelper.MarkAsNonPII(notAfterUtc), LogHelper.MarkAsNonPII(utcNow))), - typeof(SecurityTokenInvalidSigningKeyException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidSigningKey, new StackFrame(true))); if (LogHelper.IsEnabled(EventLogLevel.Informational)) diff --git a/src/Microsoft.IdentityModel.Tokens/Validation/Validators.Lifetime.cs b/src/Microsoft.IdentityModel.Tokens/Validation/Validators.Lifetime.cs index 1073db2cd3..a56ee6bd9e 100644 --- a/src/Microsoft.IdentityModel.Tokens/Validation/Validators.Lifetime.cs +++ b/src/Microsoft.IdentityModel.Tokens/Validation/Validators.Lifetime.cs @@ -60,7 +60,7 @@ internal static LifetimeValidationResult ValidateLifetime(DateTime? notBefore, D new MessageDetail( LogMessages.IDX10000, LogHelper.MarkAsNonPII(nameof(validationParameters))), - typeof(ArgumentNullException), + ExceptionDetail.ExceptionType.ArgumentNull, new StackFrame(true))); if (!expires.HasValue) @@ -72,7 +72,7 @@ internal static LifetimeValidationResult ValidateLifetime(DateTime? notBefore, D new MessageDetail( LogMessages.IDX10225, LogHelper.MarkAsNonPII(securityToken == null ? "null" : securityToken.GetType().ToString())), - typeof(SecurityTokenNoExpirationException), + ExceptionDetail.ExceptionType.SecurityTokenNoExpiration, new StackFrame(true))); if (notBefore.HasValue && expires.HasValue && (notBefore.Value > expires.Value)) @@ -85,7 +85,7 @@ internal static LifetimeValidationResult ValidateLifetime(DateTime? notBefore, D LogMessages.IDX10224, LogHelper.MarkAsNonPII(notBefore.Value), LogHelper.MarkAsNonPII(expires.Value)), - typeof(SecurityTokenInvalidLifetimeException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidLifetime, new StackFrame(true))); DateTime utcNow = DateTime.UtcNow; @@ -99,7 +99,7 @@ internal static LifetimeValidationResult ValidateLifetime(DateTime? notBefore, D LogMessages.IDX10222, LogHelper.MarkAsNonPII(notBefore.Value), LogHelper.MarkAsNonPII(utcNow)), - typeof(SecurityTokenNotYetValidException), + ExceptionDetail.ExceptionType.SecurityTokenNotYetValid, new StackFrame(true))); if (expires.HasValue && (expires.Value < DateTimeUtil.Add(utcNow, validationParameters.ClockSkew.Negate()))) @@ -112,7 +112,7 @@ internal static LifetimeValidationResult ValidateLifetime(DateTime? notBefore, D LogMessages.IDX10223, LogHelper.MarkAsNonPII(expires.Value), LogHelper.MarkAsNonPII(utcNow)), - typeof(SecurityTokenExpiredException), + ExceptionDetail.ExceptionType.SecurityTokenExpired, new StackFrame(true))); // if it reaches here, that means lifetime of the token is valid diff --git a/src/Microsoft.IdentityModel.Tokens/Validation/Validators.TokenReplay.cs b/src/Microsoft.IdentityModel.Tokens/Validation/Validators.TokenReplay.cs index 17186207ef..8d301ea6a8 100644 --- a/src/Microsoft.IdentityModel.Tokens/Validation/Validators.TokenReplay.cs +++ b/src/Microsoft.IdentityModel.Tokens/Validation/Validators.TokenReplay.cs @@ -51,7 +51,7 @@ internal static ReplayValidationResult ValidateTokenReplay(DateTime? expirationT new MessageDetail( LogMessages.IDX10000, LogHelper.MarkAsNonPII(nameof(securityToken))), - typeof(ArgumentNullException), + ExceptionDetail.ExceptionType.ArgumentNull, new StackFrame(), null)); @@ -63,7 +63,7 @@ internal static ReplayValidationResult ValidateTokenReplay(DateTime? expirationT new MessageDetail( LogMessages.IDX10000, LogHelper.MarkAsNonPII(nameof(validationParameters))), - typeof(ArgumentNullException), + ExceptionDetail.ExceptionType.ArgumentNull, new StackFrame(), null)); @@ -78,7 +78,7 @@ internal static ReplayValidationResult ValidateTokenReplay(DateTime? expirationT new MessageDetail( LogMessages.IDX10227, LogHelper.MarkAsUnsafeSecurityArtifact(securityToken, t => t.ToString())), - typeof(SecurityTokenReplayDetectedException), + ExceptionDetail.ExceptionType.SecurityTokenReplayDetected, new StackFrame(), null)); @@ -90,7 +90,7 @@ internal static ReplayValidationResult ValidateTokenReplay(DateTime? expirationT new MessageDetail( LogMessages.IDX10228, LogHelper.MarkAsUnsafeSecurityArtifact(securityToken, t => t.ToString())), - typeof(SecurityTokenReplayDetectedException), + ExceptionDetail.ExceptionType.SecurityTokenReplayDetected, new StackFrame(), null)); @@ -102,7 +102,7 @@ internal static ReplayValidationResult ValidateTokenReplay(DateTime? expirationT new MessageDetail( LogMessages.IDX10229, LogHelper.MarkAsUnsafeSecurityArtifact(securityToken, t => t.ToString())), - typeof(SecurityTokenReplayAddFailedException), + ExceptionDetail.ExceptionType.SecurityTokenReplayAddFailed, new StackFrame(), null)); } diff --git a/src/Microsoft.IdentityModel.Tokens/Validation/Validators.TokenType.cs b/src/Microsoft.IdentityModel.Tokens/Validation/Validators.TokenType.cs index ef119b6224..07af5a4300 100644 --- a/src/Microsoft.IdentityModel.Tokens/Validation/Validators.TokenType.cs +++ b/src/Microsoft.IdentityModel.Tokens/Validation/Validators.TokenType.cs @@ -53,7 +53,7 @@ internal static TokenTypeValidationResult ValidateTokenType( new MessageDetail( LogMessages.IDX10000, LogHelper.MarkAsNonPII(nameof(securityToken))), - typeof(ArgumentNullException), + ExceptionDetail.ExceptionType.ArgumentNull, new StackFrame(true))); } @@ -66,7 +66,7 @@ internal static TokenTypeValidationResult ValidateTokenType( new MessageDetail( LogMessages.IDX10000, LogHelper.MarkAsNonPII(nameof(validationParameters))), - typeof(ArgumentNullException), + ExceptionDetail.ExceptionType.ArgumentNull, new StackFrame(true))); } @@ -85,7 +85,7 @@ internal static TokenTypeValidationResult ValidateTokenType( new MessageDetail( LogMessages.IDX10256, LogHelper.MarkAsNonPII(nameof(type))), - typeof(SecurityTokenInvalidTypeException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidType, new StackFrame(true))); } @@ -99,7 +99,7 @@ internal static TokenTypeValidationResult ValidateTokenType( LogMessages.IDX10257, LogHelper.MarkAsNonPII(nameof(type)), LogHelper.MarkAsNonPII(Utility.SerializeAsSingleCommaDelimitedString(validationParameters.ValidTypes))), - typeof(SecurityTokenInvalidTypeException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidType, new StackFrame(true))); } diff --git a/test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenHandler.DecryptTokenTests.cs b/test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenHandler.DecryptTokenTests.cs index 0b5b8829ca..da65e0afad 100644 --- a/test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenHandler.DecryptTokenTests.cs +++ b/test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenHandler.DecryptTokenTests.cs @@ -109,7 +109,7 @@ public static TheoryData JsonWebTokenHandlerDecryptTo ValidationFailureType.TokenDecryptionFailed, new ExceptionDetail( new MessageDetail(TokenLogMessages.IDX10612), - typeof(SecurityTokenException), + ExceptionDetail.ExceptionType.SecurityToken, new StackFrame(), null)), }, new TokenDecryptingTheoryData @@ -123,7 +123,7 @@ public static TheoryData JsonWebTokenHandlerDecryptTo ValidationFailureType.TokenDecryptionFailed, new ExceptionDetail( new MessageDetail(TokenLogMessages.IDX10000, "jwtToken"), - typeof(ArgumentNullException), + ExceptionDetail.ExceptionType.ArgumentNull, new StackFrame(true))), }, new TokenDecryptingTheoryData @@ -137,7 +137,7 @@ public static TheoryData JsonWebTokenHandlerDecryptTo ValidationFailureType.TokenDecryptionFailed, new ExceptionDetail( new MessageDetail(TokenLogMessages.IDX10000, "validationParameters"), - typeof(ArgumentNullException), + ExceptionDetail.ExceptionType.ArgumentNull, new StackFrame(true))), }, new TokenDecryptingTheoryData @@ -204,7 +204,7 @@ public static TheoryData JsonWebTokenHandlerDecryptTo LogHelper.MarkAsSecurityArtifact( new JsonWebToken(ReferenceTokens.JWEDirectEncryptionUnsignedInnerJWTWithAdditionalHeaderClaims), JwtTokenUtilities.SafeLogJwtToken)), - typeof(SecurityTokenDecryptionFailedException), + ExceptionDetail.ExceptionType.SecurityTokenDecryptionFailed, new StackFrame(), null)), } }; diff --git a/test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenHandler.ReadTokenTests.cs b/test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenHandler.ReadTokenTests.cs index 3e21280c17..848f414789 100644 --- a/test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenHandler.ReadTokenTests.cs +++ b/test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenHandler.ReadTokenTests.cs @@ -71,7 +71,7 @@ public static TheoryData JsonWebTokenHandlerReadTokenTes new MessageDetail( TokenLogMessages.IDX10000, LogHelper.MarkAsNonPII("token")), - typeof(ArgumentNullException), + ExceptionDetail.ExceptionType.ArgumentNull, new System.Diagnostics.StackFrame())) }, new TokenReadingTheoryData @@ -86,7 +86,7 @@ public static TheoryData JsonWebTokenHandlerReadTokenTes new MessageDetail( TokenLogMessages.IDX10000, LogHelper.MarkAsNonPII("token")), - typeof(ArgumentNullException), + ExceptionDetail.ExceptionType.ArgumentNull, new System.Diagnostics.StackFrame())) }, new TokenReadingTheoryData @@ -103,7 +103,7 @@ public static TheoryData JsonWebTokenHandlerReadTokenTes new MessageDetail( LogMessages.IDX14107, LogHelper.MarkAsNonPII("token")), - typeof(SecurityTokenMalformedException), + ExceptionDetail.ExceptionType.SecurityTokenMalformed, new System.Diagnostics.StackFrame())) } }; diff --git a/test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenHandler.ValidateSignatureTests.cs b/test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenHandler.ValidateSignatureTests.cs index d830f9d766..e1a3c7c27a 100644 --- a/test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenHandler.ValidateSignatureTests.cs +++ b/test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenHandler.ValidateSignatureTests.cs @@ -74,7 +74,7 @@ public static TheoryData JsonWeb new MessageDetail( TokenLogMessages.IDX10000, "jwtToken"), - typeof(ArgumentNullException), + ExceptionDetail.ExceptionType.ArgumentNull, new System.Diagnostics.StackFrame())) }, new JsonWebTokenHandlerValidateSignatureTheoryData { @@ -88,7 +88,7 @@ public static TheoryData JsonWeb new MessageDetail( TokenLogMessages.IDX10000, "validationParameters"), - typeof(ArgumentNullException), + ExceptionDetail.ExceptionType.ArgumentNull, new System.Diagnostics.StackFrame())) }, new JsonWebTokenHandlerValidateSignatureTheoryData { @@ -105,7 +105,7 @@ public static TheoryData JsonWeb new MessageDetail( TokenLogMessages.IDX10000, "fakeParameter"), - typeof(ArgumentNullException), + ExceptionDetail.ExceptionType.ArgumentNull, new System.Diagnostics.StackFrame())) }, new JsonWebTokenHandlerValidateSignatureTheoryData @@ -120,7 +120,7 @@ public static TheoryData JsonWeb new MessageDetail( TokenLogMessages.IDX10504, LogHelper.MarkAsSecurityArtifact(unsignedToken, JwtTokenUtilities.SafeLogJwtToken)), - typeof(SecurityTokenInvalidSignatureException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidSignature, new System.Diagnostics.StackFrame())) }, new JsonWebTokenHandlerValidateSignatureTheoryData @@ -190,7 +190,7 @@ public static TheoryData JsonWeb ValidationFailureType.SignatureValidationFailed, new ExceptionDetail( new MessageDetail(TokenLogMessages.IDX10500), - typeof(SecurityTokenSignatureKeyNotFoundException), + ExceptionDetail.ExceptionType.SecurityTokenSignatureKeyNotFound, new System.Diagnostics.StackFrame())) }, new JsonWebTokenHandlerValidateSignatureTheoryData @@ -203,7 +203,7 @@ public static TheoryData JsonWeb ValidationFailureType.SignatureValidationFailed, new ExceptionDetail( new MessageDetail(TokenLogMessages.IDX10500), - typeof(SecurityTokenSignatureKeyNotFoundException), + ExceptionDetail.ExceptionType.SecurityTokenSignatureKeyNotFound, new System.Diagnostics.StackFrame())) } }; diff --git a/test/Microsoft.IdentityModel.Tokens.Tests/Validation/AlgorithmValidationResultTests.cs b/test/Microsoft.IdentityModel.Tokens.Tests/Validation/AlgorithmValidationResultTests.cs index 82fe4194af..0dc4f8e77a 100644 --- a/test/Microsoft.IdentityModel.Tokens.Tests/Validation/AlgorithmValidationResultTests.cs +++ b/test/Microsoft.IdentityModel.Tokens.Tests/Validation/AlgorithmValidationResultTests.cs @@ -59,7 +59,7 @@ public static TheoryData AlgorithmValidationTestCases new MessageDetail( LogMessages.IDX10000, LogHelper.MarkAsNonPII("validationParameters")), - typeof(ArgumentNullException), + ExceptionDetail.ExceptionType.ArgumentNull, new StackFrame(true))) }, new AlgorithmTheoryData @@ -81,7 +81,7 @@ public static TheoryData AlgorithmValidationTestCases LogMessages.IDX10696, LogHelper.MarkAsNonPII(SecurityAlgorithms.Sha256), securityKey), - typeof(SecurityTokenInvalidAlgorithmException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidAlgorithm, new StackFrame(true))) }, new AlgorithmTheoryData diff --git a/test/Microsoft.IdentityModel.Tokens.Tests/Validation/AudienceValidationResultTests.cs b/test/Microsoft.IdentityModel.Tokens.Tests/Validation/AudienceValidationResultTests.cs index 4c4a732613..064c30be8c 100644 --- a/test/Microsoft.IdentityModel.Tokens.Tests/Validation/AudienceValidationResultTests.cs +++ b/test/Microsoft.IdentityModel.Tokens.Tests/Validation/AudienceValidationResultTests.cs @@ -63,7 +63,7 @@ public static TheoryData ValidateAudienceParameter new MessageDetail( LogMessages.IDX10000, LogHelper.MarkAsNonPII("validationParameters")), - typeof(ArgumentNullException), + ExceptionDetail.ExceptionType.ArgumentNull, new StackFrame(true), null)), }, @@ -79,7 +79,7 @@ public static TheoryData ValidateAudienceParameter new MessageDetail( LogMessages.IDX10207, null), - typeof(SecurityTokenInvalidAudienceException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidAudience, new StackFrame(true), null)), }, @@ -96,7 +96,7 @@ public static TheoryData ValidateAudienceParameter new MessageDetail( LogMessages.IDX10206, null), - typeof(SecurityTokenInvalidAudienceException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidAudience, new StackFrame(true), null)), }, @@ -115,7 +115,7 @@ public static TheoryData ValidateAudienceParameter LogMessages.IDX10215, LogHelper.MarkAsNonPII("audience1"), LogHelper.MarkAsNonPII(String.Empty)), - typeof(SecurityTokenInvalidAudienceException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidAudience, new StackFrame(true), null)), }, @@ -134,7 +134,7 @@ public static TheoryData ValidateAudienceParameter LogMessages.IDX10215, LogHelper.MarkAsNonPII("audience1"), LogHelper.MarkAsNonPII(" ")), - typeof(SecurityTokenInvalidAudienceException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidAudience, new StackFrame(true), null)), } @@ -218,7 +218,7 @@ public static TheoryData ValidateAudienceTheoryDat LogMessages.IDX10215, LogHelper.MarkAsNonPII(commaAudience1), LogHelper.MarkAsNonPII(audience2)), - typeof(SecurityTokenInvalidAudienceException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidAudience, new StackFrame(true), null)), }, @@ -238,7 +238,7 @@ public static TheoryData ValidateAudienceTheoryDat LogMessages.IDX10215, LogHelper.MarkAsNonPII(commaAudience1), LogHelper.MarkAsNonPII(audience2Slash)), - typeof(SecurityTokenInvalidAudienceException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidAudience, new StackFrame(true), null)), }, @@ -257,7 +257,7 @@ public static TheoryData ValidateAudienceTheoryDat LogMessages.IDX10215, LogHelper.MarkAsNonPII(commaAudience2Slash), LogHelper.MarkAsNonPII(audience1)), - typeof(SecurityTokenInvalidAudienceException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidAudience, new StackFrame(true), null)), }, @@ -276,7 +276,7 @@ public static TheoryData ValidateAudienceTheoryDat LogMessages.IDX10215, LogHelper.MarkAsNonPII(commaAudience1), LogHelper.MarkAsNonPII(audience1Slash)), - typeof(SecurityTokenInvalidAudienceException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidAudience, new StackFrame(true), null)), }, @@ -303,7 +303,7 @@ public static TheoryData ValidateAudienceTheoryDat LogMessages.IDX10215, LogHelper.MarkAsNonPII(commaAudience1), LogHelper.MarkAsNonPII(commaAudience1Slash)), - typeof(SecurityTokenInvalidAudienceException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidAudience, new StackFrame(true), null)), }, @@ -330,7 +330,7 @@ public static TheoryData ValidateAudienceTheoryDat LogMessages.IDX10215, LogHelper.MarkAsNonPII(commaAudience1), LogHelper.MarkAsNonPII(audience1 + "A")), - typeof(SecurityTokenInvalidAudienceException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidAudience, new StackFrame(true), null)), }, @@ -349,7 +349,7 @@ public static TheoryData ValidateAudienceTheoryDat LogMessages.IDX10215, LogHelper.MarkAsNonPII(commaAudience1), LogHelper.MarkAsNonPII(audience1 + "//")), - typeof(SecurityTokenInvalidAudienceException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidAudience, new StackFrame(true), null)), }, @@ -368,7 +368,7 @@ public static TheoryData ValidateAudienceTheoryDat LogMessages.IDX10215, LogHelper.MarkAsNonPII(commaAudience1), LogHelper.MarkAsNonPII(commaAudience1 + "//")), - typeof(SecurityTokenInvalidAudienceException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidAudience, new StackFrame(true), null)), }, @@ -387,7 +387,7 @@ public static TheoryData ValidateAudienceTheoryDat LogMessages.IDX10215, LogHelper.MarkAsNonPII(commaAudience1Slash), LogHelper.MarkAsNonPII(audience1)), - typeof(SecurityTokenInvalidAudienceException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidAudience, new StackFrame(true), null)), }, @@ -414,7 +414,7 @@ public static TheoryData ValidateAudienceTheoryDat LogMessages.IDX10215, LogHelper.MarkAsNonPII(commaAudience2Slash), LogHelper.MarkAsNonPII(audience1)), - typeof(SecurityTokenInvalidAudienceException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidAudience, new StackFrame(true), null)), }, @@ -433,7 +433,7 @@ public static TheoryData ValidateAudienceTheoryDat LogMessages.IDX10215, LogHelper.MarkAsNonPII(commaAudience1Slash), LogHelper.MarkAsNonPII(audience1)), - typeof(SecurityTokenInvalidAudienceException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidAudience, new StackFrame(true), null)), }, @@ -460,7 +460,7 @@ public static TheoryData ValidateAudienceTheoryDat LogMessages.IDX10215, LogHelper.MarkAsNonPII(commaAudience1Slash), LogHelper.MarkAsNonPII(commaAudience2)), - typeof(SecurityTokenInvalidAudienceException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidAudience, new StackFrame(true), null)), }, @@ -479,7 +479,7 @@ public static TheoryData ValidateAudienceTheoryDat LogMessages.IDX10215, LogHelper.MarkAsNonPII(commaAudience1 + "//"), LogHelper.MarkAsNonPII(audience1)), - typeof(SecurityTokenInvalidAudienceException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidAudience, new StackFrame(true), null)), } diff --git a/test/Microsoft.IdentityModel.Tokens.Tests/Validation/IssuerValidationResultTests.cs b/test/Microsoft.IdentityModel.Tokens.Tests/Validation/IssuerValidationResultTests.cs index bd9ba6185c..2a887b10d3 100644 --- a/test/Microsoft.IdentityModel.Tokens.Tests/Validation/IssuerValidationResultTests.cs +++ b/test/Microsoft.IdentityModel.Tokens.Tests/Validation/IssuerValidationResultTests.cs @@ -68,7 +68,7 @@ public static TheoryData IssuerValdationResul LogHelper.MarkAsNonPII(validIssuer), LogHelper.MarkAsNonPII(Utility.SerializeAsSingleCommaDelimitedString(null)), LogHelper.MarkAsNonPII(null)), - typeof(SecurityTokenInvalidIssuerException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidIssuer, new StackFrame(true))), IsValid = false, SecurityToken = JsonUtilities.CreateUnsignedJsonWebToken(JwtRegisteredClaimNames.Iss, issClaim), @@ -86,7 +86,7 @@ public static TheoryData IssuerValdationResul new MessageDetail( LogMessages.IDX10000, LogHelper.MarkAsNonPII("validationParameters")), - typeof(ArgumentNullException), + ExceptionDetail.ExceptionType.ArgumentNull, new StackFrame(true), null)), IsValid = false, @@ -105,7 +105,7 @@ public static TheoryData IssuerValdationResul new MessageDetail( LogMessages.IDX10000, LogHelper.MarkAsNonPII("securityToken")), - typeof(ArgumentNullException), + ExceptionDetail.ExceptionType.ArgumentNull, new StackFrame(true), null)), IsValid = false, @@ -154,7 +154,7 @@ public static TheoryData IssuerValdationResul LogHelper.MarkAsNonPII(issClaim), LogHelper.MarkAsNonPII(Utility.SerializeAsSingleCommaDelimitedString(validIssuers)), LogHelper.MarkAsNonPII(null)), - typeof(SecurityTokenInvalidIssuerException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidIssuer, new StackFrame(true))), IsValid = false, SecurityToken = JsonUtilities.CreateUnsignedJsonWebToken(JwtRegisteredClaimNames.Iss, issClaim), diff --git a/test/Microsoft.IdentityModel.Tokens.Tests/Validation/LifetimeValidationResultTests.cs b/test/Microsoft.IdentityModel.Tokens.Tests/Validation/LifetimeValidationResultTests.cs index 504817363b..03eb7a9f6b 100644 --- a/test/Microsoft.IdentityModel.Tokens.Tests/Validation/LifetimeValidationResultTests.cs +++ b/test/Microsoft.IdentityModel.Tokens.Tests/Validation/LifetimeValidationResultTests.cs @@ -95,7 +95,7 @@ public static TheoryData ValidateLifetimeTestCases new MessageDetail( LogMessages.IDX10000, "validationParameters"), - typeof(ArgumentNullException), + ExceptionDetail.ExceptionType.ArgumentNull, new StackFrame(true), null)), }, @@ -112,7 +112,7 @@ public static TheoryData ValidateLifetimeTestCases new MessageDetail( LogMessages.IDX10225, "null"), - typeof(SecurityTokenNoExpirationException), + ExceptionDetail.ExceptionType.SecurityTokenNoExpiration, new StackFrame(true), null)), }, @@ -131,7 +131,7 @@ public static TheoryData ValidateLifetimeTestCases LogMessages.IDX10224, LogHelper.MarkAsNonPII(oneHourFromNow), LogHelper.MarkAsNonPII(oneHourAgo)), - typeof(SecurityTokenInvalidLifetimeException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidLifetime, new StackFrame(true), null)), }, @@ -150,7 +150,7 @@ public static TheoryData ValidateLifetimeTestCases LogMessages.IDX10222, LogHelper.MarkAsNonPII(oneHourFromNow), LogHelper.MarkAsNonPII(now)), - typeof(SecurityTokenNotYetValidException), + ExceptionDetail.ExceptionType.SecurityTokenNotYetValid, new StackFrame(true), null)), }, @@ -169,7 +169,7 @@ public static TheoryData ValidateLifetimeTestCases LogMessages.IDX10223, LogHelper.MarkAsNonPII(oneHourAgo), LogHelper.MarkAsNonPII(now)), - typeof(SecurityTokenExpiredException), + ExceptionDetail.ExceptionType.SecurityTokenExpired, new StackFrame(true), null)), }, @@ -188,7 +188,7 @@ public static TheoryData ValidateLifetimeTestCases LogMessages.IDX10222, LogHelper.MarkAsNonPII(sixMinutesFromNow), LogHelper.MarkAsNonPII(now)), - typeof(SecurityTokenNotYetValidException), + ExceptionDetail.ExceptionType.SecurityTokenNotYetValid, new StackFrame(true), null)), }, @@ -207,7 +207,7 @@ public static TheoryData ValidateLifetimeTestCases LogMessages.IDX10223, LogHelper.MarkAsNonPII(sixMinutesAgo), LogHelper.MarkAsNonPII(now)), - typeof(SecurityTokenExpiredException), + ExceptionDetail.ExceptionType.SecurityTokenExpired, new StackFrame(true), null)), } diff --git a/test/Microsoft.IdentityModel.Tokens.Tests/Validation/ReplayValidationResultTests.cs b/test/Microsoft.IdentityModel.Tokens.Tests/Validation/ReplayValidationResultTests.cs index 9e97a7ba65..5d6124452f 100644 --- a/test/Microsoft.IdentityModel.Tokens.Tests/Validation/ReplayValidationResultTests.cs +++ b/test/Microsoft.IdentityModel.Tokens.Tests/Validation/ReplayValidationResultTests.cs @@ -82,7 +82,7 @@ public static TheoryData TokenReplayValidationTestCases new MessageDetail( LogMessages.IDX10000, LogHelper.MarkAsNonPII("securityToken")), - typeof(ArgumentNullException), + ExceptionDetail.ExceptionType.ArgumentNull, new StackFrame(), null)) }, @@ -100,7 +100,7 @@ public static TheoryData TokenReplayValidationTestCases new MessageDetail( LogMessages.IDX10000, LogHelper.MarkAsNonPII("securityToken")), - typeof(ArgumentNullException), + ExceptionDetail.ExceptionType.ArgumentNull, new StackFrame(), null)) }, @@ -118,7 +118,7 @@ public static TheoryData TokenReplayValidationTestCases new MessageDetail( LogMessages.IDX10000, LogHelper.MarkAsNonPII("validationParameters")), - typeof(ArgumentNullException), + ExceptionDetail.ExceptionType.ArgumentNull, new StackFrame(), null)) }, @@ -143,7 +143,7 @@ public static TheoryData TokenReplayValidationTestCases new MessageDetail( LogMessages.IDX10227, LogHelper.MarkAsUnsafeSecurityArtifact("token", t => t.ToString())), - typeof(SecurityTokenReplayDetectedException), + ExceptionDetail.ExceptionType.SecurityTokenReplayDetected, new StackFrame(), null)) }, @@ -168,7 +168,7 @@ public static TheoryData TokenReplayValidationTestCases new MessageDetail( LogMessages.IDX10228, LogHelper.MarkAsUnsafeSecurityArtifact("token", t => t.ToString())), - typeof(SecurityTokenReplayDetectedException), + ExceptionDetail.ExceptionType.SecurityTokenReplayDetected, new StackFrame(), null)) }, @@ -193,7 +193,7 @@ public static TheoryData TokenReplayValidationTestCases new MessageDetail( LogMessages.IDX10229, LogHelper.MarkAsUnsafeSecurityArtifact("token", t => t.ToString())), - typeof(SecurityTokenReplayAddFailedException), + ExceptionDetail.ExceptionType.SecurityTokenReplayDetected, new StackFrame(), null)) } diff --git a/test/Microsoft.IdentityModel.Tokens.Tests/Validation/SigningKeyValidationResultTests.cs b/test/Microsoft.IdentityModel.Tokens.Tests/Validation/SigningKeyValidationResultTests.cs index 98e10456d0..8e3d9a8fd2 100644 --- a/test/Microsoft.IdentityModel.Tokens.Tests/Validation/SigningKeyValidationResultTests.cs +++ b/test/Microsoft.IdentityModel.Tokens.Tests/Validation/SigningKeyValidationResultTests.cs @@ -69,7 +69,7 @@ public static TheoryData SigningKeyValidationTes ValidationFailureType.NullArgument, new ExceptionDetail( new MessageDetail(LogMessages.IDX10253), - typeof(ArgumentNullException), + ExceptionDetail.ExceptionType.ArgumentNull, new StackFrame(true))) }, new SigningKeyValidationTheoryData @@ -86,7 +86,7 @@ public static TheoryData SigningKeyValidationTes new MessageDetail( LogMessages.IDX10000, LogHelper.MarkAsNonPII("securityToken")), - typeof(ArgumentNullException), + ExceptionDetail.ExceptionType.ArgumentNull, new StackFrame(true))) }, new SigningKeyValidationTheoryData @@ -103,7 +103,7 @@ public static TheoryData SigningKeyValidationTes new MessageDetail( LogMessages.IDX10000, LogHelper.MarkAsNonPII("validationParameters")), - typeof(ArgumentNullException), + ExceptionDetail.ExceptionType.ArgumentNull, new StackFrame(true))) }, new SigningKeyValidationTheoryData @@ -121,7 +121,7 @@ public static TheoryData SigningKeyValidationTes LogMessages.IDX10249, LogHelper.MarkAsNonPII(utcExpired), LogHelper.MarkAsNonPII(utcNow)), - typeof(SecurityTokenInvalidSigningKeyException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidSigningKey, new StackFrame(true))) }, new SigningKeyValidationTheoryData @@ -139,7 +139,7 @@ public static TheoryData SigningKeyValidationTes LogMessages.IDX10248, LogHelper.MarkAsNonPII(utcNotYetValid), LogHelper.MarkAsNonPII(utcNow)), - typeof(SecurityTokenInvalidSigningKeyException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidSigningKey, new StackFrame(true))) }, new SigningKeyValidationTheoryData @@ -154,7 +154,7 @@ public static TheoryData SigningKeyValidationTes ValidationFailureType.NullArgument, new ExceptionDetail( new MessageDetail(LogMessages.IDX10253), - typeof(ArgumentNullException), + ExceptionDetail.ExceptionType.ArgumentNull, new StackFrame(true))) }, diff --git a/test/Microsoft.IdentityModel.Tokens.Tests/Validation/TokenTypeValidationResultTests.cs b/test/Microsoft.IdentityModel.Tokens.Tests/Validation/TokenTypeValidationResultTests.cs index 9bba0817b7..11548f61ad 100644 --- a/test/Microsoft.IdentityModel.Tokens.Tests/Validation/TokenTypeValidationResultTests.cs +++ b/test/Microsoft.IdentityModel.Tokens.Tests/Validation/TokenTypeValidationResultTests.cs @@ -77,7 +77,7 @@ public static TheoryData TokenTypeValidationTestCases new MessageDetail( LogMessages.IDX10000, LogHelper.MarkAsNonPII("securityToken")), - typeof(ArgumentNullException), + ExceptionDetail.ExceptionType.ArgumentNull, new StackFrame(true))) }, new TokenTypeTheoryData @@ -94,7 +94,7 @@ public static TheoryData TokenTypeValidationTestCases new MessageDetail( LogMessages.IDX10000, LogHelper.MarkAsNonPII("validationParameters")), - typeof(ArgumentNullException), + ExceptionDetail.ExceptionType.ArgumentNull, new StackFrame(true))) }, new TokenTypeTheoryData @@ -112,7 +112,7 @@ public static TheoryData TokenTypeValidationTestCases new MessageDetail( LogMessages.IDX10256, LogHelper.MarkAsNonPII("type")), - typeof(SecurityTokenInvalidTypeException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidType, new StackFrame(true))) }, new TokenTypeTheoryData @@ -130,7 +130,7 @@ public static TheoryData TokenTypeValidationTestCases new MessageDetail( LogMessages.IDX10256, LogHelper.MarkAsNonPII("type")), - typeof(SecurityTokenInvalidTypeException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidType, new StackFrame(true))) }, new TokenTypeTheoryData @@ -149,7 +149,7 @@ public static TheoryData TokenTypeValidationTestCases LogMessages.IDX10257, LogHelper.MarkAsNonPII("type"), LogHelper.MarkAsNonPII(Utility.SerializeAsSingleCommaDelimitedString(validTypesNoJwt))), - typeof(SecurityTokenInvalidTypeException), + ExceptionDetail.ExceptionType.SecurityTokenInvalidType, new StackFrame(true))) } }; From 6d1c3ecd1f177fd9813bfbb4426b07bb300af874 Mon Sep 17 00:00:00 2001 From: Ignacio Inglese Date: Thu, 8 Aug 2024 15:47:05 +0100 Subject: [PATCH 2/3] Added tests --- .../Validation/ExceptionDetail.cs | 1 + .../ExpectedException.cs | 19 ++ .../Validation/ExceptionDetailsTests.cs | 181 ++++++++++++++++++ 3 files changed, 201 insertions(+) create mode 100644 test/Microsoft.IdentityModel.Tokens.Tests/Validation/ExceptionDetailsTests.cs diff --git a/src/Microsoft.IdentityModel.Tokens/Validation/ExceptionDetail.cs b/src/Microsoft.IdentityModel.Tokens/Validation/ExceptionDetail.cs index fa048a5f08..c2416d3be4 100644 --- a/src/Microsoft.IdentityModel.Tokens/Validation/ExceptionDetail.cs +++ b/src/Microsoft.IdentityModel.Tokens/Validation/ExceptionDetail.cs @@ -95,6 +95,7 @@ public enum ExceptionType SecurityTokenReplayDetected, SecurityTokenReplayAddFailed, SecurityTokenSignatureKeyNotFound, + ExceptionTypeCount } private Exception ExceptionFromType(ExceptionType exceptionType, Exception innerException) diff --git a/test/Microsoft.IdentityModel.TestUtils/ExpectedException.cs b/test/Microsoft.IdentityModel.TestUtils/ExpectedException.cs index d95be38f45..1fea9cdd20 100644 --- a/test/Microsoft.IdentityModel.TestUtils/ExpectedException.cs +++ b/test/Microsoft.IdentityModel.TestUtils/ExpectedException.cs @@ -319,6 +319,25 @@ public static ExpectedException JsonException(string substringExpected = null, T { return new ExpectedException(typeof(JsonException), substringExpected, innerTypeExpected); } + public static ExpectedException SecurityTokenDecompressionFailedException(string substringExpected = null, Type innerTypeExpected = null) + { + return new ExpectedException(typeof(SecurityTokenDecompressionFailedException), substringExpected, innerTypeExpected); + } + + public static ExpectedException SecurityTokenMalformedException(string substringExpected = null, Type innerTypeExpected = null) + { + return new ExpectedException(typeof(SecurityTokenMalformedException), substringExpected, innerTypeExpected); + } + + public static ExpectedException SecurityTokenReplayDetectedException(string substringExpected = null, Type innerTypeExpected = null) + { + return new ExpectedException(typeof(SecurityTokenReplayDetectedException), substringExpected, innerTypeExpected); + } + + public static ExpectedException SecurityTokenReplayAddFailedException(string substringExpected = null, Type innerTypeExpected = null) + { + return new ExpectedException(typeof(SecurityTokenReplayAddFailedException), substringExpected, innerTypeExpected); + } public bool IgnoreExceptionType { get; set; } diff --git a/test/Microsoft.IdentityModel.Tokens.Tests/Validation/ExceptionDetailsTests.cs b/test/Microsoft.IdentityModel.Tokens.Tests/Validation/ExceptionDetailsTests.cs new file mode 100644 index 0000000000..62b1bd2418 --- /dev/null +++ b/test/Microsoft.IdentityModel.Tokens.Tests/Validation/ExceptionDetailsTests.cs @@ -0,0 +1,181 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + + +using System; +using System.Linq; +using Microsoft.IdentityModel.TestUtils; +using Xunit; + +namespace Microsoft.IdentityModel.Tokens.Tests +{ + public class ExceptionDetailsTests + { + [Theory, MemberData(nameof(ExceptionDetailsTestCases), DisableDiscoveryEnumeration = true)] + public void ExceptionDetails(ExceptionDetailsTheoryData theoryData) + { + var context = TestUtilities.WriteHeader($"{this}.ExceptionDetails", theoryData); + ExceptionDetail exceptionDetail = new ExceptionDetail( + new MessageDetail(""), + theoryData.ExceptionType, + new System.Diagnostics.StackFrame()); + + theoryData.ExpectedException.ProcessException(exceptionDetail.GetException(), context); + + TestUtilities.AssertFailIfErrors(context); + } + + [Fact] + public void ExceptionDetails_UnknownType_Throws() + { + ExceptionDetail exceptionDetail = new ExceptionDetail( + new MessageDetail(""), + ExceptionDetail.ExceptionType.Unknown, + new System.Diagnostics.StackFrame()); + + Assert.Throws(() => exceptionDetail.GetException()); + } + + [Fact] + public void All_ExceptionDetails_HaveTests() + { + // If this test fails, we are missing a test for a new ExceptionDetail.ExceptionType + Assert.Equal(((int)ExceptionDetail.ExceptionType.ExceptionTypeCount), ExceptionDetailsTestCases.Count()); + } + + public static TheoryData ExceptionDetailsTestCases + { + get + { + return new() + { + new ExceptionDetailsTheoryData + { + TestId = "ArgumentNull", + ExceptionType = ExceptionDetail.ExceptionType.ArgumentNull, + ExpectedException = ExpectedException.ArgumentNullException(), + }, + new ExceptionDetailsTheoryData + { + TestId = "InvalidOperation", + ExceptionType = ExceptionDetail.ExceptionType.InvalidOperation, + ExpectedException = ExpectedException.InvalidOperationException(), + }, + new ExceptionDetailsTheoryData + { + TestId = "SecurityToken", + ExceptionType = ExceptionDetail.ExceptionType.SecurityToken, + ExpectedException = ExpectedException.SecurityTokenException(), + }, + new ExceptionDetailsTheoryData + { + TestId = "SecurityTokenDecompressionFailed", + ExceptionType = ExceptionDetail.ExceptionType.SecurityTokenDecompressionFailed, + ExpectedException = ExpectedException.SecurityTokenDecompressionFailedException(), + }, + new ExceptionDetailsTheoryData + { + TestId = "SecurityTokenDecryptionFailed", + ExceptionType = ExceptionDetail.ExceptionType.SecurityTokenDecryptionFailed, + ExpectedException = ExpectedException.SecurityTokenDecryptionFailedException(), + }, + new ExceptionDetailsTheoryData + { + TestId = "SecurityTokenExpired", + ExceptionType = ExceptionDetail.ExceptionType.SecurityTokenExpired, + ExpectedException = ExpectedException.SecurityTokenExpiredException(), + }, + new ExceptionDetailsTheoryData + { + TestId = "SecurityTokenInvalidAudience", + ExceptionType = ExceptionDetail.ExceptionType.SecurityTokenInvalidAudience, + ExpectedException = ExpectedException.SecurityTokenInvalidAudienceException(), + }, + new ExceptionDetailsTheoryData + { + TestId = "SecurityTokenInvalidAlgorithm", + ExceptionType = ExceptionDetail.ExceptionType.SecurityTokenInvalidAlgorithm, + ExpectedException = ExpectedException.SecurityTokenInvalidAlgorithmException(), + }, + new ExceptionDetailsTheoryData + { + TestId = "SecurityTokenInvalidIssuer", + ExceptionType = ExceptionDetail.ExceptionType.SecurityTokenInvalidIssuer, + ExpectedException = ExpectedException.SecurityTokenInvalidIssuerException(), + }, + new ExceptionDetailsTheoryData + { + TestId = "SecurityTokenInvalidLifetime", + ExceptionType = ExceptionDetail.ExceptionType.SecurityTokenInvalidLifetime, + ExpectedException = ExpectedException.SecurityTokenInvalidLifetimeException(), + }, + new ExceptionDetailsTheoryData + { + TestId = "SecurityTokenInvalidSigningKey", + ExceptionType = ExceptionDetail.ExceptionType.SecurityTokenInvalidSigningKey, + ExpectedException = ExpectedException.SecurityTokenInvalidSigningKeyException(), + }, + new ExceptionDetailsTheoryData + { + TestId = "SecurityTokenInvalidSignature", + ExceptionType = ExceptionDetail.ExceptionType.SecurityTokenInvalidSignature, + ExpectedException = ExpectedException.SecurityTokenInvalidSignatureException(), + }, + new ExceptionDetailsTheoryData + { + TestId = "SecurityTokenInvalidType", + ExceptionType = ExceptionDetail.ExceptionType.SecurityTokenInvalidType, + ExpectedException = ExpectedException.SecurityTokenInvalidTypeException(), + }, + new ExceptionDetailsTheoryData + { + TestId = "SecurityTokenKeyWrap", + ExceptionType = ExceptionDetail.ExceptionType.SecurityTokenKeyWrap, + ExpectedException = ExpectedException.SecurityTokenKeyWrapException(), + }, + new ExceptionDetailsTheoryData + { + TestId = "SecurityTokenMalformed", + ExceptionType = ExceptionDetail.ExceptionType.SecurityTokenMalformed, + ExpectedException = ExpectedException.SecurityTokenMalformedException(), + }, + new ExceptionDetailsTheoryData + { + TestId = "SecurityTokenNoExpiration", + ExceptionType = ExceptionDetail.ExceptionType.SecurityTokenNoExpiration, + ExpectedException = ExpectedException.SecurityTokenNoExpirationException(), + }, + new ExceptionDetailsTheoryData + { + TestId = "SecurityTokenNotYetValid", + ExceptionType = ExceptionDetail.ExceptionType.SecurityTokenNotYetValid, + ExpectedException = ExpectedException.SecurityTokenNotYetValidException(), + }, + new ExceptionDetailsTheoryData + { + TestId = "SecurityTokenReplayDetected", + ExceptionType = ExceptionDetail.ExceptionType.SecurityTokenReplayDetected, + ExpectedException = ExpectedException.SecurityTokenReplayDetectedException(), + }, + new ExceptionDetailsTheoryData + { + TestId = "SecurityTokenReplayAddFailed", + ExceptionType = ExceptionDetail.ExceptionType.SecurityTokenReplayAddFailed, + ExpectedException = ExpectedException.SecurityTokenReplayAddFailedException(), + }, + new ExceptionDetailsTheoryData + { + TestId = "SecurityTokenSignatureKeyNotFound", + ExceptionType = ExceptionDetail.ExceptionType.SecurityTokenSignatureKeyNotFound, + ExpectedException = ExpectedException.SecurityTokenSignatureKeyNotFoundException(), + }, + }; + } + } + } + + public class ExceptionDetailsTheoryData : TheoryDataBase + { + internal ExceptionDetail.ExceptionType ExceptionType { get; set; } + } +} From fe0cac17954cea35879940f741b9f3342471f54f Mon Sep 17 00:00:00 2001 From: Ignacio Inglese Date: Thu, 8 Aug 2024 17:26:08 +0100 Subject: [PATCH 3/3] Added missing new line --- test/Microsoft.IdentityModel.TestUtils/ExpectedException.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Microsoft.IdentityModel.TestUtils/ExpectedException.cs b/test/Microsoft.IdentityModel.TestUtils/ExpectedException.cs index 1fea9cdd20..1d8eb223ed 100644 --- a/test/Microsoft.IdentityModel.TestUtils/ExpectedException.cs +++ b/test/Microsoft.IdentityModel.TestUtils/ExpectedException.cs @@ -319,6 +319,7 @@ public static ExpectedException JsonException(string substringExpected = null, T { return new ExpectedException(typeof(JsonException), substringExpected, innerTypeExpected); } + public static ExpectedException SecurityTokenDecompressionFailedException(string substringExpected = null, Type innerTypeExpected = null) { return new ExpectedException(typeof(SecurityTokenDecompressionFailedException), substringExpected, innerTypeExpected);