Skip to content

Commit 2364608

Browse files
bgavrilMStrwalke
andauthored
Bogavril/regionaltest (#4962)
* Add an E2E test around refresh_in and region * msg * Update tests/Microsoft.Identity.Test.Integration.netcore/HeadlessTests/ClientCredentialsTests.NetFwk.cs Co-authored-by: Travis Walker <[email protected]> --------- Co-authored-by: Travis Walker <[email protected]>
1 parent f29be92 commit 2364608

File tree

2 files changed

+64
-24
lines changed

2 files changed

+64
-24
lines changed

tests/Microsoft.Identity.Test.Integration.netcore/HeadlessTests/ClientCredentialsTests.NetFwk.cs

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Diagnostics;
77
using System.Globalization;
88
using System.Linq;
9+
using System.Runtime.ConstrainedExecution;
910
using System.Security.Cryptography;
1011
using System.Security.Cryptography.X509Certificates;
1112
using System.Text;
@@ -50,9 +51,46 @@ public void TestInitialize()
5051
TestCommon.ResetInternalStaticCaches();
5152
}
5253

54+
// regression test based on SAL introducing a new SKU value and making ESTS not issue the refresh_in value
55+
// This needs to run on .NET and .NET FWK to protect against MSAL SKU value changes
5356
[DataTestMethod]
54-
[DataRow(Cloud.Public, TargetFrameworks.NetFx | TargetFrameworks.NetCore )]
55-
[DataRow(Cloud.Adfs, TargetFrameworks.NetFx | TargetFrameworks.NetCore )]
57+
[DataRow(true)]
58+
[DataRow(false)]
59+
public async Task RefreshOnIsEnabled(bool useRegional)
60+
{
61+
// if this test runs on local devbox, disable it
62+
if (useRegional && Environment.GetEnvironmentVariable("TF_BUILD") == null)
63+
{
64+
Assert.Inconclusive("Can't run regional on local devbox.");
65+
}
66+
67+
var cert = CertificateHelper.FindCertificateByName(TestConstants.AutomationTestCertName);
68+
69+
var builder = ConfidentialClientApplicationBuilder.Create(LabAuthenticationHelper.LabAccessConfidentialClientId)
70+
.WithCertificate(cert, sendX5C: true)
71+
.WithAuthority(LabAuthenticationHelper.LabClientInstance, LabAuthenticationHelper.LabClientTenantId);
72+
73+
// auto-detect should work on Azure DevOps build
74+
if (useRegional)
75+
builder = builder.WithAzureRegion();
76+
77+
var cca = builder.Build();
78+
79+
var result = await cca.AcquireTokenForClient([LabAuthenticationHelper.LabScope]).ExecuteAsync().ConfigureAwait(false);
80+
81+
Assert.AreEqual(TokenSource.IdentityProvider, result.AuthenticationResultMetadata.TokenSource);
82+
Assert.IsTrue(result.AuthenticationResultMetadata.RefreshOn.HasValue, "refresh_in was not issued - did the MSAL SKU value change?");
83+
84+
if (useRegional)
85+
Assert.AreEqual(
86+
Client.Region.RegionOutcome.AutodetectSuccess,
87+
result.AuthenticationResultMetadata.RegionDetails.RegionOutcome);
88+
}
89+
90+
91+
[DataTestMethod]
92+
[DataRow(Cloud.Public, TargetFrameworks.NetFx | TargetFrameworks.NetCore)]
93+
[DataRow(Cloud.Adfs, TargetFrameworks.NetFx | TargetFrameworks.NetCore)]
5694
//[DataRow(Cloud.PPE, TargetFrameworks.NetFx)]
5795
[DataRow(Cloud.Public, TargetFrameworks.NetCore, true)]
5896
//[DataRow(Cloud.Arlington)] - cert not setup
@@ -63,7 +101,7 @@ public async Task WithCertificate_TestAsync(Cloud cloud, TargetFrameworks runOn,
63101
}
64102

65103
[DataTestMethod]
66-
[DataRow(Cloud.Public, TargetFrameworks.NetCore)]
104+
[DataRow(Cloud.Public, TargetFrameworks.NetCore)]
67105
[DataRow(Cloud.Adfs, TargetFrameworks.NetFx)]
68106
//[DataRow(Cloud.Arlington, TargetFrameworks.NetCore)] TODO: https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/4905
69107
//[DataRow(Cloud.PPE)] - secret not setup
@@ -74,8 +112,8 @@ public async Task WithSecret_TestAsync(Cloud cloud, TargetFrameworks runOn)
74112
}
75113

76114
[DataTestMethod]
77-
[DataRow(Cloud.Public, TargetFrameworks.NetCore)]
78-
[DataRow(Cloud.Adfs, TargetFrameworks.NetCore)]
115+
[DataRow(Cloud.Public, TargetFrameworks.NetCore)]
116+
[DataRow(Cloud.Adfs, TargetFrameworks.NetCore)]
79117
//[DataRow(Cloud.PPE, TargetFrameworks.NetCore)]
80118
// [DataRow(Cloud.Arlington)] - cert not setup
81119
public async Task WithClientAssertion_Manual_TestAsync(Cloud cloud, TargetFrameworks runOn)
@@ -85,7 +123,7 @@ public async Task WithClientAssertion_Manual_TestAsync(Cloud cloud, TargetFramew
85123
}
86124

87125
[DataTestMethod]
88-
[DataRow(Cloud.Public, TargetFrameworks.NetFx )]
126+
[DataRow(Cloud.Public, TargetFrameworks.NetFx)]
89127
[DataRow(Cloud.Adfs, TargetFrameworks.NetFx)]
90128
//[DataRow(Cloud.PPE, TargetFrameworks.NetCore)]
91129
// [DataRow(Cloud.Arlington)] - cert not setup
@@ -134,7 +172,7 @@ public async Task WithClientClaims_SendX5C_OverrideClaims_TestAsync(Cloud cloud,
134172
}
135173

136174
[DataTestMethod]
137-
[DataRow(Cloud.Public, TargetFrameworks.NetCore)]
175+
[DataRow(Cloud.Public, TargetFrameworks.NetCore)]
138176
public async Task WithOnBeforeTokenRequest_TestAsync(Cloud cloud, TargetFrameworks runOn)
139177
{
140178
runOn.AssertFramework();
@@ -148,7 +186,7 @@ public async Task WithOnBeforeTokenRequest_TestAsync(Cloud cloud, TargetFramewor
148186
.WithAuthority(settings.Authority, true)
149187
.WithTestLogging()
150188
.Build();
151-
189+
152190
authResult = await confidentialApp
153191
.AcquireTokenForClient(settings.AppScopes)
154192
.OnBeforeTokenRequest((data) =>
@@ -171,7 +209,7 @@ public async Task WithOnBeforeTokenRequest_TestAsync(Cloud cloud, TargetFramewor
171209
.ExecuteAsync()
172210
.ConfigureAwait(false);
173211

174-
Assert.AreEqual(TokenSource.Cache, authResult.AuthenticationResultMetadata.TokenSource);
212+
Assert.AreEqual(TokenSource.Cache, authResult.AuthenticationResultMetadata.TokenSource);
175213
}
176214

177215
[RunOn(TargetFrameworks.NetCore)]
@@ -229,9 +267,9 @@ private static void ModifyRequest(OnBeforeTokenRequestData data, X509Certificate
229267
string tokenEndpoint = data.RequestUri.AbsoluteUri;
230268

231269
string assertion = GetSignedClientAssertionManual(
232-
issuer: clientId,
233-
audience: tokenEndpoint,
234-
certificate: certificate,
270+
issuer: clientId,
271+
audience: tokenEndpoint,
272+
certificate: certificate,
235273
useSha2AndPss: true);
236274

237275
data.BodyParameters.Add("client_assertion_type", "urn:ietf:params:oauth:client-assertion-type:jwt-bearer");
@@ -294,9 +332,9 @@ private async Task RunClientCredsAsync(Cloud cloud, CredentialType credentialTyp
294332
}
295333

296334
private static IConfidentialClientApplication CreateApp(
297-
CredentialType credentialType,
298-
IConfidentialAppSettings settings,
299-
bool sendX5C,
335+
CredentialType credentialType,
336+
IConfidentialAppSettings settings,
337+
bool sendX5C,
300338
bool useSha2AndPssForAssertion)
301339
{
302340
var builder = ConfidentialClientApplicationBuilder
@@ -420,9 +458,9 @@ private static string GetSignedClientAssertionUsingWilson(
420458
/// <param name="certificate"></param>
421459
/// <returns></returns>
422460
private static string GetSignedClientAssertionManual(
423-
string issuer,
424-
string audience,
425-
X509Certificate2 certificate,
461+
string issuer,
462+
string audience,
463+
X509Certificate2 certificate,
426464
bool useSha2AndPss)
427465
{
428466
const uint JwtToAadLifetimeInSeconds = 60 * 10; // Ten minutes
@@ -464,7 +502,7 @@ private static string GetSignedClientAssertionManual(
464502
{ "x5t", Base64UrlHelpers.Encode(certificate.GetCertHash())},
465503
};
466504
}
467-
505+
468506

469507
var headerBytes = JsonSerializer.SerializeToUtf8Bytes(header);
470508
var claimsBytes = JsonSerializer.SerializeToUtf8Bytes(claims);

tests/Microsoft.Identity.Test.LabInfrastructure/LabAuthenticationHelper.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@ namespace Microsoft.Identity.Test.LabInfrastructure
1515
{
1616
public static class LabAuthenticationHelper
1717
{
18-
private const string LabAccessConfidentialClientId = "f62c5ae3-bf3a-4af5-afa8-a68b800396e9";
19-
private const string LabAccessPublicClientId = "3c1e0e0d-b742-45ba-a35e-01c664e14b16";
20-
18+
public const string LabAccessConfidentialClientId = "f62c5ae3-bf3a-4af5-afa8-a68b800396e9";
19+
public const string LabScope = "https://request.msidlab.com/.default";
20+
public const string LabClientInstance = "https://login.microsoftonline.com/";
21+
public const string LabClientTenantId = "72f988bf-86f1-41af-91ab-2d7cd011db47";
22+
2123
public static async Task<AccessToken> GetAccessTokenForLabAPIAsync(string labAccessClientId)
2224
{
23-
string[] scopes = new string[] { "https://request.msidlab.com/.default" };
25+
string[] scopes = new string[] { LabScope };
2426

2527
return await GetLabAccessTokenAsync(
26-
"https://login.microsoftonline.com/72f988bf-86f1-41af-91ab-2d7cd011db47/",
28+
LabClientInstance + LabClientTenantId,
2729
scopes,
2830
labAccessClientId).ConfigureAwait(false);
2931
}

0 commit comments

Comments
 (0)