Skip to content

Commit

Permalink
Add unit tests for new methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kllysng committed Jun 4, 2024
1 parent a585032 commit c04a235
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 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()
{
// 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());

// assert
Assert.False(result);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,21 @@ public static TheoryData<AadSigningKeyIssuerTheoryData> ValidateIssuerSigningKey
}
}

[Fact]
public static void CreateIssuer_ReturnsExpectedIssuer()
{
// arrange
var issuerTemplate = "{tenantId}";
var issuer = ValidatorConstants.AadInstance + issuerTemplate;
int templateStartIndex = issuer.IndexOf(issuerTemplate);

// act
var result = AadTokenValidationParametersExtension.CreateIssuer(issuer, issuerTemplate, ValidatorConstants.TenantIdAsGuid, templateStartIndex);

Check failure on line 337 in test/Microsoft.IdentityModel.Validators.Tests/AadSigningKeyIssuerValidatorTests.cs

View workflow job for this annotation

GitHub Actions / Wilson GitHub Action Test

'AadTokenValidationParametersExtension' does not contain a definition for 'CreateIssuer'

Check failure on line 337 in test/Microsoft.IdentityModel.Validators.Tests/AadSigningKeyIssuerValidatorTests.cs

View workflow job for this annotation

GitHub Actions / Wilson GitHub Action Test

'AadTokenValidationParametersExtension' does not contain a definition for 'CreateIssuer'

Check failure on line 337 in test/Microsoft.IdentityModel.Validators.Tests/AadSigningKeyIssuerValidatorTests.cs

View workflow job for this annotation

GitHub Actions / Wilson GitHub Action Test

'AadTokenValidationParametersExtension' does not contain a definition for 'CreateIssuer'

Check failure on line 337 in test/Microsoft.IdentityModel.Validators.Tests/AadSigningKeyIssuerValidatorTests.cs

View workflow job for this annotation

GitHub Actions / Wilson GitHub Action Test

'AadTokenValidationParametersExtension' does not contain a definition for 'CreateIssuer'

Check failure on line 337 in test/Microsoft.IdentityModel.Validators.Tests/AadSigningKeyIssuerValidatorTests.cs

View workflow job for this annotation

GitHub Actions / Wilson GitHub Action Test

'AadTokenValidationParametersExtension' does not contain a definition for 'CreateIssuer'

Check failure on line 337 in test/Microsoft.IdentityModel.Validators.Tests/AadSigningKeyIssuerValidatorTests.cs

View workflow job for this annotation

GitHub Actions / Wilson GitHub Action Test

'AadTokenValidationParametersExtension' does not contain a definition for 'CreateIssuer'

Check failure on line 337 in test/Microsoft.IdentityModel.Validators.Tests/AadSigningKeyIssuerValidatorTests.cs

View workflow job for this annotation

GitHub Actions / Wilson GitHub Action Test

'AadTokenValidationParametersExtension' does not contain a definition for 'CreateIssuer'

// assert
Assert.Equal(ValidatorConstants.AadInstance + ValidatorConstants.TenantIdAsGuid, result);
}

private static OpenIdConnectConfiguration GetConfigurationMock()
{
var config = new OpenIdConnectConfiguration();
Expand Down

0 comments on commit c04a235

Please sign in to comment.