-
Notifications
You must be signed in to change notification settings - Fork 417
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
26 additions
and
69 deletions.
There are no files selected for viewing
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
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
39 changes: 8 additions & 31 deletions
39
test/Microsoft.IdentityModel.Validators.Tests/AadIssuerValidatorTests.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 |
---|---|---|
@@ -1,46 +1,23 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
using System; | ||
using Xunit; | ||
|
||
namespace Microsoft.IdentityModel.Validators.Tests | ||
{ | ||
public class AadIssuerValidatorTests | ||
{ | ||
[Fact] | ||
public static void IssuersWithTemplatesAreEqualTests_EqualIssuers() | ||
{ | ||
// arrange | ||
var issuer1Template = "{tenantId}"; | ||
var issuer1 = ValidatorConstants.AadInstance + issuer1Template; | ||
var issuer2Template = ValidatorConstants.TenantIdAsGuid; | ||
var issuer2 = ValidatorConstants.AadInstance + issuer2Template; | ||
int templateStartIndex = issuer1.IndexOf(issuer1Template); | ||
|
||
// act | ||
var result = AadIssuerValidator.IssuersWithTemplatesAreEqual( | ||
issuer1.AsSpan(), issuer1Template.AsSpan(), templateStartIndex, issuer2.AsSpan(), issuer2Template.AsSpan()); | ||
|
||
// assert | ||
Assert.True(result); | ||
} | ||
|
||
[Fact] | ||
public static void IssuersWithTemplatesAreEqualTests_UnequalIssuers() | ||
[Theory] | ||
[InlineData(ValidatorConstants.AadInstance + AadIssuerValidator.TenantIdTemplate, ValidatorConstants.AadInstance + ValidatorConstants.TenantIdAsGuid, true)] | ||
[InlineData(ValidatorConstants.AadInstancePPE + AadIssuerValidator.TenantIdTemplate, ValidatorConstants.AadInstance + ValidatorConstants.TenantIdAsGuid, false)] | ||
[InlineData("", ValidatorConstants.AadInstance + ValidatorConstants.TenantIdAsGuid, false)] | ||
[InlineData(ValidatorConstants.AadInstance + AadIssuerValidator.TenantIdTemplate, "", false)] | ||
public static void IsValidIssuer_CanValidateTemplatedIssuers(string templatedIssuer, string issuer, bool expectedResult) | ||
{ | ||
// arrange | ||
var issuer1Template = "{tenantId}"; | ||
var issuer1 = ValidatorConstants.AadInstancePPE + issuer1Template; | ||
var issuer2Template = ValidatorConstants.TenantIdAsGuid; | ||
var issuer2 = ValidatorConstants.AadInstance + issuer2Template; | ||
int templateStartIndex = issuer1.IndexOf(issuer1Template); | ||
|
||
// act | ||
var result = AadIssuerValidator.IssuersWithTemplatesAreEqual( | ||
issuer1.AsSpan(), issuer1Template.AsSpan(), templateStartIndex, issuer2.AsSpan(), issuer2Template.AsSpan()); | ||
var result = AadIssuerValidator.IsValidIssuer(templatedIssuer, ValidatorConstants.TenantIdAsGuid, issuer); | ||
|
||
// assert | ||
Assert.False(result); | ||
Assert.Equal(expectedResult, result); | ||
} | ||
} | ||
} |