Skip to content

Commit

Permalink
Update regional tests. (#4378)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmaytak authored Oct 19, 2023
1 parent 7696e10 commit 520ef2b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using Microsoft.Identity.Client;
using Microsoft.Identity.Client.Cache;
using Microsoft.Identity.Client.Internal;
using Microsoft.Identity.Client.PlatformsCommon.Factories;
#if NET_CORE
using Microsoft.Identity.Client.PlatformsCommon.Shared;
Expand All @@ -31,10 +28,6 @@ namespace Microsoft.Identity.Test.Integration.HeadlessTests
public class RegionalAuthIntegrationTests
{
private KeyVaultSecretsProvider _keyVault;
private Dictionary<string, string> _dict = new Dictionary<string, string>
{
["allowestsrnonmsi"] = "true"
};

private const string RegionalHost = "centralus.login.microsoft.com";
private const string GlobalHost = "login.microsoftonline.com";
Expand Down Expand Up @@ -158,7 +151,6 @@ private async Task<AuthenticationResult> GetAuthenticationResultAsync(
bool withForceRefresh = false)
{
var result = await _confidentialClientApplication.AcquireTokenForClient(scope)
.WithExtraQueryParameters(_dict)
.WithForceRefresh(withForceRefresh)
.ExecuteAsync()
.ConfigureAwait(false);
Expand Down Expand Up @@ -199,8 +191,8 @@ private static string GetSignedClientAssertionUsingMsalInternal(string clientId,
var manager = PlatformProxyFactory.CreatePlatformProxy(null).CryptographyManager;

var jwtToken = new Client.Internal.JsonWebToken(manager, clientId, TestConstants.ClientCredentialAudience, claims);
var cert = ConfidentialAppSettings.GetSettings(Cloud.Public).GetCertificate();
var cert = ConfidentialAppSettings.GetSettings(Cloud.Public).GetCertificate();

return jwtToken.Sign(cert, Base64UrlHelpers.Encode(cert.GetCertHash()), true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public async Task WithMultipleUsers_TestAsync()
public async Task ArlingtonWebAPIAccessingGraphOnBehalfOfUserTestAsync()
{
var arligntonUser = (await LabUserHelper.GetArlingtonUserAsync().ConfigureAwait(false)).User;

var msalPublicClient = PublicClientApplicationBuilder.Create("cb7faed4-b8c0-49ee-b421-f5ed16894c83")
.WithAuthority("https://login.microsoftonline.us/organizations")
.WithRedirectUri(TestConstants.RedirectUri)
Expand Down Expand Up @@ -417,7 +417,7 @@ private async Task<IConfidentialClientApplication> RunOnBehalfOfTestAsync(
.WithTestLogging()
.Build();
s_inMemoryTokenCache.Bind(pca.UserTokenCache);

try
{
authResult = await pca
Expand Down Expand Up @@ -498,11 +498,7 @@ private ConfidentialClientApplication BuildCca(string tenantId, bool withRegion
if (withRegion)
{
builder
.WithAzureRegion(TestConstants.Region)
.WithExtraQueryParameters(new Dictionary<string, string>
{
["allowestsrnonmsi"] = "true" // allow regional for testing
});
.WithAzureRegion(TestConstants.Region);
}

return builder.BuildConcrete();
Expand Down
8 changes: 0 additions & 8 deletions tests/devapps/RegionalTestApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Identity.Client;
using Microsoft.Identity.Test.Integration.NetFx.Infrastructure;

/**
* Note: Restart the application between the test cases to clear the statics.
Expand Down Expand Up @@ -174,10 +171,6 @@ private static async Task AcquireTokenAsync(string region, bool setEnvVariable =
}

string[] scopes = new string[] { $"{s_appSettings.ClientId}/.default", };
Dictionary<string, string> dict = new Dictionary<string, string>
{
["allowestsrnonmsi"] = "true"
};

var builder = ConfidentialClientApplicationBuilder.Create(s_appSettings.ClientId)
.WithAuthority(s_appSettings.Authority, false)
Expand All @@ -195,7 +188,6 @@ private static async Task AcquireTokenAsync(string region, bool setEnvVariable =
Console.WriteLine($"CCA created. Is regional:{region}, Set env var:{setEnvVariable}.");

AuthenticationResult result = await cca.AcquireTokenForClient(scopes)
.WithExtraQueryParameters(dict)
.ExecuteAsync()
.ConfigureAwait(false);

Expand Down

0 comments on commit 520ef2b

Please sign in to comment.