-
Notifications
You must be signed in to change notification settings - Fork 420
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added custom lifetime validation delegates for testing
- Loading branch information
Showing
1 changed file
with
152 additions
and
0 deletions.
There are no files selected for viewing
152 changes: 152 additions & 0 deletions
152
...IdentityModel.TestUtils/TokenValidationExtensibility/CustomLifetimeValidationDelegates.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,152 @@ | ||
// 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 CustomLifetimeValidationDelegates | ||
{ | ||
internal static ValidationResult<ValidatedLifetime> CustomLifetimeValidatorDelegate( | ||
DateTime? notBefore, | ||
DateTime? expires, | ||
SecurityToken? securityToken, | ||
ValidationParameters validationParameters, | ||
CallContext callContext) | ||
{ | ||
// Returns a CustomLifetimeValidationError : LifetimeValidationError | ||
return new CustomLifetimeValidationError( | ||
new MessageDetail(nameof(CustomLifetimeValidatorDelegate), null), | ||
typeof(SecurityTokenInvalidLifetimeException), | ||
ValidationError.GetCurrentStackFrame(), | ||
notBefore, | ||
expires, | ||
null); | ||
} | ||
|
||
internal static ValidationResult<ValidatedLifetime> CustomLifetimeValidatorCustomExceptionDelegate( | ||
DateTime? notBefore, | ||
DateTime? expires, | ||
SecurityToken? securityToken, | ||
ValidationParameters validationParameters, | ||
CallContext callContext) | ||
{ | ||
return new CustomLifetimeValidationError( | ||
new MessageDetail(nameof(CustomLifetimeValidatorCustomExceptionDelegate), null), | ||
typeof(CustomSecurityTokenInvalidLifetimeException), | ||
ValidationError.GetCurrentStackFrame(), | ||
notBefore, | ||
expires, | ||
null); | ||
} | ||
|
||
internal static ValidationResult<ValidatedLifetime> CustomLifetimeValidatorCustomExceptionCustomFailureTypeDelegate( | ||
DateTime? notBefore, | ||
DateTime? expires, | ||
SecurityToken? securityToken, | ||
ValidationParameters validationParameters, | ||
CallContext callContext) | ||
{ | ||
return new CustomLifetimeValidationError( | ||
new MessageDetail(nameof(CustomLifetimeValidatorCustomExceptionCustomFailureTypeDelegate), null), | ||
typeof(CustomSecurityTokenInvalidLifetimeException), | ||
ValidationError.GetCurrentStackFrame(), | ||
notBefore, | ||
expires, | ||
CustomLifetimeValidationError.CustomLifetimeValidationFailureType); | ||
} | ||
|
||
internal static ValidationResult<ValidatedLifetime> CustomLifetimeValidatorUnknownExceptionDelegate( | ||
DateTime? notBefore, | ||
DateTime? expires, | ||
SecurityToken? securityToken, | ||
ValidationParameters validationParameters, | ||
CallContext callContext) | ||
{ | ||
return new CustomLifetimeValidationError( | ||
new MessageDetail(nameof(CustomLifetimeValidatorUnknownExceptionDelegate), null), | ||
typeof(NotSupportedException), | ||
ValidationError.GetCurrentStackFrame(), | ||
notBefore, | ||
expires, | ||
null); | ||
} | ||
|
||
internal static ValidationResult<ValidatedLifetime> CustomLifetimeValidatorWithoutGetExceptionOverrideDelegate( | ||
DateTime? notBefore, | ||
DateTime? expires, | ||
SecurityToken? securityToken, | ||
ValidationParameters validationParameters, | ||
CallContext callContext) | ||
{ | ||
return new CustomLifetimeWithoutGetExceptionValidationOverrideError( | ||
new MessageDetail(nameof(CustomLifetimeValidatorWithoutGetExceptionOverrideDelegate), null), | ||
typeof(CustomSecurityTokenInvalidLifetimeException), | ||
ValidationError.GetCurrentStackFrame(), | ||
notBefore, | ||
expires, | ||
null); | ||
} | ||
|
||
internal static ValidationResult<ValidatedLifetime> LifetimeValidatorDelegate( | ||
DateTime? notBefore, | ||
DateTime? expires, | ||
SecurityToken? securityToken, | ||
ValidationParameters validationParameters, | ||
CallContext callContext) | ||
{ | ||
return new LifetimeValidationError( | ||
new MessageDetail(nameof(LifetimeValidatorDelegate), null), | ||
typeof(SecurityTokenInvalidLifetimeException), | ||
ValidationError.GetCurrentStackFrame(), | ||
notBefore, | ||
expires, | ||
null); | ||
} | ||
|
||
internal static ValidationResult<ValidatedLifetime> LifetimeValidatorThrows( | ||
DateTime? notBefore, | ||
DateTime? expires, | ||
SecurityToken? securityToken, | ||
ValidationParameters validationParameters, | ||
CallContext callContext) | ||
{ | ||
throw new CustomSecurityTokenInvalidLifetimeException(nameof(LifetimeValidatorThrows), null); | ||
} | ||
|
||
internal static ValidationResult<ValidatedLifetime> LifetimeValidatorCustomLifetimeExceptionTypeDelegate( | ||
DateTime? notBefore, | ||
DateTime? expires, | ||
SecurityToken? securityToken, | ||
ValidationParameters validationParameters, | ||
CallContext callContext) | ||
{ | ||
return new LifetimeValidationError( | ||
new MessageDetail(nameof(LifetimeValidatorCustomLifetimeExceptionTypeDelegate), null), | ||
typeof(CustomSecurityTokenInvalidLifetimeException), | ||
ValidationError.GetCurrentStackFrame(), | ||
notBefore, | ||
expires, | ||
null); | ||
} | ||
|
||
internal static ValidationResult<ValidatedLifetime> LifetimeValidatorCustomExceptionTypeDelegate( | ||
DateTime? notBefore, | ||
DateTime? expires, | ||
SecurityToken? securityToken, | ||
ValidationParameters validationParameters, | ||
CallContext callContext) | ||
{ | ||
return new LifetimeValidationError( | ||
new MessageDetail(nameof(LifetimeValidatorCustomExceptionTypeDelegate), null), | ||
typeof(CustomSecurityTokenException), | ||
ValidationError.GetCurrentStackFrame(), | ||
notBefore, | ||
expires, | ||
null); | ||
} | ||
} | ||
} | ||
#nullable restore |