diff --git a/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenArgumentNullException.cs b/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenArgumentNullException.cs
new file mode 100644
index 0000000000..d18217d237
--- /dev/null
+++ b/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenArgumentNullException.cs
@@ -0,0 +1,97 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+using System;
+using System.Diagnostics;
+#if !NET8_0_OR_GREATER
+using System.Text;
+#endif
+
+#nullable enable
+
+namespace Microsoft.IdentityModel.Tokens
+{
+ internal class SecurityTokenArgumentNullException : ArgumentNullException, ISecurityTokenException
+ {
+ private string? _stackTrace;
+ private ValidationError? _validationError;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public SecurityTokenArgumentNullException()
+ : base()
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class with a specified null parameter.
+ ///
+ /// The name of the null parameter that triggered the exception.
+ public SecurityTokenArgumentNullException(string? paramName)
+ : base(paramName)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class with a specified error message
+ /// and a reference to the inner exception that is the cause of this exception.
+ ///
+ /// The error message that explains the reason for the exception.
+ /// The that is the cause of the current exception, or a null reference if no inner exception is specified.
+ public SecurityTokenArgumentNullException(string? message, Exception? innerException)
+ : base(message, innerException)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class with a specified null parameter and an error message.
+ ///
+ /// The name of the null parameter that triggered the exception.
+ /// The error message that explains the reason for the exception.
+ public SecurityTokenArgumentNullException(string? paramName, string? message)
+ : base(paramName, message)
+ {
+ }
+
+ ///
+ /// Sets the that is associated with the exception.
+ ///
+ /// The validation error to associate with the exception.
+ public void SetValidationError(ValidationError validationError)
+ {
+ _validationError = validationError;
+ }
+
+
+ ///
+ /// Gets the stack trace that is captured when the exception is created.
+ ///
+ public override string? StackTrace
+ {
+ get
+ {
+ if (_stackTrace == null)
+ {
+ if (_validationError == null)
+ return base.StackTrace;
+#if NET8_0_OR_GREATER
+ _stackTrace = new StackTrace(_validationError.StackFrames).ToString();
+#else
+ StringBuilder sb = new();
+ foreach (StackFrame frame in _validationError.StackFrames)
+ {
+ sb.Append(frame.ToString());
+ sb.Append(Environment.NewLine);
+ }
+
+ _stackTrace = sb.ToString();
+#endif
+ }
+
+ return _stackTrace;
+ }
+ }
+ }
+}
+#nullable restore
diff --git a/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenException.cs b/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenException.cs
index be701d54c5..1b7096ff30 100644
--- a/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenException.cs
+++ b/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenException.cs
@@ -20,11 +20,13 @@ namespace Microsoft.IdentityModel.Tokens
/// Represents a security token exception.
///
[Serializable]
- public class SecurityTokenException : Exception
+ public class SecurityTokenException : Exception, ISecurityTokenException
{
[NonSerialized]
private string _stackTrace;
+ private ValidationError _validationError;
+
///
/// Initializes a new instance of the class.
///
@@ -66,6 +68,15 @@ protected SecurityTokenException(SerializationInfo info, StreamingContext contex
{
}
+ ///
+ /// Sets the that caused the exception.
+ ///
+ ///
+ public void SetValidationError(ValidationError validationError)
+ {
+ _validationError = validationError;
+ }
+
///
/// Gets the stack trace that is captured when the exception is created.
///
@@ -75,13 +86,13 @@ public override string StackTrace
{
if (_stackTrace == null)
{
- if (ValidationError == null)
+ if (_validationError == null)
return base.StackTrace;
#if NET8_0_OR_GREATER
- _stackTrace = new StackTrace(ValidationError.StackFrames).ToString();
+ _stackTrace = new StackTrace(_validationError.StackFrames).ToString();
#else
StringBuilder sb = new();
- foreach (StackFrame frame in ValidationError.StackFrames)
+ foreach (StackFrame frame in _validationError.StackFrames)
{
sb.Append(frame.ToString());
sb.Append(Environment.NewLine);
@@ -104,11 +115,6 @@ public override string Source
set => base.Source = value;
}
- internal ValidationError ValidationError
- {
- get; set;
- }
-
#if NET472 || NETSTANDARD2_0 || NET6_0_OR_GREATER
///
/// When overridden in a derived class, sets the System.Runtime.Serialization.SerializationInfo
diff --git a/src/Microsoft.IdentityModel.Tokens/Validation/Results/Details/LifetimeValidationError.cs b/src/Microsoft.IdentityModel.Tokens/Validation/Results/Details/LifetimeValidationError.cs
index a42da3150d..40537d497c 100644
--- a/src/Microsoft.IdentityModel.Tokens/Validation/Results/Details/LifetimeValidationError.cs
+++ b/src/Microsoft.IdentityModel.Tokens/Validation/Results/Details/LifetimeValidationError.cs
@@ -46,7 +46,7 @@ public LifetimeValidationError(
_additionalInformation = additionalInformation.Value;
}
- protected override void AddAdditionalInformation(Exception exception)
+ internal override void AddAdditionalInformation(ISecurityTokenException exception)
{
if (exception is SecurityTokenExpiredException expiredException &&
_additionalInformation.ExpirationDate.HasValue)
diff --git a/src/Microsoft.IdentityModel.Tokens/Validation/Results/Details/ValidationError.cs b/src/Microsoft.IdentityModel.Tokens/Validation/Results/Details/ValidationError.cs
index 653d6ff22b..7ccc11dc6e 100644
--- a/src/Microsoft.IdentityModel.Tokens/Validation/Results/Details/ValidationError.cs
+++ b/src/Microsoft.IdentityModel.Tokens/Validation/Results/Details/ValidationError.cs
@@ -7,10 +7,15 @@
namespace Microsoft.IdentityModel.Tokens
{
+ internal interface ISecurityTokenException
+ {
+ void SetValidationError(ValidationError validationError);
+ }
+
///
/// Contains information so that Exceptions can be logged or thrown written as required.
///
- internal class ValidationError
+ public class ValidationError
{
private Type _exceptionType;
@@ -21,7 +26,7 @@ internal class ValidationError
/// is the type of exception that occurred.
/// is the type of validation failure that occurred.
/// is the stack frame where the exception occurred.
- public ValidationError(
+ internal ValidationError(
MessageDetail MessageDetail,
ValidationFailureType failureType,
Type exceptionType,
@@ -38,7 +43,7 @@ public ValidationError(
/// is the type of validation failure that occurred.
/// is the stack frame where the exception occurred.
/// is the inner exception that occurred.
- public ValidationError(
+ internal ValidationError(
MessageDetail messageDetail,
ValidationFailureType failureType,
Type exceptionType,
@@ -55,7 +60,7 @@ public ValidationError(
};
}
- public ValidationError(
+ internal ValidationError(
MessageDetail messageDetail,
ValidationFailureType failureType,
Type exceptionType,
@@ -79,10 +84,12 @@ public ValidationError(
public Exception GetException()
{
Exception exception = GetException(ExceptionType, InnerException);
- if (exception is SecurityTokenException securityTokenException)
- securityTokenException.ValidationError = this;
- AddAdditionalInformation(exception);
+ if (exception is ISecurityTokenException securityTokenException)
+ {
+ securityTokenException.SetValidationError(this);
+ AddAdditionalInformation(securityTokenException);
+ }
return exception;
}
@@ -127,8 +134,8 @@ private Exception GetException(Type exceptionType, Exception innerException)
exception = new SecurityTokenMalformedException(MessageDetail.Message);
else if (exceptionType == typeof(SecurityTokenInvalidSignatureException))
exception = new SecurityTokenInvalidSignatureException(MessageDetail.Message);
- else if (exceptionType == typeof(ArgumentNullException))
- exception = new ArgumentNullException(MessageDetail.Message);
+ else if (exceptionType == typeof(SecurityTokenArgumentNullException))
+ exception = new SecurityTokenArgumentNullException(MessageDetail.Message);
else if (exceptionType == typeof(SecurityTokenInvalidAlgorithmException))
exception = new SecurityTokenInvalidAlgorithmException(MessageDetail.Message);
else if (exceptionType == typeof(SecurityTokenInvalidAlgorithmException))
@@ -174,8 +181,8 @@ private Exception GetException(Type exceptionType, Exception innerException)
exception = new SecurityTokenMalformedException(MessageDetail.Message, actualException);
else if (exceptionType == typeof(SecurityTokenInvalidSignatureException))
exception = new SecurityTokenInvalidSignatureException(MessageDetail.Message, actualException);
- else if (exceptionType == typeof(ArgumentNullException))
- exception = new ArgumentNullException(MessageDetail.Message, actualException);
+ else if (exceptionType == typeof(SecurityTokenArgumentNullException))
+ exception = new SecurityTokenArgumentNullException(MessageDetail.Message, actualException);
else if (exceptionType == typeof(SecurityTokenInvalidAlgorithmException))
exception = new SecurityTokenInvalidAlgorithmException(MessageDetail.Message, actualException);
else if (exceptionType == typeof(SecurityTokenInvalidAlgorithmException))
@@ -187,21 +194,21 @@ private Exception GetException(Type exceptionType, Exception innerException)
return exception;
}
- protected virtual void AddAdditionalInformation(Exception exception)
+ internal virtual void AddAdditionalInformation(ISecurityTokenException exception)
{
// base implementation is no-op. Derived classes can override to add additional information to the exception.
}
- internal static ValidationError NullParameter(string parameterName, StackFrame stackFrame) => new ValidationError(
+ internal static ValidationError NullParameter(string parameterName, StackFrame stackFrame) => new(
MessageDetail.NullParameter(parameterName),
ValidationFailureType.NullArgument,
- typeof(ArgumentNullException),
+ typeof(SecurityTokenArgumentNullException),
stackFrame);
///
/// Gets the type of validation failure that occurred.
///
- public ValidationFailureType FailureType { get; }
+ internal ValidationFailureType FailureType { get; }
///
/// Gets the type of exception that occurred.
@@ -221,7 +228,7 @@ protected virtual void AddAdditionalInformation(Exception exception)
///
/// Gets the message details that are used to generate the exception message.
///
- public MessageDetail MessageDetail { get; }
+ internal MessageDetail MessageDetail { get; }
///
/// Gets the stack frames where the exception occurred.
diff --git a/src/Microsoft.IdentityModel.Tokens/Validation/Results/ValidatedToken.cs b/src/Microsoft.IdentityModel.Tokens/Validation/Results/ValidatedToken.cs
index 7a063181c2..3722fc4e8e 100644
--- a/src/Microsoft.IdentityModel.Tokens/Validation/Results/ValidatedToken.cs
+++ b/src/Microsoft.IdentityModel.Tokens/Validation/Results/ValidatedToken.cs
@@ -49,12 +49,19 @@ public void Log()
#region Validated Properties
public ValidatedToken? ActorValidationResult { get; internal set; }
+
public string? ValidatedAudience { get; internal set; }
+
public ValidatedIssuer? ValidatedIssuer { get; internal set; }
+
public ValidatedLifetime? ValidatedLifetime { get; internal set; }
+
public DateTime? ValidatedTokenReplayExpirationTime { get; internal set; }
+
public ValidatedTokenType? ValidatedTokenType { get; internal set; }
+
public SecurityKey? ValidatedSigningKey { get; internal set; }
+
public ValidatedSigningKeyLifetime? ValidatedSigningKeyLifetime { get; internal set; }
#endregion
diff --git a/src/Microsoft.IdentityModel.Tokens/Validation/Validators.IssuerSigningKey.cs b/src/Microsoft.IdentityModel.Tokens/Validation/Validators.IssuerSigningKey.cs
index 332390dc52..e5a8162370 100644
--- a/src/Microsoft.IdentityModel.Tokens/Validation/Validators.IssuerSigningKey.cs
+++ b/src/Microsoft.IdentityModel.Tokens/Validation/Validators.IssuerSigningKey.cs
@@ -42,9 +42,9 @@ public static partial class Validators
/// The to be used for validating the token.
/// The to be used for validation.
/// The to be used for logging.
- /// if 'securityKey' is null and ValidateIssuerSigningKey is true.
- /// if 'securityToken' is null and ValidateIssuerSigningKey is true.
- /// if 'validationParameters' is null.
+ /// if 'securityKey' is null and ValidateIssuerSigningKey is true.
+ /// if 'securityToken' is null and ValidateIssuerSigningKey is true.
+ /// if 'validationParameters' is null.
internal static ValidationResult ValidateIssuerSigningKey(
SecurityKey securityKey,
SecurityToken securityToken,
@@ -63,7 +63,7 @@ internal static ValidationResult ValidateIssuerSign
return new ValidationError(
new MessageDetail(LogMessages.IDX10253, nameof(securityKey)),
ValidationFailureType.SigningKeyValidationFailed,
- typeof(ArgumentNullException),
+ typeof(SecurityTokenArgumentNullException),
new StackFrame(true));
if (securityToken == null)
diff --git a/test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenHandler.DecryptTokenTests.cs b/test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenHandler.DecryptTokenTests.cs
index e36a598de3..5c37fbc941 100644
--- a/test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenHandler.DecryptTokenTests.cs
+++ b/test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenHandler.DecryptTokenTests.cs
@@ -120,11 +120,11 @@ public static TheoryData JsonWebTokenHandlerDecryptTo
TestId = "Invalid_SecurityTokenIsNull",
Token = null,
ValidationParameters = new ValidationParameters(),
- ExpectedException = ExpectedException.ArgumentNullException("IDX10000:"),
+ ExpectedException = ExpectedException.SecurityTokenArgumentNullException("IDX10000:"),
Result = new ValidationError(
new MessageDetail(TokenLogMessages.IDX10000, "jwtToken"),
ValidationFailureType.NullArgument,
- typeof(ArgumentNullException),
+ typeof(SecurityTokenArgumentNullException),
null),
},
new TokenDecryptingTheoryData
@@ -132,11 +132,11 @@ public static TheoryData JsonWebTokenHandlerDecryptTo
TestId = "Invalid_ValidationParametersIsNull",
Token = token,
ValidationParameters = null,
- ExpectedException = ExpectedException.ArgumentNullException("IDX10000:"),
+ ExpectedException = ExpectedException.SecurityTokenArgumentNullException("IDX10000:"),
Result = new ValidationError(
new MessageDetail(TokenLogMessages.IDX10000, "validationParameters"),
ValidationFailureType.NullArgument,
- typeof(ArgumentNullException),
+ typeof(SecurityTokenArgumentNullException),
null),
},
new TokenDecryptingTheoryData
diff --git a/test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenHandler.ReadTokenTests.cs b/test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenHandler.ReadTokenTests.cs
index f89abdc4a0..eebf8cdd85 100644
--- a/test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenHandler.ReadTokenTests.cs
+++ b/test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenHandler.ReadTokenTests.cs
@@ -71,26 +71,26 @@ public static TheoryData JsonWebTokenHandlerReadTokenTes
{
TestId = "Invalid_NullToken",
Token = null,
- ExpectedException = ExpectedException.ArgumentNullException("IDX10000:"),
+ ExpectedException = ExpectedException.SecurityTokenArgumentNullException("IDX10000:"),
Result = new ValidationError(
new MessageDetail(
TokenLogMessages.IDX10000,
LogHelper.MarkAsNonPII("token")),
ValidationFailureType.NullArgument,
- typeof(ArgumentNullException),
+ typeof(SecurityTokenArgumentNullException),
null)
},
new TokenReadingTheoryData
{
TestId = "Invalid_EmptyToken",
Token = string.Empty,
- ExpectedException = ExpectedException.ArgumentNullException("IDX10000:"),
+ ExpectedException = ExpectedException.SecurityTokenArgumentNullException("IDX10000:"),
Result = new ValidationError(
new MessageDetail(
TokenLogMessages.IDX10000,
LogHelper.MarkAsNonPII("token")),
ValidationFailureType.NullArgument,
- typeof(ArgumentNullException),
+ typeof(SecurityTokenArgumentNullException),
null)
},
new TokenReadingTheoryData
diff --git a/test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenHandler.ValidateSignatureTests.cs b/test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenHandler.ValidateSignatureTests.cs
index b26d965339..a74315ff12 100644
--- a/test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenHandler.ValidateSignatureTests.cs
+++ b/test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenHandler.ValidateSignatureTests.cs
@@ -81,26 +81,26 @@ public static TheoryData JsonWeb
new JsonWebTokenHandlerValidateSignatureTheoryData {
TestId = "Invalid_Null_JWT",
JWT = null,
- ExpectedException = ExpectedException.ArgumentNullException("IDX10000:"),
+ ExpectedException = ExpectedException.SecurityTokenArgumentNullException("IDX10000:"),
Result = new ValidationError(
new MessageDetail(
TokenLogMessages.IDX10000,
"jwtToken"),
ValidationFailureType.NullArgument,
- typeof(ArgumentNullException),
+ typeof(SecurityTokenArgumentNullException),
null)
},
new JsonWebTokenHandlerValidateSignatureTheoryData {
TestId = "Invalid_Null_ValidationParameters",
JWT = new JsonWebToken(EncodedJwts.LiveJwt),
ValidationParameters = null,
- ExpectedException = ExpectedException.ArgumentNullException("IDX10000:"),
+ ExpectedException = ExpectedException.SecurityTokenArgumentNullException("IDX10000:"),
Result = new ValidationError(
new MessageDetail(
TokenLogMessages.IDX10000,
"validationParameters"),
ValidationFailureType.NullArgument,
- typeof(ArgumentNullException),
+ typeof(SecurityTokenArgumentNullException),
null)
},
new JsonWebTokenHandlerValidateSignatureTheoryData {
@@ -110,13 +110,13 @@ public static TheoryData JsonWeb
{
SignatureValidator = (token, parameters, configuration, callContext) => ValidationError.NullParameter("fakeParameter", null)
},
- ExpectedException = ExpectedException.ArgumentNullException("IDX10000:"),
+ ExpectedException = ExpectedException.SecurityTokenArgumentNullException("IDX10000:"),
Result = new ValidationError(
new MessageDetail(
TokenLogMessages.IDX10000,
"fakeParameter"),
ValidationFailureType.NullArgument,
- typeof(ArgumentNullException),
+ typeof(SecurityTokenArgumentNullException),
null)
},
new JsonWebTokenHandlerValidateSignatureTheoryData
diff --git a/test/Microsoft.IdentityModel.TestUtils/ExpectedException.cs b/test/Microsoft.IdentityModel.TestUtils/ExpectedException.cs
index 1d8eb223ed..cc4a006577 100644
--- a/test/Microsoft.IdentityModel.TestUtils/ExpectedException.cs
+++ b/test/Microsoft.IdentityModel.TestUtils/ExpectedException.cs
@@ -213,6 +213,11 @@ private static void HandleError(string error, List errors)
throw new TestException($"List errors == null, error in test: {error}.");
}
+ public static ExpectedException SecurityTokenArgumentNullException(string substringExpected = null, Type inner = null)
+ {
+ return new ExpectedException(typeof(SecurityTokenArgumentNullException), substringExpected, inner);
+ }
+
public static ExpectedException SecurityTokenEncryptionKeyNotFoundException(string substringExpected = null, Type innerTypeExpected = null)
{
return new ExpectedException(typeof(SecurityTokenEncryptionKeyNotFoundException), substringExpected, innerTypeExpected);
diff --git a/test/Microsoft.IdentityModel.Tokens.Tests/Validation/AlgorithmValidationResultTests.cs b/test/Microsoft.IdentityModel.Tokens.Tests/Validation/AlgorithmValidationResultTests.cs
index b3b701eebc..70d28b6251 100644
--- a/test/Microsoft.IdentityModel.Tokens.Tests/Validation/AlgorithmValidationResultTests.cs
+++ b/test/Microsoft.IdentityModel.Tokens.Tests/Validation/AlgorithmValidationResultTests.cs
@@ -58,7 +58,7 @@ public static TheoryData AlgorithmValidationTestCases
{
TestId = "Invalid_ValidationParametersAreNull",
Algorithm = null,
- ExpectedException = ExpectedException.ArgumentNullException("IDX10000:"),
+ ExpectedException = ExpectedException.SecurityTokenArgumentNullException("IDX10000:"),
SecurityKey = null,
SecurityToken = null,
ValidationParameters = null,
@@ -67,7 +67,7 @@ public static TheoryData AlgorithmValidationTestCases
LogMessages.IDX10000,
LogHelper.MarkAsNonPII("validationParameters")),
ValidationFailureType.NullArgument,
- typeof(ArgumentNullException),
+ typeof(SecurityTokenArgumentNullException),
null) // StackFrame
},
new AlgorithmTheoryData
diff --git a/test/Microsoft.IdentityModel.Tokens.Tests/Validation/AudienceValidationResultTests.cs b/test/Microsoft.IdentityModel.Tokens.Tests/Validation/AudienceValidationResultTests.cs
index fc8f49685b..180ccc4fb0 100644
--- a/test/Microsoft.IdentityModel.Tokens.Tests/Validation/AudienceValidationResultTests.cs
+++ b/test/Microsoft.IdentityModel.Tokens.Tests/Validation/AudienceValidationResultTests.cs
@@ -78,7 +78,7 @@ public static TheoryData ValidateAudienceTestCases
new AudienceValidationTheoryData
{
Audiences = new List { "audience1" },
- ExpectedException = ExpectedException.ArgumentNullException("IDX10000:"),
+ ExpectedException = ExpectedException.SecurityTokenArgumentNullException("IDX10000:"),
TestId = "Invalid_ValidationParametersIsNull",
ValidationParameters = null,
Result = new ValidationError(
@@ -86,7 +86,7 @@ public static TheoryData ValidateAudienceTestCases
LogMessages.IDX10000,
LogHelper.MarkAsNonPII("validationParameters")),
ValidationFailureType.NullArgument,
- typeof(ArgumentNullException),
+ typeof(SecurityTokenArgumentNullException),
null)
},
new AudienceValidationTheoryData
diff --git a/test/Microsoft.IdentityModel.Tokens.Tests/Validation/IssuerValidationResultTests.cs b/test/Microsoft.IdentityModel.Tokens.Tests/Validation/IssuerValidationResultTests.cs
index d4d0632cd8..7cce6baad2 100644
--- a/test/Microsoft.IdentityModel.Tokens.Tests/Validation/IssuerValidationResultTests.cs
+++ b/test/Microsoft.IdentityModel.Tokens.Tests/Validation/IssuerValidationResultTests.cs
@@ -84,14 +84,14 @@ public static TheoryData IssuerValdationResul
theoryData.Add(new IssuerValidationResultsTheoryData("NULL_ValidationParameters")
{
- ExpectedException = ExpectedException.ArgumentNullException("IDX10000:"),
+ ExpectedException = ExpectedException.SecurityTokenArgumentNullException("IDX10000:"),
Issuer = issClaim,
Result = new ValidationError(
new MessageDetail(
LogMessages.IDX10000,
LogHelper.MarkAsNonPII("validationParameters")),
ValidationFailureType.NullArgument,
- typeof(ArgumentNullException),
+ typeof(SecurityTokenArgumentNullException),
null),
SecurityToken = JsonUtilities.CreateUnsignedJsonWebToken(JwtRegisteredClaimNames.Iss, issClaim),
ValidationParameters = null
@@ -99,14 +99,14 @@ public static TheoryData IssuerValdationResul
theoryData.Add(new IssuerValidationResultsTheoryData("NULL_SecurityToken")
{
- ExpectedException = ExpectedException.ArgumentNullException("IDX10000:"),
+ ExpectedException = ExpectedException.SecurityTokenArgumentNullException("IDX10000:"),
Issuer = issClaim,
Result = new ValidationError(
new MessageDetail(
LogMessages.IDX10000,
LogHelper.MarkAsNonPII("securityToken")),
ValidationFailureType.NullArgument,
- typeof(ArgumentNullException),
+ typeof(SecurityTokenArgumentNullException),
null),
SecurityToken = null,
ValidationParameters = new ValidationParameters()
diff --git a/test/Microsoft.IdentityModel.Tokens.Tests/Validation/LifetimeValidationResultTests.cs b/test/Microsoft.IdentityModel.Tokens.Tests/Validation/LifetimeValidationResultTests.cs
index a4c8307261..814935c9b8 100644
--- a/test/Microsoft.IdentityModel.Tokens.Tests/Validation/LifetimeValidationResultTests.cs
+++ b/test/Microsoft.IdentityModel.Tokens.Tests/Validation/LifetimeValidationResultTests.cs
@@ -93,14 +93,14 @@ public static TheoryData ValidateLifetimeTestCases
},
new ValidateLifetimeTheoryData("Invalid_ValidationParametersIsNull")
{
- ExpectedException = ExpectedException.ArgumentNullException("IDX10000:"),
+ ExpectedException = ExpectedException.SecurityTokenArgumentNullException("IDX10000:"),
Expires = oneHourFromNow,
NotBefore = oneHourAgo,
ValidationParameters = null,
Result = new ValidationError(
new MessageDetail(LogMessages.IDX10000, "validationParameters"),
ValidationFailureType.NullArgument,
- typeof(ArgumentNullException),
+ typeof(SecurityTokenArgumentNullException),
null),
},
new ValidateLifetimeTheoryData("Invalid_ExpiresIsNull")
diff --git a/test/Microsoft.IdentityModel.Tokens.Tests/Validation/ReplayValidationResultTests.cs b/test/Microsoft.IdentityModel.Tokens.Tests/Validation/ReplayValidationResultTests.cs
index df474312a2..449c7fcab9 100644
--- a/test/Microsoft.IdentityModel.Tokens.Tests/Validation/ReplayValidationResultTests.cs
+++ b/test/Microsoft.IdentityModel.Tokens.Tests/Validation/ReplayValidationResultTests.cs
@@ -81,7 +81,7 @@ public static TheoryData TokenReplayValidationTestCases
new TokenReplayTheoryData
{
TestId = "Invalid_SecurityToken_Null",
- ExpectedException = ExpectedException.ArgumentNullException("IDX10000:"),
+ ExpectedException = ExpectedException.SecurityTokenArgumentNullException("IDX10000:"),
ExpirationTime = now,
SecurityToken = null,
ValidationParameters = new ValidationParameters(),
@@ -90,13 +90,13 @@ public static TheoryData TokenReplayValidationTestCases
LogMessages.IDX10000,
LogHelper.MarkAsNonPII("securityToken")),
ValidationFailureType.NullArgument,
- typeof(ArgumentNullException),
+ typeof(SecurityTokenArgumentNullException),
null),
},
new TokenReplayTheoryData
{
TestId = "Invalid_SecurityToken_Empty",
- ExpectedException = ExpectedException.ArgumentNullException("IDX10000:"),
+ ExpectedException = ExpectedException.SecurityTokenArgumentNullException("IDX10000:"),
ExpirationTime = now,
SecurityToken = string.Empty,
ValidationParameters = new ValidationParameters(),
@@ -105,13 +105,13 @@ public static TheoryData TokenReplayValidationTestCases
LogMessages.IDX10000,
LogHelper.MarkAsNonPII("securityToken")),
ValidationFailureType.NullArgument,
- typeof(ArgumentNullException),
+ typeof(SecurityTokenArgumentNullException),
null),
},
new TokenReplayTheoryData
{
TestId = "Invalid_ValidationParameters_Null",
- ExpectedException = ExpectedException.ArgumentNullException("IDX10000:"),
+ ExpectedException = ExpectedException.SecurityTokenArgumentNullException("IDX10000:"),
ExpirationTime = now,
SecurityToken = "token",
ValidationParameters = null,
@@ -120,7 +120,7 @@ public static TheoryData TokenReplayValidationTestCases
LogMessages.IDX10000,
LogHelper.MarkAsNonPII("validationParameters")),
ValidationFailureType.NullArgument,
- typeof(ArgumentNullException),
+ typeof(SecurityTokenArgumentNullException),
null),
},
new TokenReplayTheoryData
diff --git a/test/Microsoft.IdentityModel.Tokens.Tests/Validation/SigningKeyValidationResultTests.cs b/test/Microsoft.IdentityModel.Tokens.Tests/Validation/SigningKeyValidationResultTests.cs
index 1bef274ba1..a12a973189 100644
--- a/test/Microsoft.IdentityModel.Tokens.Tests/Validation/SigningKeyValidationResultTests.cs
+++ b/test/Microsoft.IdentityModel.Tokens.Tests/Validation/SigningKeyValidationResultTests.cs
@@ -68,20 +68,20 @@ public static TheoryData SigningKeyValidationTes
new SigningKeyValidationTheoryData
{
TestId = "Invalid_SecurityKeyIsNull",
- ExpectedException = ExpectedException.ArgumentNullException(substringExpected: "IDX10253:"),
+ ExpectedException = ExpectedException.SecurityTokenArgumentNullException(substringExpected: "IDX10253:"),
SecurityKey = null,
SecurityToken = new JwtSecurityToken(),
ValidationParameters = new ValidationParameters(),
Result = new ValidationError(
new MessageDetail(LogMessages.IDX10253),
ValidationFailureType.SigningKeyValidationFailed,
- typeof(ArgumentNullException),
+ typeof(SecurityTokenArgumentNullException),
null),
},
new SigningKeyValidationTheoryData
{
TestId = "Invalid_SecurityTokenIsNull",
- ExpectedException = ExpectedException.ArgumentNullException(substringExpected: "IDX10000:"),
+ ExpectedException = ExpectedException.SecurityTokenArgumentNullException(substringExpected: "IDX10000:"),
SecurityKey = KeyingMaterial.SymmetricSecurityKey2_256,
SecurityToken = null,
ValidationParameters = new ValidationParameters (),
@@ -90,13 +90,13 @@ public static TheoryData SigningKeyValidationTes
LogMessages.IDX10000,
LogHelper.MarkAsNonPII("securityToken")),
ValidationFailureType.NullArgument,
- typeof(ArgumentNullException),
+ typeof(SecurityTokenArgumentNullException),
null),
},
new SigningKeyValidationTheoryData
{
TestId = "Invalid_ValidationParametersIsNull",
- ExpectedException = ExpectedException.ArgumentNullException(substringExpected: "IDX10000:"),
+ ExpectedException = ExpectedException.SecurityTokenArgumentNullException(substringExpected: "IDX10000:"),
SecurityKey = KeyingMaterial.SymmetricSecurityKey2_256,
SecurityToken = new JwtSecurityToken(),
ValidationParameters = null,
@@ -105,7 +105,7 @@ public static TheoryData SigningKeyValidationTes
LogMessages.IDX10000,
LogHelper.MarkAsNonPII("validationParameters")),
ValidationFailureType.NullArgument,
- typeof(ArgumentNullException),
+ typeof(SecurityTokenArgumentNullException),
null),
},
new SigningKeyValidationTheoryData
@@ -143,14 +143,14 @@ public static TheoryData SigningKeyValidationTes
new SigningKeyValidationTheoryData
{
TestId = "Invalid_SecurityKeyIsNull",
- ExpectedException = ExpectedException.ArgumentNullException("IDX10253:"),
+ ExpectedException = ExpectedException.SecurityTokenArgumentNullException("IDX10253:"),
SecurityKey = null,
SecurityToken = new JwtSecurityToken(),
ValidationParameters = new ValidationParameters (),
Result = new ValidationError(
new MessageDetail(LogMessages.IDX10253),
ValidationFailureType.SigningKeyValidationFailed,
- typeof(ArgumentNullException),
+ typeof(SecurityTokenArgumentNullException),
null),
},
diff --git a/test/Microsoft.IdentityModel.Tokens.Tests/Validation/TokenTypeValidationResultTests.cs b/test/Microsoft.IdentityModel.Tokens.Tests/Validation/TokenTypeValidationResultTests.cs
index 4b90950d97..d0d4aa47bb 100644
--- a/test/Microsoft.IdentityModel.Tokens.Tests/Validation/TokenTypeValidationResultTests.cs
+++ b/test/Microsoft.IdentityModel.Tokens.Tests/Validation/TokenTypeValidationResultTests.cs
@@ -76,7 +76,7 @@ public static TheoryData TokenTypeValidationTestCases
new TokenTypeTheoryData
{
TestId = "Invalid_SecurityTokenIsNull",
- ExpectedException = ExpectedException.ArgumentNullException("IDX10000:"),
+ ExpectedException = ExpectedException.SecurityTokenArgumentNullException("IDX10000:"),
Type = "JWT",
SecurityToken = null,
ValidationParameters = null,
@@ -85,13 +85,13 @@ public static TheoryData TokenTypeValidationTestCases
LogMessages.IDX10000,
LogHelper.MarkAsNonPII("securityToken")),
ValidationFailureType.NullArgument,
- typeof(ArgumentNullException),
+ typeof(SecurityTokenArgumentNullException),
null)
},
new TokenTypeTheoryData
{
TestId = "Invalid_ValidationParametersAreNull",
- ExpectedException = ExpectedException.ArgumentNullException("IDX10000:"),
+ ExpectedException = ExpectedException.SecurityTokenArgumentNullException("IDX10000:"),
Type = "JWT",
SecurityToken = JsonUtilities.CreateUnsignedJsonWebToken(JwtRegisteredClaimNames.Typ, "JWT"),
ValidationParameters = null,
@@ -100,7 +100,7 @@ public static TheoryData TokenTypeValidationTestCases
LogMessages.IDX10000,
LogHelper.MarkAsNonPII("validationParameters")),
ValidationFailureType.NullArgument,
- typeof(ArgumentNullException),
+ typeof(SecurityTokenArgumentNullException),
null)
},
new TokenTypeTheoryData