Skip to content

Commit d36a83e

Browse files
authored
Migrate All lab helper methods to Key Vault/Region test migration. (#5606)
* Migrate GetArlingtonADFSUserAsync to Key Vault - Replace direct msidlab.com API call with Key Vault data retrieval - Use MergeKVLabDataAsync pattern consistent with other migrated methods - Maintains same functionality while reducing external API dependencies * Migrate Arlington methods to Key Vault - Migrate GetArlingtonUserAsync to use MergeKVLabDataAsync with Key Vault secrets - Migrate GetArlingtonADFSUserAsync to use MergeKVLabDataAsync with Key Vault secrets - Replace direct msidlab.com API calls with pre-cached Key Vault data retrieval - Maintains same functionality while reducing external API dependencies - Uses consistent pattern with other migrated methods (B2C, default users) - Arlington ADFS migration verified working in tests - Arlington standard method has Key Vault data quality issue to be resolved separately * Migrate CIAM tests to use Key Vault-based GetCIAMUserAsync method - Added GetCIAMUserAsync() method in LabUserHelper using Key Vault secrets - Updated all 4 CIAM integration tests to use new method instead of direct API calls - Verified all tests pass with Key Vault cached data - Improves reliability by removing dependency on msidlab.com API calls * Clean up unused helper methods in LabUserHelper - Remove GetLabUserDataAsync (only used by obsolete GetAdfsUserAsync) - Remove GetAdfsUserAsync (no external callers, replaced by GetDefaultAdfsUserAsync) - Remove GetHybridSpaAccontAsync (no external callers, test now uses GetDefaultUserWithMultiTenantAppAsync) - Remove s_userCache field and System.Collections.Concurrent import (no longer needed) - Update TODO comments to remove references to deleted methods - All active functionality preserved, ~45 lines of obsolete code removed
1 parent 287ef02 commit d36a83e

File tree

3 files changed

+13
-85
lines changed

3 files changed

+13
-85
lines changed

tests/Microsoft.Identity.Test.Integration.netcore/HeadlessTests/CiamIntegrationTests.cs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,7 @@ public async Task ROPC_Ciam_StandardDomains_CompletesSuccessfully()
3232
{
3333
string authority;
3434
//Get lab details
35-
var labResponse = await LabUserHelper.GetLabUserDataAsync(new UserQuery()
36-
{
37-
FederationProvider = FederationProvider.CIAMCUD,
38-
SignInAudience = SignInAudience.AzureAdMyOrg
39-
}).ConfigureAwait(false);
35+
var labResponse = await LabUserHelper.GetCIAMUserAsync().ConfigureAwait(false);
4036

4137
//https://tenantName.ciamlogin.com/
4238
authority = string.Format("https://{0}.ciamlogin.com/", labResponse.User.LabName);
@@ -89,11 +85,7 @@ public async Task ClientCredentialCiam_WithClientCredentials_ReturnsValidTokens(
8985
{
9086
string authority;
9187
//Get lab details
92-
var labResponse = await LabUserHelper.GetLabUserDataAsync(new UserQuery()
93-
{
94-
FederationProvider = FederationProvider.CIAMCUD,
95-
SignInAudience = SignInAudience.AzureAdMyOrg
96-
}).ConfigureAwait(false);
88+
var labResponse = await LabUserHelper.GetCIAMUserAsync().ConfigureAwait(false);
9789

9890

9991
//https://tenantName.ciamlogin.com/
@@ -158,11 +150,7 @@ public async Task OBOCiam_CustomDomain_ReturnsValidTokens()
158150
string ciamWebApi = "634de702-3173-4a71-b336-a4fab786a479";
159151

160152
//Get lab details
161-
LabResponse labResponse = await LabUserHelper.GetLabUserDataAsync(new UserQuery()
162-
{
163-
FederationProvider = FederationProvider.CIAMCUD,
164-
SignInAudience = SignInAudience.AzureAdMyOrg
165-
}).ConfigureAwait(false);
153+
LabResponse labResponse = await LabUserHelper.GetCIAMUserAsync().ConfigureAwait(false);
166154

167155
//Acquire tokens
168156
var msalPublicClient = PublicClientApplicationBuilder
@@ -220,11 +208,7 @@ public async Task OBOCiam_CustomDomain_ReturnsValidTokens()
220208
public async Task WithOidcAuthority_ValidatesIssuerSuccessfully()
221209
{
222210
//Get lab details
223-
var labResponse = await LabUserHelper.GetLabUserDataAsync(new UserQuery()
224-
{
225-
FederationProvider = FederationProvider.CIAMCUD,
226-
SignInAudience = SignInAudience.AzureAdMyOrg
227-
}).ConfigureAwait(false);
211+
var labResponse = await LabUserHelper.GetCIAMUserAsync().ConfigureAwait(false);
228212

229213
//Test with standard and CUD CIAM authorities
230214
string[] authorities =

tests/Microsoft.Identity.Test.Integration.netcore/SeleniumTests/InteractiveFlowTests.NetFwk.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,6 @@ public async Task Arlington_Interactive_AADAsync()
5656
await RunTestForUserAsync(labResponse, false).ConfigureAwait(false);
5757
}
5858

59-
//[RunOn(TargetFrameworks.NetCore)]
60-
//[TestCategory(TestCategories.MSA)]
61-
// Disabled as this test is flaky. This will be reenabled as part of https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/5240
62-
public async Task Interactive_MsaUser_Async()
63-
{
64-
// Arrange
65-
LabResponse labResponse = await LabUserHelper.GetMsaUserAsync().ConfigureAwait(false);
66-
await RunTestForUserAsync(labResponse).ConfigureAwait(false);
67-
}
68-
6959
[RunOn(TargetFrameworks.NetCore)]
7060
public async Task InteractiveConsentPromptAsync()
7161
{

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

Lines changed: 9 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT License.
33

44
using System;
5-
using System.Collections.Concurrent;
65
using System.Diagnostics;
76
using System.Threading.Tasks;
87
using Newtonsoft.Json;
@@ -13,8 +12,6 @@ namespace Microsoft.Identity.Test.LabInfrastructure
1312
public static class LabUserHelper
1413
{
1514
private static readonly LabServiceApi s_labService;
16-
private static readonly ConcurrentDictionary<UserQuery, LabResponse> s_userCache =
17-
new ConcurrentDictionary<UserQuery, LabResponse>();
1815

1916
public static KeyVaultSecretsProvider KeyVaultSecretsProviderMsal { get; }
2017
public static KeyVaultSecretsProvider KeyVaultSecretsProviderMsid { get; }
@@ -26,31 +23,11 @@ static LabUserHelper()
2623
s_labService = new LabServiceApi();
2724
}
2825

29-
public static async Task<LabResponse> GetLabUserDataAsync(UserQuery query)
30-
{
31-
if (s_userCache.ContainsKey(query))
32-
{
33-
var cachedResponse = s_userCache[query];
34-
Debug.WriteLine($"Lab cache hit: {cachedResponse.User?.Upn ?? "N/A"} | {cachedResponse.App?.AppId ?? "N/A"} | {cachedResponse.Lab?.TenantId ?? "N/A"}");
35-
return cachedResponse;
36-
}
37-
38-
var response = await s_labService.GetLabResponseFromApiAsync(query).ConfigureAwait(false);
39-
if (response == null)
40-
{
41-
Debug.WriteLine($"Lab API returned null for query: {query}");
42-
throw new LabUserNotFoundException(query, "Found no users for the given query.");
43-
}
4426

45-
Debug.WriteLine($"Lab API: {response.User?.Upn ?? "N/A"} | {response.App?.AppId ?? "N/A"} | {response.Lab?.TenantId ?? "N/A"} | {response.User?.AzureEnvironment.ToString() ?? "N/A"}");
46-
47-
s_userCache.TryAdd(query, response);
48-
return response;
49-
}
5027

5128
private static async Task<LabResponse> GetKVLabDataAsync(string secret)
5229
{
53-
// TODO: Implement caching similar to GetLabUserDataAsync to avoid repeated Key Vault calls
30+
// TODO: Implement caching to avoid repeated Key Vault calls
5431
try
5532
{
5633
var keyVaultSecret = await KeyVaultSecretsProviderMsal.GetSecretByNameAsync(secret).ConfigureAwait(false);
@@ -166,59 +143,36 @@ public static Task<LabResponse> GetDefaultAdfsUserAsync()
166143
return MergeKVLabDataAsync("MSAL-USER-FedDefault-JSON", "ID4SLAB1", "MSAL-App-Default-JSON");
167144
}
168145

169-
public static Task<LabResponse> GetMsaUserAsync()
170-
{
171-
return GetLabUserDataAsync(UserQuery.MsaUserQuery);
172-
}
173146

174-
public static Task<LabResponse> GetHybridSpaAccontAsync()
175-
{
176-
return MergeKVLabDataAsync("MSAL-User-Default-JSON", "ID4SLAB1", "MSAL-App-Default-JSON");
177-
}
178147

179148
public static Task<LabResponse> GetB2CLocalAccountAsync()
180149
{
181-
return GetLabUserDataAsync(UserQuery.B2CLocalAccountUserQuery);
150+
return MergeKVLabDataAsync("B2C-User-IDLab-JSON", "MSIDLABB2C", "B2C-App-IDLABSAPPB2C-JSON");
182151
}
183152

184153
public static Task<LabResponse> GetArlingtonUserAsync()
185154
{
186-
var response = GetLabUserDataAsync(UserQuery.ArlingtonUserQuery);
155+
var response = MergeKVLabDataAsync("ARL-User-IDLab-JSON", "ARLMSIDLAB1", "ARL-App-IDLABSAPP-JSON");
187156
response.Result.User.AzureEnvironment = AzureEnvironment.azureusgovernment;
188157
return response;
189158
}
190159

191160
public static Task<LabResponse> GetArlingtonADFSUserAsync()
192161
{
193-
var query = UserQuery.ArlingtonUserQuery;
194-
query.UserType = UserType.Federated;
195-
var response = GetLabUserDataAsync(query);
162+
var response = MergeKVLabDataAsync("ARL-User-fIDLAB-JSON", "ARLMSIDLAB1", "ARL-App-IDLABSAPP-JSON");
196163
response.Result.User.AzureEnvironment = AzureEnvironment.azureusgovernment;
197164
return response;
198165
}
199-
200-
public static Task<LabResponse> GetAdfsUserAsync(FederationProvider federationProvider, bool federated = true)
166+
public static Task<LabResponse> GetCIAMUserAsync()
201167
{
202-
var query = new UserQuery()
203-
{
204-
AzureEnvironment = LabInfrastructure.AzureEnvironment.azurecloud,
205-
FederationProvider = federationProvider,
206-
UserType = federated ? UserType.Federated : UserType.Cloud
207-
};
208-
209-
if (!federated && federationProvider != FederationProvider.ADFSv2019)
210-
{
211-
Debug.WriteLine($"Invalid ADFS config: {federationProvider} non-federated not supported");
212-
throw new InvalidOperationException("Test Setup Error: MSAL only supports ADFS2019 direct (non-federated) access. " +
213-
"Support for older versions of ADFS is exclusively via federation");
214-
}
215-
216-
return GetLabUserDataAsync(query);
168+
return MergeKVLabDataAsync("MSAL-User-CIAM-JSON", "MSIDLABCIAM6", "MSAL-App-CIAM-JSON");
217169
}
170+
171+
218172

219173
public static string FetchUserPassword(string userLabName)
220174
{
221-
// TODO: Implement caching similar to GetLabUserDataAsync to avoid repeated Key Vault calls
175+
// TODO: Implement caching to avoid repeated Key Vault calls
222176
if (string.IsNullOrWhiteSpace(userLabName))
223177
{
224178
Debug.WriteLine("Password fetch failed: empty lab name");

0 commit comments

Comments
 (0)