-
Notifications
You must be signed in to change notification settings - Fork 414
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added cusotm audience validation delegates for testing
- Loading branch information
Showing
1 changed file
with
137 additions
and
0 deletions.
There are no files selected for viewing
137 changes: 137 additions & 0 deletions
137
...IdentityModel.TestUtils/TokenValidationExtensibility/CustomAudienceValidationDelegates.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,137 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.IdentityModel.Tokens; | ||
|
||
#nullable enable | ||
namespace Microsoft.IdentityModel.TestUtils | ||
{ | ||
internal class CustomAudienceValidationDelegates | ||
{ | ||
internal static ValidationResult<string> CustomAudienceValidatorDelegate( | ||
IList<string> tokenAudiences, | ||
SecurityToken? securityToken, | ||
ValidationParameters validationParameters, | ||
CallContext callContext) | ||
{ | ||
// Returns a CustomAudienceValidationError : AudienceValidationError | ||
return new CustomAudienceValidationError( | ||
new MessageDetail(nameof(CustomAudienceValidatorDelegate), null), | ||
typeof(SecurityTokenInvalidAudienceException), | ||
ValidationError.GetCurrentStackFrame(), | ||
tokenAudiences, | ||
null); | ||
} | ||
|
||
internal static ValidationResult<string> CustomAudienceValidatorCustomExceptionDelegate( | ||
IList<string> tokenAudiences, | ||
SecurityToken? securityToken, | ||
ValidationParameters validationParameters, | ||
CallContext callContext) | ||
{ | ||
return new CustomAudienceValidationError( | ||
new MessageDetail(nameof(CustomAudienceValidatorCustomExceptionDelegate), null), | ||
typeof(CustomSecurityTokenInvalidAudienceException), | ||
ValidationError.GetCurrentStackFrame(), | ||
tokenAudiences, | ||
null); | ||
} | ||
|
||
internal static ValidationResult<string> CustomAudienceValidatorCustomExceptionCustomFailureTypeDelegate( | ||
IList<string> tokenAudiences, | ||
SecurityToken? securityToken, | ||
ValidationParameters validationParameters, | ||
CallContext callContext) | ||
{ | ||
return new CustomAudienceValidationError( | ||
new MessageDetail(nameof(CustomAudienceValidatorCustomExceptionCustomFailureTypeDelegate), null), | ||
typeof(CustomSecurityTokenInvalidAudienceException), | ||
ValidationError.GetCurrentStackFrame(), | ||
tokenAudiences, | ||
null, | ||
CustomAudienceValidationError.CustomAudienceValidationFailureType); | ||
} | ||
|
||
internal static ValidationResult<string> CustomAudienceValidatorUnknownExceptionDelegate( | ||
IList<string> tokenAudiences, | ||
SecurityToken? securityToken, | ||
ValidationParameters validationParameters, | ||
CallContext callContext) | ||
{ | ||
return new CustomAudienceValidationError( | ||
new MessageDetail(nameof(CustomAudienceValidatorUnknownExceptionDelegate), null), | ||
typeof(NotSupportedException), | ||
ValidationError.GetCurrentStackFrame(), | ||
tokenAudiences, | ||
null); | ||
} | ||
|
||
internal static ValidationResult<string> CustomAudienceValidatorWithoutGetExceptionOverrideDelegate( | ||
IList<string> tokenAudiences, | ||
SecurityToken? securityToken, | ||
ValidationParameters validationParameters, | ||
CallContext callContext) | ||
{ | ||
return new CustomAudienceWithoutGetExceptionValidationOverrideError( | ||
new MessageDetail(nameof(CustomAudienceValidatorWithoutGetExceptionOverrideDelegate), null), | ||
typeof(CustomSecurityTokenInvalidAudienceException), | ||
ValidationError.GetCurrentStackFrame(), | ||
tokenAudiences, | ||
null); | ||
} | ||
|
||
internal static ValidationResult<string> AudienceValidatorDelegate( | ||
IList<string> tokenAudiences, | ||
SecurityToken? securityToken, | ||
ValidationParameters validationParameters, | ||
CallContext callContext) | ||
{ | ||
return new AudienceValidationError( | ||
new MessageDetail(nameof(AudienceValidatorDelegate), null), | ||
typeof(SecurityTokenInvalidAudienceException), | ||
ValidationError.GetCurrentStackFrame(), | ||
tokenAudiences, | ||
null); | ||
} | ||
|
||
internal static ValidationResult<string> AudienceValidatorThrows( | ||
IList<string> tokenAudiences, | ||
SecurityToken? securityToken, | ||
ValidationParameters validationParameters, | ||
CallContext callContext) | ||
{ | ||
throw new CustomSecurityTokenInvalidAudienceException(nameof(AudienceValidatorThrows), null); | ||
} | ||
|
||
internal static ValidationResult<string> AudienceValidatorCustomAudienceExceptionTypeDelegate( | ||
IList<string> tokenAudiences, | ||
SecurityToken? securityToken, | ||
ValidationParameters validationParameters, | ||
CallContext callContext) | ||
{ | ||
return new AudienceValidationError( | ||
new MessageDetail(nameof(AudienceValidatorCustomAudienceExceptionTypeDelegate), null), | ||
typeof(CustomSecurityTokenInvalidAudienceException), | ||
ValidationError.GetCurrentStackFrame(), | ||
tokenAudiences, | ||
null); | ||
} | ||
|
||
internal static ValidationResult<string> AudienceValidatorCustomExceptionTypeDelegate( | ||
IList<string> tokenAudiences, | ||
SecurityToken? securityToken, | ||
ValidationParameters validationParameters, | ||
CallContext callContext) | ||
{ | ||
return new AudienceValidationError( | ||
new MessageDetail(nameof(AudienceValidatorCustomExceptionTypeDelegate), null), | ||
typeof(CustomSecurityTokenException), | ||
ValidationError.GetCurrentStackFrame(), | ||
tokenAudiences, | ||
null); | ||
} | ||
} | ||
} | ||
#nullable restore |