-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added custom validation delegates and validation errors for issuer si…
…gning key extensibility testing
- Loading branch information
Showing
2 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
144 changes: 144 additions & 0 deletions
144
...Model.TestUtils/TokenValidationExtensibility/CustomIssuerSigningKeyValidationDelegates.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using Microsoft.IdentityModel.Tokens; | ||
|
||
#nullable enable | ||
namespace Microsoft.IdentityModel.TestUtils | ||
{ | ||
internal class CustomIssuerSigningKeyValidationDelegates | ||
{ | ||
internal static ValidationResult<ValidatedSigningKeyLifetime> CustomIssuerSigningKeyValidatorDelegate( | ||
SecurityKey signingKey, | ||
SecurityToken securityToken, | ||
ValidationParameters validationParameters, | ||
BaseConfiguration? configuration, | ||
CallContext callContext) | ||
{ | ||
// Returns a CustomIssuerSigningKeyValidationError : IssuerSigningKeyValidationError | ||
return new CustomIssuerSigningKeyValidationError( | ||
new MessageDetail(nameof(CustomIssuerSigningKeyValidatorDelegate), null), | ||
typeof(SecurityTokenInvalidSigningKeyException), | ||
ValidationError.GetCurrentStackFrame(), | ||
signingKey, | ||
null); | ||
} | ||
|
||
internal static ValidationResult<ValidatedSigningKeyLifetime> CustomIssuerSigningKeyValidatorCustomExceptionDelegate( | ||
SecurityKey signingKey, | ||
SecurityToken securityToken, | ||
ValidationParameters validationParameters, | ||
BaseConfiguration? configuration, | ||
CallContext callContext) | ||
{ | ||
return new CustomIssuerSigningKeyValidationError( | ||
new MessageDetail(nameof(CustomIssuerSigningKeyValidatorCustomExceptionDelegate), null), | ||
typeof(CustomSecurityTokenInvalidSigningKeyException), | ||
ValidationError.GetCurrentStackFrame(), | ||
signingKey, | ||
null); | ||
} | ||
|
||
internal static ValidationResult<ValidatedSigningKeyLifetime> CustomIssuerSigningKeyValidatorCustomExceptionCustomFailureTypeDelegate( | ||
SecurityKey signingKey, | ||
SecurityToken securityToken, | ||
ValidationParameters validationParameters, | ||
BaseConfiguration? configuration, | ||
CallContext callContext) | ||
{ | ||
return new CustomIssuerSigningKeyValidationError( | ||
new MessageDetail(nameof(CustomIssuerSigningKeyValidatorCustomExceptionCustomFailureTypeDelegate), null), | ||
typeof(CustomSecurityTokenInvalidSigningKeyException), | ||
ValidationError.GetCurrentStackFrame(), | ||
signingKey, | ||
CustomIssuerSigningKeyValidationError.CustomIssuerSigningKeyValidationFailureType); | ||
} | ||
|
||
internal static ValidationResult<ValidatedSigningKeyLifetime> CustomIssuerSigningKeyValidatorUnknownExceptionDelegate( | ||
SecurityKey signingKey, | ||
SecurityToken securityToken, | ||
ValidationParameters validationParameters, | ||
BaseConfiguration? configuration, | ||
CallContext callContext) | ||
{ | ||
return new CustomIssuerSigningKeyValidationError( | ||
new MessageDetail(nameof(CustomIssuerSigningKeyValidatorUnknownExceptionDelegate), null), | ||
typeof(NotSupportedException), | ||
ValidationError.GetCurrentStackFrame(), | ||
signingKey, | ||
null); | ||
} | ||
|
||
internal static ValidationResult<ValidatedSigningKeyLifetime> CustomIssuerSigningKeyValidatorWithoutGetExceptionOverrideDelegate( | ||
SecurityKey signingKey, | ||
SecurityToken securityToken, | ||
ValidationParameters validationParameters, | ||
BaseConfiguration? configuration, | ||
CallContext callContext) | ||
{ | ||
return new CustomIssuerSigningKeyWithoutGetExceptionValidationOverrideError( | ||
new MessageDetail(nameof(CustomIssuerSigningKeyValidatorWithoutGetExceptionOverrideDelegate), null), | ||
typeof(CustomSecurityTokenInvalidSigningKeyException), | ||
ValidationError.GetCurrentStackFrame(), | ||
signingKey, | ||
null); | ||
} | ||
|
||
internal static ValidationResult<ValidatedSigningKeyLifetime> IssuerSigningKeyValidatorDelegate( | ||
SecurityKey signingKey, | ||
SecurityToken securityToken, | ||
ValidationParameters validationParameters, | ||
BaseConfiguration? configuration, | ||
CallContext callContext) | ||
{ | ||
return new IssuerSigningKeyValidationError( | ||
new MessageDetail(nameof(IssuerSigningKeyValidatorDelegate), null), | ||
typeof(SecurityTokenInvalidSigningKeyException), | ||
ValidationError.GetCurrentStackFrame(), | ||
signingKey, | ||
null); | ||
} | ||
|
||
internal static ValidationResult<ValidatedSigningKeyLifetime> IssuerSigningKeyValidatorThrows( | ||
SecurityKey signingKey, | ||
SecurityToken securityToken, | ||
ValidationParameters validationParameters, | ||
BaseConfiguration? configuration, | ||
CallContext callContext) | ||
{ | ||
throw new CustomSecurityTokenInvalidSigningKeyException(nameof(IssuerSigningKeyValidatorThrows), null); | ||
} | ||
|
||
internal static ValidationResult<ValidatedSigningKeyLifetime> IssuerSigningKeyValidatorCustomIssuerSigningKeyExceptionTypeDelegate( | ||
SecurityKey signingKey, | ||
SecurityToken securityToken, | ||
ValidationParameters validationParameters, | ||
BaseConfiguration? configuration, | ||
CallContext callContext) | ||
{ | ||
return new IssuerSigningKeyValidationError( | ||
new MessageDetail(nameof(IssuerSigningKeyValidatorCustomIssuerSigningKeyExceptionTypeDelegate), null), | ||
typeof(CustomSecurityTokenInvalidSigningKeyException), | ||
ValidationError.GetCurrentStackFrame(), | ||
signingKey, | ||
null); | ||
} | ||
|
||
internal static ValidationResult<ValidatedSigningKeyLifetime> IssuerSigningKeyValidatorCustomExceptionTypeDelegate( | ||
SecurityKey signingKey, | ||
SecurityToken securityToken, | ||
ValidationParameters validationParameters, | ||
BaseConfiguration? configuration, | ||
CallContext callContext) | ||
{ | ||
return new IssuerSigningKeyValidationError( | ||
new MessageDetail(nameof(IssuerSigningKeyValidatorCustomExceptionTypeDelegate), null), | ||
typeof(CustomSecurityTokenException), | ||
ValidationError.GetCurrentStackFrame(), | ||
signingKey, | ||
null); | ||
} | ||
} | ||
} | ||
#nullable restore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters