-
Notifications
You must be signed in to change notification settings - Fork 438
Extensibility tests: Audience - JWT, SAML and SAML2 #3027
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
416ffa0
Handle potential exceptions thrown by the audience validation delegat…
iNinja e7a37a9
Added cusotm audience validation delegates for testing
iNinja b1539a6
Added audience extensibility tests for JWT, SAML, and SAML2
iNinja 45623f0
Updated validation failure type position in tests
iNinja 69cb814
Merge branch 'dev' into iinglese/extensibility-tests-audience-jwt-saml
iNinja 13e705f
Merge branch 'dev' into iinglese/extensibility-tests-audience-jwt-saml
iNinja bec9783
Merge branch 'dev' into iinglese/extensibility-tests-audience-jwt-saml
iNinja 5435e78
Merge branch 'dev' into iinglese/extensibility-tests-audience-jwt-saml
iNinja 3cd2fd8
Merge branch 'dev' into iinglese/extensibility-tests-audience-jwt-saml
iNinja 6e9d6d3
Handle success case as unexpected in audience extensibility tests
iNinja 907d9e6
Merge branch 'dev' into iinglese/extensibility-tests-audience-jwt-saml
iNinja 429f082
Merge branch 'dev' into iinglese/extensibility-tests-audience-jwt-saml
iNinja 0a47c4f
Removed duplicate test code adopting the refactored approach after me…
iNinja 8b76eb8
Merge branch 'dev' into iinglese/extensibility-tests-audience-jwt-saml
iNinja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
37 changes: 37 additions & 0 deletions
37
...Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenHandler.Extensibility.Audience.cs
This file contains hidden or 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,37 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Threading.Tasks; | ||
| using Microsoft.IdentityModel.TestUtils.TokenValidationExtensibility.Tests; | ||
| using Xunit; | ||
|
|
||
| #nullable enable | ||
| namespace Microsoft.IdentityModel.JsonWebTokens.Extensibility.Tests | ||
| { | ||
| public partial class JsonWebTokenHandlerValidateTokenAsyncTests | ||
| { | ||
| [Theory, MemberData( | ||
| nameof(GenerateAudienceExtensibilityTestCases), | ||
| parameters: ["JWT", 2], | ||
| DisableDiscoveryEnumeration = true)] | ||
| public async Task ValidateTokenAsync_AudienceValidator_Extensibility( | ||
| AudienceExtensibilityTheoryData theoryData) | ||
| { | ||
| await ExtensibilityTesting.ValidateTokenAsync_Extensibility( | ||
| theoryData, | ||
| this, | ||
| nameof(ValidateTokenAsync_AudienceValidator_Extensibility)); | ||
| } | ||
|
|
||
| public static TheoryData<AudienceExtensibilityTheoryData> GenerateAudienceExtensibilityTestCases( | ||
| string tokenHandlerType, | ||
| int extraStackFrames) | ||
| { | ||
| return ExtensibilityTesting.GenerateAudienceExtensibilityTestCases( | ||
| tokenHandlerType, | ||
| extraStackFrames, | ||
| "JsonWebTokenHandler.ValidateToken.Internal.cs"); | ||
| } | ||
| } | ||
| } | ||
| #nullable restore |
143 changes: 143 additions & 0 deletions
143
...IdentityModel.TestUtils/TokenValidationExtensibility/CustomAudienceValidationDelegates.cs
This file contains hidden or 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,143 @@ | ||
| // 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), | ||
| ValidationFailureType.AudienceValidationFailed, | ||
| 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), | ||
| ValidationFailureType.AudienceValidationFailed, | ||
| 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), | ||
| CustomAudienceValidationError.CustomAudienceValidationFailureType, | ||
| typeof(CustomSecurityTokenInvalidAudienceException), | ||
| ValidationError.GetCurrentStackFrame(), | ||
| tokenAudiences, | ||
| null); | ||
| } | ||
|
|
||
| internal static ValidationResult<string> CustomAudienceValidatorUnknownExceptionDelegate( | ||
| IList<string> tokenAudiences, | ||
| SecurityToken? securityToken, | ||
| ValidationParameters validationParameters, | ||
| CallContext callContext) | ||
| { | ||
| return new CustomAudienceValidationError( | ||
| new MessageDetail(nameof(CustomAudienceValidatorUnknownExceptionDelegate), null), | ||
| ValidationFailureType.AudienceValidationFailed, | ||
| 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), | ||
| ValidationFailureType.AudienceValidationFailed, | ||
| 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), | ||
| ValidationFailureType.AudienceValidationFailed, | ||
| 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), | ||
| ValidationFailureType.AudienceValidationFailed, | ||
| typeof(CustomSecurityTokenException), | ||
| ValidationError.GetCurrentStackFrame(), | ||
| tokenAudiences, | ||
| null); | ||
| } | ||
| } | ||
| } | ||
| #nullable restore |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.