-
Notifications
You must be signed in to change notification settings - Fork 434
Uses spans for issuer comparison and fixes prior index out of range error #2826
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
2 commits
Select commit
Hold shift + click to select a range
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
121 changes: 121 additions & 0 deletions
121
test/Microsoft.IdentityModel.Validators.Tests/AadIssuerValidatorTests.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,121 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Microsoft.IdentityModel.TestUtils; | ||
| using Xunit; | ||
|
|
||
| namespace Microsoft.IdentityModel.Validators.Tests | ||
| { | ||
| public class AadIssuerValidatorTests | ||
| { | ||
| [Theory, MemberData(nameof(AadIssuerValidationTestCases))] | ||
| public static void IsValidIssuer_ValidatesIssuersCorrectly(AadIssuerValidatorTheoryData theoryData) | ||
| { | ||
| // Act | ||
| var validationResult = AadIssuerValidator.IsValidIssuer( | ||
| theoryData.TemplatedIssuer, | ||
| theoryData.TenantIdClaim, | ||
| theoryData.TokenIssuer); | ||
|
|
||
| // Assert | ||
| Assert.Equal(theoryData.ExpectedResult, validationResult); | ||
| } | ||
|
|
||
| public static TheoryData<AadIssuerValidatorTheoryData> AadIssuerValidationTestCases() | ||
sruke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| var theoryData = new TheoryData<AadIssuerValidatorTheoryData> | ||
| { | ||
| // Success cases | ||
| new AadIssuerValidatorTheoryData("V1_Template_Matches_V1_Issuer_Success") | ||
| { | ||
| TemplatedIssuer = ValidatorConstants.AadIssuerV1CommonAuthority, | ||
| TokenIssuer = ValidatorConstants.V1Issuer, | ||
| TenantIdClaim = ValidatorConstants.TenantIdAsGuid, | ||
| ExpectedResult = true, | ||
| }, | ||
| new AadIssuerValidatorTheoryData("V2_Template_Matches_V2_Issuer_Success") | ||
| { | ||
| TemplatedIssuer = ValidatorConstants.AadIssuerV2CommonAuthority, | ||
| TokenIssuer = ValidatorConstants.AadIssuer, | ||
| TenantIdClaim = ValidatorConstants.TenantIdAsGuid, | ||
| ExpectedResult = true, | ||
| }, | ||
| new AadIssuerValidatorTheoryData("IssuerTemplate_WithTenantId_TokenIssuer_Match_Success") | ||
| { | ||
| TemplatedIssuer = ValidatorConstants.AadIssuer, | ||
| TokenIssuer = ValidatorConstants.AadIssuer, | ||
| TenantIdClaim = ValidatorConstants.TenantIdAsGuid, | ||
| ExpectedResult = true, | ||
| }, | ||
|
|
||
| // Failure cases | ||
| new AadIssuerValidatorTheoryData("V1_Template_With_V2_Issuer_Failure") | ||
| { | ||
| TemplatedIssuer = ValidatorConstants.AadIssuerV1CommonAuthority, | ||
| TokenIssuer = ValidatorConstants.AadIssuer, | ||
| TenantIdClaim = ValidatorConstants.TenantIdAsGuid, | ||
| ExpectedResult = false, | ||
| }, | ||
| new AadIssuerValidatorTheoryData("V2_Template_With_V1_Issuer_Failure") | ||
| { | ||
| TemplatedIssuer = ValidatorConstants.AadIssuerV2CommonAuthority, | ||
| TokenIssuer = ValidatorConstants.V1Issuer, | ||
| TenantIdClaim = ValidatorConstants.TenantIdAsGuid, | ||
| ExpectedResult = false, | ||
| }, | ||
| new AadIssuerValidatorTheoryData("Null_TokenIssuer_Failure") | ||
| { | ||
| TemplatedIssuer = ValidatorConstants.AadIssuerV1CommonAuthority, | ||
| TokenIssuer = "", | ||
| TenantIdClaim = ValidatorConstants.TenantIdAsGuid, | ||
| ExpectedResult = false, | ||
| }, | ||
| new AadIssuerValidatorTheoryData("Null_TenantId_Failure") | ||
| { | ||
| TemplatedIssuer = ValidatorConstants.AadIssuerV1CommonAuthority, | ||
| TokenIssuer = ValidatorConstants.AadIssuer, | ||
| TenantIdClaim = "", | ||
| ExpectedResult = false, | ||
| }, | ||
| new AadIssuerValidatorTheoryData("PPE_Template_With_V1_Issuer_Failure") | ||
| { | ||
| TemplatedIssuer = ValidatorConstants.AadInstancePPE + "/" + AadIssuerValidator.TenantIdTemplate, | ||
| TokenIssuer = ValidatorConstants.AadInstance + "/" + ValidatorConstants.TenantIdAsGuid, | ||
| TenantIdClaim = ValidatorConstants.TenantIdAsGuid, | ||
| ExpectedResult = false, | ||
| }, | ||
| new AadIssuerValidatorTheoryData("Malformed_V2_TokenIssuer_Failure") | ||
| { | ||
| TemplatedIssuer = ValidatorConstants.AadIssuerV2CommonAuthority, | ||
| TokenIssuer = "https://login.microsoftonline.com/{tenantid}/v2.0", | ||
| TenantIdClaim = ValidatorConstants.TenantIdAsGuid, | ||
| ExpectedResult = false, | ||
| }, | ||
| new AadIssuerValidatorTheoryData("IssuerTemplate_WithTenantId_TokenIssuer_NoMatch_Failure") | ||
| { | ||
| TemplatedIssuer = ValidatorConstants.AadIssuerPPE, | ||
| TokenIssuer = ValidatorConstants.AadIssuer, | ||
| TenantIdClaim = ValidatorConstants.TenantIdAsGuid, | ||
| ExpectedResult = false, | ||
| }, | ||
| }; | ||
|
|
||
| return theoryData; | ||
| } | ||
| } | ||
|
|
||
| public class AadIssuerValidatorTheoryData : TheoryDataBase | ||
| { | ||
| public AadIssuerValidatorTheoryData() {} | ||
|
|
||
| public AadIssuerValidatorTheoryData(string testId) : base(testId) { } | ||
|
|
||
| public string TemplatedIssuer { get; set; } | ||
|
|
||
| public string TokenIssuer { get; set; } | ||
|
|
||
| public string TenantIdClaim { get; set; } | ||
|
|
||
| public bool ExpectedResult { get; set; } | ||
| } | ||
| } | ||
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.