Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public async Task Susi_B2C_LocalAccount_TodoAppFucntionsCorrectly()
if (InitialConnectionRetryCount == 0) { throw ex; }
}
}
LabResponse labResponse = await LabUserHelper.GetB2CLocalAccountAsync().ConfigureAwait(false);
LabResponse labResponse = await LabUserHelper.GetB2CLocalAccountAsync();

// Initial sign in
_output.WriteLine("Starting web app sign-in flow.");
Expand Down
6 changes: 3 additions & 3 deletions tests/E2E Tests/WebAppUiTests/TestingWebAppLocally.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ public TestingWebAppLocally(ITestOutputHelper output)
[SupportedOSPlatform("windows")]
public async Task ChallengeUser_MicrosoftIdFlow_LocalApp_ValidEmailPassword()
{
LabResponse labResponse = await LabUserHelper.GetDefaultUserAsync().ConfigureAwait(false);
LabResponse labResponse = await LabUserHelper.GetDefaultUserAsync();

var clientEnvVars = new Dictionary<string, string>();

await ExecuteWebAppCallsGraphFlow(labResponse.User.Upn, labResponse.User.GetOrFetchPassword(), clientEnvVars, TraceFileClassName).ConfigureAwait(false);
await ExecuteWebAppCallsGraphFlow(labResponse.User.Upn, labResponse.User.GetOrFetchPassword(), clientEnvVars, TraceFileClassName);
}

[Theory]
Expand All @@ -61,7 +61,7 @@ public async Task ChallengeUser_MicrosoftIdFlow_LocalApp_ValidEmailWithCiamPassw
{"AzureAd__Instance", "" }
};

await ExecuteWebAppCallsGraphFlow("[email protected]", LabUserHelper.FetchUserPassword("msidlabciam6"), clientEnvVars, TraceFileClassNameCiam).ConfigureAwait(false);
await ExecuteWebAppCallsGraphFlow("[email protected]", LabUserHelper.FetchUserPassword("msidlabciam6"), clientEnvVars, TraceFileClassNameCiam);
}

private async Task ExecuteWebAppCallsGraphFlow(string upn, string credential, Dictionary<string, string>? clientEnvVars, string traceFileClassName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ public async Task ChallengeUser_MicrosoftIdFlow_LocalApp_ValidEmailPasswordCreds
Assert.Fail(TC.WebAppCrashedString + " " + runningProcesses.ToString());
}

page = await NavigateToWebApp(context, TodoListClientPort).ConfigureAwait(false);
LabResponse labResponse = await LabUserHelper.GetDefaultUserAsync().ConfigureAwait(false);
page = await NavigateToWebApp(context, TodoListClientPort);
LabResponse labResponse = await LabUserHelper.GetDefaultUserAsync();

// Initial sign in
_output.WriteLine("Starting web app sign-in flow.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public async Task GetAccessTokenOrAuthResultForApp_ReturnsAccessTokenOrAuthResul
}

AuthenticationResult authResult =
await _tokenAcquisition.GetAuthenticationResultForAppAsync(TestConstants.s_scopeForApp, tokenAcquisitionOptions: tokenAcquisitionOptions).ConfigureAwait(false);
await _tokenAcquisition.GetAuthenticationResultForAppAsync(TestConstants.s_scopeForApp, tokenAcquisitionOptions: tokenAcquisitionOptions);

// Assert
Assert.NotNull(authResult);
Expand All @@ -97,7 +97,7 @@ public async Task GetAccessTokenOrAuthResultForApp_ReturnsAccessTokenOrAuthResul
else
{
string token =
await _tokenAcquisition.GetAccessTokenForAppAsync(TestConstants.s_scopeForApp).ConfigureAwait(false);
await _tokenAcquisition.GetAccessTokenForAppAsync(TestConstants.s_scopeForApp);

// Assert
Assert.NotNull(token);
Expand All @@ -116,16 +116,16 @@ public async Task GetAccessTokenForAppAndAuthResultForApp_WithMetaTenant_ShouldT

// Act & Assert
async Task tokenResult() =>
await _tokenAcquisition.GetAccessTokenForAppAsync(TestConstants.s_scopeForApp, tenant: metaTenant).ConfigureAwait(false);
await _tokenAcquisition.GetAccessTokenForAppAsync(TestConstants.s_scopeForApp, tenant: metaTenant);

ArgumentException ex = await Assert.ThrowsAsync<ArgumentException>(tokenResult).ConfigureAwait(false);
ArgumentException ex = await Assert.ThrowsAsync<ArgumentException>(tokenResult);
Assert.Contains(IDWebErrorMessage.ClientCredentialTenantShouldBeTenanted, ex.Message, System.StringComparison.OrdinalIgnoreCase);

// Act & Assert
async Task authResult() =>
await _tokenAcquisition.GetAuthenticationResultForAppAsync(TestConstants.s_scopeForApp, tenant: metaTenant).ConfigureAwait(false);
await _tokenAcquisition.GetAuthenticationResultForAppAsync(TestConstants.s_scopeForApp, tenant: metaTenant);

ArgumentException ex2 = await Assert.ThrowsAsync<ArgumentException>(authResult).ConfigureAwait(false);
ArgumentException ex2 = await Assert.ThrowsAsync<ArgumentException>(authResult);
Assert.Contains(IDWebErrorMessage.ClientCredentialTenantShouldBeTenanted, ex2.Message, System.StringComparison.OrdinalIgnoreCase);

Assert.Equal(0, _msalTestTokenCacheProvider.Count);
Expand All @@ -144,7 +144,7 @@ public async Task GetAccessTokenOrAuthResultForApp_ConsumersTenantAsync(bool get
if (getAuthResult)
{
AuthenticationResult authResult =
await _tokenAcquisition.GetAuthenticationResultForAppAsync(TestConstants.s_scopeForApp, tenant: Constants.Consumers).ConfigureAwait(false);
await _tokenAcquisition.GetAuthenticationResultForAppAsync(TestConstants.s_scopeForApp, tenant: Constants.Consumers);

// Assert
Assert.NotNull(authResult);
Expand All @@ -155,7 +155,7 @@ public async Task GetAccessTokenOrAuthResultForApp_ConsumersTenantAsync(bool get
else
{
string token =
await _tokenAcquisition.GetAccessTokenForAppAsync(TestConstants.s_scopeForApp, tenant: Constants.Consumers).ConfigureAwait(false);
await _tokenAcquisition.GetAccessTokenForAppAsync(TestConstants.s_scopeForApp, tenant: Constants.Consumers);

// Assert
Assert.NotNull(token);
Expand All @@ -177,7 +177,7 @@ public async Task GetAccessTokenOrAuthResultForApp_TenantSpecificAsync(bool getA
if (getAuthResult)
{
AuthenticationResult authResult =
await _tokenAcquisition.GetAuthenticationResultForAppAsync(TestConstants.s_scopeForApp, tenant: TestConstants.ConfidentialClientLabTenant).ConfigureAwait(false);
await _tokenAcquisition.GetAuthenticationResultForAppAsync(TestConstants.s_scopeForApp, tenant: TestConstants.ConfidentialClientLabTenant);

// Assert
Assert.NotNull(authResult);
Expand All @@ -190,7 +190,7 @@ public async Task GetAccessTokenOrAuthResultForApp_TenantSpecificAsync(bool getA
string token =
await _tokenAcquisition.GetAccessTokenForAppAsync(
TestConstants.s_scopeForApp,
tenant: TestConstants.ConfidentialClientLabTenant).ConfigureAwait(false);
tenant: TestConstants.ConfidentialClientLabTenant);

// Assert
Assert.NotNull(token);
Expand All @@ -207,17 +207,17 @@ public async Task GetAccessTokenForApp_WithUserScope_MsalServiceExceptionThrownA

// Act & Assert
async Task result() =>
await _tokenAcquisition.GetAccessTokenForAppAsync(TestConstants.s_userReadScope.First()).ConfigureAwait(false);
await _tokenAcquisition.GetAccessTokenForAppAsync(TestConstants.s_userReadScope.First());

ArgumentException ex = await Assert.ThrowsAsync<ArgumentException>(result).ConfigureAwait(false);
ArgumentException ex = await Assert.ThrowsAsync<ArgumentException>(result);

Assert.Contains(IDWebErrorMessage.ClientCredentialScopeParameterShouldEndInDotDefault, ex.Message, System.StringComparison.OrdinalIgnoreCase);

// Act & Assert
async Task authResult() =>
await _tokenAcquisition.GetAuthenticationResultForAppAsync(TestConstants.s_userReadScope.First()).ConfigureAwait(false);
await _tokenAcquisition.GetAuthenticationResultForAppAsync(TestConstants.s_userReadScope.First());

ArgumentException ex2 = await Assert.ThrowsAsync<ArgumentException>(authResult).ConfigureAwait(false);
ArgumentException ex2 = await Assert.ThrowsAsync<ArgumentException>(authResult);

Assert.Contains(IDWebErrorMessage.ClientCredentialScopeParameterShouldEndInDotDefault, ex2.Message, System.StringComparison.OrdinalIgnoreCase);
Assert.Equal(0, _msalTestTokenCacheProvider.Count);
Expand Down Expand Up @@ -247,7 +247,7 @@ public async Task GetAccessTokenForApp_WithAnonymousController_Async()
var tokenAcquisition = services.GetRequiredService<ITokenAcquisition>();
var tokenAcquisitionHost = services.GetRequiredService<ITokenAcquisitionHost>();

var token = await tokenAcquisition.GetAccessTokenForAppAsync("https://graph.microsoft.com/.default").ConfigureAwait(false);
var token = await tokenAcquisition.GetAccessTokenForAppAsync("https://graph.microsoft.com/.default");

Assert.NotNull(token);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ public async Task GetTokenForUserAsync(
// Arrange
HttpClient client = CreateHttpClient(addInMemoryTokenCache);

var result = await AcquireTokenForLabUserAsync().ConfigureAwait(false);
var result = await AcquireTokenForLabUserAsync();

// Act
HttpResponseMessage response = await CreateHttpResponseMessage(webApiUrl, client, result).ConfigureAwait(false);
HttpResponseMessage response = await CreateHttpResponseMessage(webApiUrl, client, result);

// Assert
Assert.True(response.IsSuccessStatusCode);
Expand All @@ -78,10 +78,10 @@ public async Task GetTokenForUserWithDifferentAuthSchemeAsync(
// Arrange
HttpClient client = CreateHttpClient(addInMemoryTokenCache);

var result = await AcquireTokenForLabUserAsync().ConfigureAwait(false);
var result = await AcquireTokenForLabUserAsync();

// Act
HttpResponseMessage response = await CreateHttpResponseMessage(webApiUrl, client, result).ConfigureAwait(false);
HttpResponseMessage response = await CreateHttpResponseMessage(webApiUrl, client, result);

// Assert
Assert.True(response.IsSuccessStatusCode);
Expand Down Expand Up @@ -119,11 +119,11 @@ public async Task TestSigningKeyIssuer()
);

// Act
var result = await AcquireTokenForLabUserAsync().ConfigureAwait(false);
var result = await AcquireTokenForLabUserAsync();
HttpResponseMessage response = await CreateHttpResponseMessage(
TestConstants.SecurePage2GetTokenForUserAsync,
client,
result).ConfigureAwait(false);
result);
p.Kill();

// Assert
Expand Down Expand Up @@ -154,7 +154,7 @@ private static async Task<HttpResponseMessage> CreateHttpResponseMessage(string
Constants.Bearer,
result.AccessToken));
}
response = await client.SendAsync(httpRequestMessage).ConfigureAwait(false);
response = await client.SendAsync(httpRequestMessage);
}

return response;
Expand Down Expand Up @@ -194,7 +194,7 @@ private HttpClient CreateHttpClient(

private static async Task<AuthenticationResult> AcquireTokenForLabUserAsync()
{
var labResponse = await LabUserHelper.GetSpecificUserAsync(TestConstants.OBOUser).ConfigureAwait(false);
var labResponse = await LabUserHelper.GetSpecificUserAsync(TestConstants.OBOUser);
var msalPublicClient = PublicClientApplicationBuilder
.Create(TestConstants.OBOClientSideClientId)
.WithAuthority(labResponse.Lab.Authority, TestConstants.Organizations)
Expand All @@ -206,7 +206,7 @@ private static async Task<AuthenticationResult> AcquireTokenForLabUserAsync()
TestConstants.OBOUser,
labResponse.User.GetOrFetchPassword())
.ExecuteAsync(CancellationToken.None)
.ConfigureAwait(false);
;

return authResult;
}
Expand Down
34 changes: 17 additions & 17 deletions tests/Microsoft.Identity.Web.Test/CacheExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,23 @@ public async Task CacheExtensions_CcaAlreadyExists_TestsAsync()
{
AuthenticationResult result;
// new InMemory serializer and new cca
result = await CreateAppAndGetTokenAsync(CacheType.InMemory).ConfigureAwait(false);
result = await CreateAppAndGetTokenAsync(CacheType.InMemory);
Assert.Equal(TokenSource.IdentityProvider, result.AuthenticationResultMetadata.TokenSource);
AssertCacheTelemetry(result, CacheLevel.None);

result = await CreateAppAndGetTokenAsync(CacheType.InMemory, addTokenMock: false).ConfigureAwait(false);
result = await CreateAppAndGetTokenAsync(CacheType.InMemory, addTokenMock: false);
Assert.Equal(TokenSource.Cache, result.AuthenticationResultMetadata.TokenSource);
AssertCacheTelemetry(result, CacheLevel.L1Cache);

//Resetting token caches due to potential collision with other tests
TokenCacheExtensions.s_serviceProviderFromAction.Clear();

// new DistributedInMemory and same cca
result = await CreateAppAndGetTokenAsync(CacheType.DistributedInMemory).ConfigureAwait(false);
result = await CreateAppAndGetTokenAsync(CacheType.DistributedInMemory);
Assert.Equal(TokenSource.IdentityProvider, result.AuthenticationResultMetadata.TokenSource);
AssertCacheTelemetry(result, CacheLevel.None);

result = await CreateAppAndGetTokenAsync(CacheType.DistributedInMemory, addTokenMock: false).ConfigureAwait(false);
result = await CreateAppAndGetTokenAsync(CacheType.DistributedInMemory, addTokenMock: false);
Assert.Equal(TokenSource.Cache, result.AuthenticationResultMetadata.TokenSource);
AssertCacheTelemetry(result, CacheLevel.L1Cache);
}
Expand All @@ -63,11 +63,11 @@ public async Task CacheExtensions_CcaAlreadyExistsL2_TestsAsync()
{
AuthenticationResult result;
// new DistributedInMemory serializer with L1 cache disabled
result = await CreateAppAndGetTokenAsync(CacheType.DistributedInMemory, disableL1Cache: true).ConfigureAwait(false);
result = await CreateAppAndGetTokenAsync(CacheType.DistributedInMemory, disableL1Cache: true);
Assert.Equal(TokenSource.IdentityProvider, result.AuthenticationResultMetadata.TokenSource);
AssertCacheTelemetry(result, CacheLevel.None);

result = await CreateAppAndGetTokenAsync(CacheType.DistributedInMemory, addTokenMock: false, disableL1Cache: true).ConfigureAwait(false);
result = await CreateAppAndGetTokenAsync(CacheType.DistributedInMemory, addTokenMock: false, disableL1Cache: true);
Assert.Equal(TokenSource.Cache, result.AuthenticationResultMetadata.TokenSource);
AssertCacheTelemetry(result, CacheLevel.L2Cache);
}
Expand Down Expand Up @@ -181,10 +181,10 @@ public async Task SingletonMsal_ResultsInCorrectCacheEntries_Test()
// Different tenants used to created different cache entries
var result1 = await confidentialApp.AcquireTokenForClient(new[] { TestConstants.s_scopeForApp })
.WithTenantId(tenantId1)
.ExecuteAsync().ConfigureAwait(false);
.ExecuteAsync();
var result2 = await confidentialApp.AcquireTokenForClient(new[] { TestConstants.s_scopeForApp })
.WithTenantId(tenantId2)
.ExecuteAsync().ConfigureAwait(false);
.ExecuteAsync();

Assert.Equal(TokenSource.IdentityProvider, result1.AuthenticationResultMetadata.TokenSource);
Assert.Equal(TokenSource.IdentityProvider, result2.AuthenticationResultMetadata.TokenSource);
Expand Down Expand Up @@ -261,12 +261,12 @@ private async Task<AuthenticationResult> GetTokensAssociatedWithKey(string? cach
.WithClientSecret(TestConstants.ClientSecret)
.Build();

await msalMemoryTokenCacheProvider.InitializeAsync(confidentialApp.AppTokenCache).ConfigureAwait(false);
await msalMemoryTokenCacheProvider.InitializeAsync(confidentialApp.AppTokenCache);

AuthenticationResult result = await confidentialApp
.AcquireTokenForClient(["https://graph.microsoft.com/.default"])
.ExecuteAsync()
.ConfigureAwait(false);
;

Assert.Equal(
expectCacheHit ?
Expand All @@ -289,13 +289,13 @@ private async Task<AuthenticationResult> GetTokensAssociatedWithKey(string? cach
[Fact]
public async Task CacheKeyExtensibility()
{
var result = await GetTokensAssociatedWithKey("foo", expectCacheHit: false).ConfigureAwait(false);
result = await GetTokensAssociatedWithKey("bar", expectCacheHit: false).ConfigureAwait(false);
result = await GetTokensAssociatedWithKey(null, expectCacheHit: false).ConfigureAwait(false);
var result = await GetTokensAssociatedWithKey("foo", expectCacheHit: false);
result = await GetTokensAssociatedWithKey("bar", expectCacheHit: false);
result = await GetTokensAssociatedWithKey(null, expectCacheHit: false);

result = await GetTokensAssociatedWithKey("foo", expectCacheHit: true).ConfigureAwait(false);
result = await GetTokensAssociatedWithKey("bar", expectCacheHit: true).ConfigureAwait(false);
result = await GetTokensAssociatedWithKey(null, expectCacheHit: true).ConfigureAwait(false);
result = await GetTokensAssociatedWithKey("foo", expectCacheHit: true);
result = await GetTokensAssociatedWithKey("bar", expectCacheHit: true);
result = await GetTokensAssociatedWithKey(null, expectCacheHit: true);
}

private enum CacheType
Expand Down Expand Up @@ -353,7 +353,7 @@ private static async Task<AuthenticationResult> CreateAppAndGetTokenAsync(
}

var result = await confidentialApp.AcquireTokenForClient(new[] { TestConstants.s_scopeForApp })
.ExecuteAsync().ConfigureAwait(false);
.ExecuteAsync();

tokenHandler.ReplaceMockHttpMessageHandler = null!;
return result;
Expand Down
Loading
Loading