Skip to content

Commit

Permalink
Jennyf/fix slice (#2988)
Browse files Browse the repository at this point in the history
* fix CIAM bug and reenable tests

* only enable one test
  • Loading branch information
jennyf19 authored Aug 18, 2024
1 parent 60b96dc commit 7889d56
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/Microsoft.Identity.Web.TokenAcquisition/MergedOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,8 @@ internal static void ParseAuthorityIfNecessary(MergedOptions mergedOptions)
int indexTenant = authoritySpan.Slice(StartingIndex).IndexOf('/') + StartingIndex;
if (indexTenant >= 0)
{
int indexVersion = authoritySpan.Slice(indexTenant + 1).IndexOf('/') + indexTenant + 1;
int indexEndOfTenant = indexVersion == -1 ? authoritySpan.Length : indexVersion;
int indexVersion = authoritySpan.Slice(indexTenant + 1).IndexOf('/');
int indexEndOfTenant = indexVersion == -1 ? authoritySpan.Length : indexVersion + indexTenant + 1;

// In CIAM and B2C, customers will use "authority", not Instance and TenantId
mergedOptions.Instance = mergedOptions.PreserveAuthority ? mergedOptions.Authority : authoritySpan.Slice(0, indexTenant).ToString();
Expand Down
3 changes: 2 additions & 1 deletion tests/E2E Tests/WebAppUiTests/TestingWebAppLocally.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public async Task ChallengeUser_MicrosoftIdFlow_LocalApp_ValidEmailPassword()
await ExecuteWebAppCallsGraphFlow(labResponse.User.Upn, labResponse.User.GetOrFetchPassword(), clientEnvVars, TraceFileClassName).ConfigureAwait(false);
}

[Theory(Skip = "https://github.com/AzureAD/microsoft-identity-web/issues/2982")]
// [Theory(Skip = "https://github.com/AzureAD/microsoft-identity-web/issues/2982")]
[Theory]
[InlineData("https://MSIDLABCIAM6.ciamlogin.com")] // CIAM authority
[InlineData("https://login.msidlabsciam.com/fe362aec-5d43-45d1-b730-9755e60dc3b9/v2.0/")] // CIAM CUD Authority
[SupportedOSPlatform("windows")]
Expand Down
3 changes: 2 additions & 1 deletion tests/Microsoft.Identity.Web.Test.Common/TestConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public static class TestConstants
// CIAM
public const string CIAMInstance = "https://catsareawesome.ciamlogin.com";
public const string CIAMTenant = "aaaaaa-43bb-4ff9-89af-30ed8fe31c6d";
public const string CIAMAuthority = CIAMInstance + "/" + CIAMTenant + "/v2.0";
public const string CIAMAuthorityV2 = CIAMInstance + "/" + CIAMTenant + "/v2.0";
public const string CIAMAuthority = CIAMInstance + "/" + CIAMTenant;

// Claims
public const string ClaimNameTid = "tid";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,17 +238,33 @@ public void TestParseAuthorityIfNecessary_CIAM()
{
MergedOptions mergedOptions = new()
{
Authority = TC.CIAMAuthority,
Authority = TC.CIAMAuthorityV2,
PreserveAuthority = true
};

MergedOptions.ParseAuthorityIfNecessary(mergedOptions);

Assert.Equal(TC.CIAMAuthority, mergedOptions.Authority);
Assert.Equal(TC.CIAMAuthority, mergedOptions.Instance);
Assert.Equal(TC.CIAMAuthorityV2, mergedOptions.Authority);
Assert.Equal(TC.CIAMAuthorityV2, mergedOptions.Instance);
Assert.Null(mergedOptions.TenantId);
}

[Fact]
public void TestParseAuthority_PreserveAuthorityFalse_CIAM()
{
MergedOptions mergedOptions = new()
{
Authority = TC.CIAMAuthority,
PreserveAuthority = false
};

MergedOptions.ParseAuthorityIfNecessary(mergedOptions);

Assert.Equal(TC.CIAMAuthority, mergedOptions.Authority);
Assert.Equal(TC.CIAMInstance, mergedOptions.Instance);
Assert.Equal(TC.CIAMTenant, mergedOptions.TenantId);
}

[Fact]
public void TestParseAuthorityIfNecessary_V2Authority()
{
Expand Down

0 comments on commit 7889d56

Please sign in to comment.