-
Notifications
You must be signed in to change notification settings - Fork 432
Remove duplicate code in extensibility tests #3044
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
brentschmaltz
merged 9 commits into
dev
from
iinglese/remove-duplicate-code-in-extensibility-testing
Dec 3, 2024
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7fc6e4e
Updated Algorithm extensibility tests to remove duplicate code
iNinja 79ba994
Updated algorithm extensibility test cases. Added missing nullability…
iNinja 615a749
Added missing nullability annotations
iNinja 10cbf4d
Updated issuer signing key extensibility tests to remove duplicate code
iNinja a8b4f52
Updated signature extensibility tests to remove duplicate code
iNinja 116a4f9
Updated token replay extensibility tests to remove duplicate code
iNinja bb6b7fa
Updated token type extensibility tests to remove duplicate code
iNinja bf5de64
Merge branch 'dev' into iinglese/remove-duplicate-code-in-extensibili…
iNinja 01b991b
Removed duplicated header in files
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
333 changes: 18 additions & 315 deletions
333
...icrosoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenHandler.Extensibility.Algorithm.cs
Large diffs are not rendered by default.
Oops, something went wrong.
283 changes: 18 additions & 265 deletions
283
...t.IdentityModel.JsonWebTokens.Tests/JsonWebTokenHandler.Extensibility.IssuerSigningKey.cs
Large diffs are not rendered by default.
Oops, something went wrong.
265 changes: 18 additions & 247 deletions
265
...icrosoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenHandler.Extensibility.Signature.cs
Large diffs are not rendered by default.
Oops, something went wrong.
276 changes: 18 additions & 258 deletions
276
...rosoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenHandler.Extensibility.TokenReplay.cs
Large diffs are not rendered by default.
Oops, something went wrong.
262 changes: 18 additions & 244 deletions
262
...icrosoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenHandler.Extensibility.TokenType.cs
Large diffs are not rendered by default.
Oops, something went wrong.
228 changes: 228 additions & 0 deletions
228
...tityModel.TestUtils/TokenValidationExtensibility/Tests/AlgorithmExtensibilityTestCases.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,228 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.Diagnostics; | ||
| using Xunit; | ||
| using Microsoft.IdentityModel.Tokens; | ||
| using Microsoft.IdentityModel.Logging; | ||
|
|
||
| #nullable enable | ||
| namespace Microsoft.IdentityModel.TestUtils.TokenValidationExtensibility.Tests | ||
| { | ||
| public partial class ExtensibilityTesting | ||
| { | ||
| public static TheoryData<AlgorithmExtensibilityTheoryData> GenerateAlgorithmExtensibilityTestCases( | ||
| string tokenHandlerType, | ||
| int extraStackFrames, | ||
| string stackFrameFileName) | ||
| { | ||
| TheoryData<AlgorithmExtensibilityTheoryData> theoryData = new(); | ||
| CallContext callContext = new CallContext(); | ||
|
|
||
| #region return CustomAlgorithmValidationError | ||
| // Test cases where delegate is overridden and return a CustomAlgorithmValidationError | ||
| // CustomAlgorithmValidationError : AlgorithmValidationError, ExceptionType: SecurityTokenInvalidAlgorithmException | ||
| theoryData.Add(new AlgorithmExtensibilityTheoryData( | ||
| "CustomAlgorithmValidatorDelegate", | ||
| tokenHandlerType, | ||
| CustomAlgorithmValidationDelegates.CustomAlgorithmValidatorDelegate, | ||
| extraStackFrames: extraStackFrames) | ||
| { | ||
| ExpectedException = new ExpectedException( | ||
| typeof(SecurityTokenInvalidSignatureException), | ||
| "IDX10518:", | ||
| typeof(SecurityTokenInvalidAlgorithmException)), | ||
| ExpectedInnerException = new ExpectedException( | ||
| typeof(SecurityTokenInvalidAlgorithmException), | ||
| nameof(CustomAlgorithmValidationDelegates.CustomAlgorithmValidatorDelegate)), | ||
| ValidationError = new CustomAlgorithmValidationError( | ||
| new MessageDetail( | ||
| nameof(CustomAlgorithmValidationDelegates.CustomAlgorithmValidatorDelegate), null), | ||
| ValidationFailureType.AlgorithmValidationFailed, | ||
| typeof(SecurityTokenInvalidAlgorithmException), | ||
| new StackFrame("CustomAlgorithmValidationDelegates.cs", 0), | ||
| "algorithm") | ||
| }); | ||
|
|
||
| // CustomAlgorithmValidationError : AlgorithmValidationError, ExceptionType: CustomSecurityTokenInvalidAlgorithmException : SecurityTokenInvalidAlgorithmException | ||
| theoryData.Add(new AlgorithmExtensibilityTheoryData( | ||
| "CustomAlgorithmValidatorCustomExceptionDelegate", | ||
| tokenHandlerType, | ||
| CustomAlgorithmValidationDelegates.CustomAlgorithmValidatorCustomExceptionDelegate, | ||
| extraStackFrames: extraStackFrames) | ||
| { | ||
| ExpectedException = new ExpectedException( | ||
| typeof(SecurityTokenInvalidSignatureException), | ||
| "IDX10518:", | ||
| typeof(CustomSecurityTokenInvalidAlgorithmException)), | ||
| ExpectedInnerException = new ExpectedException( | ||
| typeof(CustomSecurityTokenInvalidAlgorithmException), | ||
| nameof(CustomAlgorithmValidationDelegates.CustomAlgorithmValidatorCustomExceptionDelegate)), | ||
| ValidationError = new CustomAlgorithmValidationError( | ||
| new MessageDetail( | ||
| nameof(CustomAlgorithmValidationDelegates.CustomAlgorithmValidatorCustomExceptionDelegate), null), | ||
| ValidationFailureType.AlgorithmValidationFailed, | ||
| typeof(CustomSecurityTokenInvalidAlgorithmException), | ||
| new StackFrame("CustomAlgorithmValidationDelegates.cs", 0), | ||
| "algorithm"), | ||
| }); | ||
|
|
||
| // CustomAlgorithmValidationError : AlgorithmValidationError, ExceptionType: NotSupportedException : SystemException | ||
| theoryData.Add(new AlgorithmExtensibilityTheoryData( | ||
| "CustomAlgorithmValidatorUnknownExceptionDelegate", | ||
| tokenHandlerType, | ||
| CustomAlgorithmValidationDelegates.CustomAlgorithmValidatorUnknownExceptionDelegate, | ||
| extraStackFrames: extraStackFrames) | ||
| { | ||
| // CustomAlgorithmValidationError does not handle the exception type 'NotSupportedException' | ||
| ExpectedException = new ExpectedException( | ||
| typeof(SecurityTokenInvalidSignatureException), | ||
| "IDX10518:", | ||
| typeof(SecurityTokenException)), | ||
| ExpectedInnerException = ExpectedException.SecurityTokenException( | ||
| LogHelper.FormatInvariant( | ||
| Tokens.LogMessages.IDX10002, // "IDX10002: Unknown exception type returned. Type: '{0}'. Message: '{1}'."; | ||
| typeof(NotSupportedException), | ||
| nameof(CustomAlgorithmValidationDelegates.CustomAlgorithmValidatorUnknownExceptionDelegate))), | ||
| ValidationError = new CustomAlgorithmValidationError( | ||
| new MessageDetail( | ||
| nameof(CustomAlgorithmValidationDelegates.CustomAlgorithmValidatorUnknownExceptionDelegate), null), | ||
| ValidationFailureType.AlgorithmValidationFailed, | ||
| typeof(NotSupportedException), | ||
| new StackFrame("CustomAlgorithmValidationDelegates.cs", 0), | ||
| "algorithm"), | ||
| }); | ||
|
|
||
| // CustomAlgorithmValidationError : AlgorithmValidationError, ExceptionType: NotSupportedException : SystemException, ValidationFailureType: CustomAudienceValidationFailureType | ||
| theoryData.Add(new AlgorithmExtensibilityTheoryData( | ||
| "CustomAlgorithmValidatorCustomExceptionCustomFailureTypeDelegate", | ||
| tokenHandlerType, | ||
| CustomAlgorithmValidationDelegates.CustomAlgorithmValidatorCustomExceptionCustomFailureTypeDelegate, | ||
| extraStackFrames: extraStackFrames) | ||
| { | ||
| ExpectedException = new ExpectedException( | ||
| typeof(SecurityTokenInvalidSignatureException), | ||
| "IDX10518:", | ||
| typeof(CustomSecurityTokenInvalidAlgorithmException)), | ||
| ExpectedInnerException = new ExpectedException( | ||
| typeof(CustomSecurityTokenInvalidAlgorithmException), | ||
| nameof(CustomAlgorithmValidationDelegates.CustomAlgorithmValidatorCustomExceptionCustomFailureTypeDelegate)), | ||
| ValidationError = new CustomAlgorithmValidationError( | ||
| new MessageDetail( | ||
| nameof(CustomAlgorithmValidationDelegates.CustomAlgorithmValidatorCustomExceptionCustomFailureTypeDelegate), null), | ||
| CustomAlgorithmValidationError.CustomAlgorithmValidationFailureType, | ||
| typeof(CustomSecurityTokenInvalidAlgorithmException), | ||
| new StackFrame("CustomAlgorithmValidationDelegates.cs", 0), | ||
| "algorithm"), | ||
| }); | ||
| #endregion | ||
|
|
||
| #region return AlgorithmValidationError | ||
| // Test cases where delegate is overridden and return an AlgorithmValidationError | ||
| // AlgorithmValidationError : ValidationError, ExceptionType: SecurityTokenInvalidAlgorithmException | ||
| theoryData.Add(new AlgorithmExtensibilityTheoryData( | ||
| "AlgorithmValidatorDelegate", | ||
| tokenHandlerType, | ||
| CustomAlgorithmValidationDelegates.AlgorithmValidatorDelegate, | ||
| extraStackFrames: extraStackFrames) | ||
| { | ||
| ExpectedException = new ExpectedException( | ||
| typeof(SecurityTokenInvalidSignatureException), | ||
| "IDX10518:", | ||
| typeof(SecurityTokenInvalidAlgorithmException)), | ||
| ExpectedInnerException = new ExpectedException( | ||
| typeof(SecurityTokenInvalidAlgorithmException), | ||
| nameof(CustomAlgorithmValidationDelegates.AlgorithmValidatorDelegate)), | ||
| ValidationError = new AlgorithmValidationError( | ||
| new MessageDetail( | ||
| nameof(CustomAlgorithmValidationDelegates.AlgorithmValidatorDelegate), null), | ||
| ValidationFailureType.AlgorithmValidationFailed, | ||
| typeof(SecurityTokenInvalidAlgorithmException), | ||
| new StackFrame("CustomAlgorithmValidationDelegates.cs", 0), | ||
| "algorithm") | ||
| }); | ||
|
|
||
| // AlgorithmValidationError : ValidationError, ExceptionType: CustomSecurityTokenInvalidAlgorithmException : SecurityTokenInvalidAlgorithmException | ||
| theoryData.Add(new AlgorithmExtensibilityTheoryData( | ||
| "AlgorithmValidatorCustomAlgorithmExceptionTypeDelegate", | ||
| tokenHandlerType, | ||
| CustomAlgorithmValidationDelegates.AlgorithmValidatorCustomAlgorithmExceptionTypeDelegate, | ||
| extraStackFrames: extraStackFrames) | ||
| { | ||
| // AlgorithmValidationError does not handle the exception type 'CustomSecurityTokenInvalidAlgorithmException' | ||
| ExpectedException = new ExpectedException( | ||
| typeof(SecurityTokenInvalidSignatureException), | ||
| "IDX10518:", | ||
| typeof(SecurityTokenException)), | ||
| ExpectedInnerException = ExpectedException.SecurityTokenException( | ||
| LogHelper.FormatInvariant( | ||
| Tokens.LogMessages.IDX10002, // "IDX10002: Unknown exception type returned. Type: '{0}'. Message: '{1}'."; | ||
| typeof(CustomSecurityTokenInvalidAlgorithmException), | ||
| nameof(CustomAlgorithmValidationDelegates.AlgorithmValidatorCustomAlgorithmExceptionTypeDelegate))), | ||
| ValidationError = new AlgorithmValidationError( | ||
| new MessageDetail( | ||
| nameof(CustomAlgorithmValidationDelegates.AlgorithmValidatorCustomAlgorithmExceptionTypeDelegate), null), | ||
| ValidationFailureType.AlgorithmValidationFailed, | ||
| typeof(CustomSecurityTokenInvalidAlgorithmException), | ||
| new StackFrame("CustomAlgorithmValidationDelegates.cs", 0), | ||
| "algorithm") | ||
| }); | ||
|
|
||
| // AlgorithmValidationError : ValidationError, ExceptionType: CustomSecurityTokenException : SystemException | ||
| theoryData.Add(new AlgorithmExtensibilityTheoryData( | ||
| "AlgorithmValidatorCustomExceptionTypeDelegate", | ||
| tokenHandlerType, | ||
| CustomAlgorithmValidationDelegates.AlgorithmValidatorCustomExceptionTypeDelegate, | ||
| extraStackFrames: extraStackFrames) | ||
| { | ||
| // AlgorithmValidationError does not handle the exception type 'CustomSecurityTokenException' | ||
| ExpectedException = new ExpectedException( | ||
| typeof(SecurityTokenInvalidSignatureException), | ||
| "IDX10518:", | ||
| typeof(SecurityTokenException)), | ||
| ExpectedInnerException = ExpectedException.SecurityTokenException( | ||
| LogHelper.FormatInvariant( | ||
| Tokens.LogMessages.IDX10002, // "IDX10002: Unknown exception type returned. Type: '{0}'. Message: '{1}'."; | ||
| typeof(CustomSecurityTokenException), | ||
| nameof(CustomAlgorithmValidationDelegates.AlgorithmValidatorCustomExceptionTypeDelegate))), | ||
| ValidationError = new AlgorithmValidationError( | ||
| new MessageDetail( | ||
| nameof(CustomAlgorithmValidationDelegates.AlgorithmValidatorCustomExceptionTypeDelegate), null), | ||
| ValidationFailureType.AlgorithmValidationFailed, | ||
| typeof(CustomSecurityTokenException), | ||
| new StackFrame("CustomAlgorithmValidationDelegates.cs", 0), | ||
| "algorithm") | ||
| }); | ||
|
|
||
| // SignatureValidationError : ValidationError, ExceptionType: SecurityTokenInvalidSignatureException, inner: CustomSecurityTokenInvalidAlgorithmException | ||
| theoryData.Add(new AlgorithmExtensibilityTheoryData( | ||
| "AlgorithmValidatorThrows", | ||
| tokenHandlerType, | ||
| CustomAlgorithmValidationDelegates.AlgorithmValidatorThrows, | ||
| extraStackFrames: extraStackFrames + 1) | ||
| { | ||
| ExpectedException = new ExpectedException( | ||
| typeof(SecurityTokenInvalidSignatureException), | ||
| "IDX10273:", | ||
| typeof(CustomSecurityTokenInvalidAlgorithmException)), | ||
| ExpectedInnerException = new ExpectedException( | ||
| typeof(CustomSecurityTokenInvalidAlgorithmException), | ||
| nameof(CustomAlgorithmValidationDelegates.AlgorithmValidatorThrows)), | ||
| ValidationError = new SignatureValidationError( | ||
| new MessageDetail( | ||
| string.Format(Tokens.LogMessages.IDX10273), null), | ||
| ValidationFailureType.AlgorithmValidatorThrew, | ||
| typeof(SecurityTokenInvalidSignatureException), | ||
| new StackFrame(stackFrameFileName, 0), | ||
| null, // no inner validation error | ||
| new CustomSecurityTokenInvalidAlgorithmException(nameof(CustomAlgorithmValidationDelegates.AlgorithmValidatorThrows), null) | ||
| ) | ||
| }); | ||
| #endregion | ||
|
|
||
| return theoryData; | ||
| } | ||
| } | ||
| } | ||
| #nullable restore |
32 changes: 32 additions & 0 deletions
32
...ityModel.TestUtils/TokenValidationExtensibility/Tests/AlgorithmExtensibilityTheoryData.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,32 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Microsoft.IdentityModel.Tokens; | ||
|
|
||
| #nullable enable | ||
| namespace Microsoft.IdentityModel.TestUtils.TokenValidationExtensibility.Tests | ||
| { | ||
| public class AlgorithmExtensibilityTheoryData : ExtensibilityTheoryData | ||
| { | ||
| internal AlgorithmExtensibilityTheoryData( | ||
| string testId, | ||
| string tokenHandlerType, | ||
| AlgorithmValidationDelegate algorithmValidationDelegate, | ||
| int extraStackFrames) : base(testId, tokenHandlerType, extraStackFrames) | ||
| { | ||
| SecurityTokenDescriptor = new() | ||
| { | ||
| Issuer = Default.Issuer, | ||
| SigningCredentials = KeyingMaterial.DefaultX509SigningCreds_2048_RsaSha2_Sha2, | ||
| }; | ||
|
|
||
| ValidationParameters.AlgorithmValidator = algorithmValidationDelegate; | ||
| ValidationParameters.SignatureValidator = null; | ||
| ValidationParameters.IssuerSigningKeys.Add(KeyingMaterial.DefaultX509SigningCreds_2048_RsaSha2_Sha2.Key); | ||
| } | ||
| } | ||
| } | ||
| #nullable restore | ||
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
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.