-
Notifications
You must be signed in to change notification settings - Fork 369
Refactor lab API and remove certificate based auth #5023
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
cc4e838
95a8a2b
993cd73
f5b456d
61817bd
f58e297
4c94b85
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Security.Cryptography; | ||
using System.Security.Cryptography.X509Certificates; | ||
|
||
namespace Microsoft.Identity.Test.Common.Core.Helpers | ||
{ | ||
public static class CertificateFinder | ||
{ | ||
/// <summary> | ||
/// Try and locate a certificate matching the given <paramref name="subjectName"/> by searching in | ||
/// the <see cref="StoreName.My"/> store subjectName for all available <see cref="StoreLocation"/>s. | ||
/// </summary> | ||
/// <param name="subjectName">Thumbprint of certificate to locate</param> | ||
/// <returns><see cref="X509Certificate2"/> with <paramref subjectName="subjectName"/>, or null if no matching certificate was found</returns> | ||
public static X509Certificate2 FindCertificateByName(string subjectName) | ||
{ | ||
foreach (StoreLocation storeLocation in Enum.GetValues(typeof(StoreLocation))) | ||
{ | ||
var certificate = FindCertificateByName(subjectName, storeLocation, StoreName.My); | ||
if (certificate != null) | ||
{ | ||
return certificate; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
/// <summary> | ||
/// Try and locate a certificate matching the given <paramref name="certName"/> by searching in | ||
/// the in the given <see cref="StoreName"/> and <see cref="StoreLocation"/>. | ||
/// </summary> | ||
/// <param subjectName="certName">Thumbprint of certificate to locate</param> | ||
/// <param subjectName="location"><see cref="StoreLocation"/> in which to search for a matching certificate</param> | ||
/// <param subjectName="name"><see cref="StoreName"/> in which to search for a matching certificate</param> | ||
/// <returns><see cref="X509Certificate2"/> with <paramref subjectName="certName"/>, or null if no matching certificate was found</returns> | ||
public static X509Certificate2 FindCertificateByName(string certName, StoreLocation location, StoreName name) | ||
{ | ||
// Don't validate certs, since the test root isn't installed. | ||
const bool validateCerts = false; | ||
|
||
using (var store = new X509Store(name, location)) | ||
{ | ||
store.Open(OpenFlags.ReadOnly); | ||
X509Certificate2Collection collection = store.Certificates.Find(X509FindType.FindBySubjectName, certName, validateCerts); | ||
|
||
X509Certificate2 certToUse = null; | ||
|
||
// select the "freshest" certificate | ||
foreach (X509Certificate2 cert in collection) | ||
{ | ||
if (certToUse == null || cert.NotBefore > certToUse.NotBefore) | ||
{ | ||
certToUse = cert; | ||
} | ||
} | ||
|
||
return certToUse; | ||
|
||
} | ||
} | ||
} | ||
|
||
public enum KnownTestCertType | ||
{ | ||
RSA, | ||
ECD | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,11 +32,7 @@ public async Task ROPC_Ciam_StandardDomains_CompletesSuccessfully() | |
{ | ||
string authority; | ||
//Get lab details | ||
var labResponse = await LabUserHelper.GetLabUserDataAsync(new UserQuery() | ||
{ | ||
FederationProvider = FederationProvider.CIAMCUD, | ||
SignInAudience = SignInAudience.AzureAdMyOrg | ||
}).ConfigureAwait(false); | ||
var labResponse = await LabUserHelper.GetCiamUserAync().ConfigureAwait(false); | ||
|
||
//https://tenantName.ciamlogin.com/ | ||
authority = string.Format("https://{0}.ciamlogin.com/", labResponse.User.LabName); | ||
|
@@ -87,12 +83,7 @@ public async Task ClientCredentialCiam_WithClientCredentials_ReturnsValidTokens( | |
{ | ||
string authority; | ||
//Get lab details | ||
var labResponse = await LabUserHelper.GetLabUserDataAsync(new UserQuery() | ||
{ | ||
FederationProvider = FederationProvider.CIAMCUD, | ||
SignInAudience = SignInAudience.AzureAdMyOrg | ||
}).ConfigureAwait(false); | ||
|
||
var labResponse = await LabUserHelper.GetCiamUserAync().ConfigureAwait(false); | ||
|
||
//https://tenantName.ciamlogin.com/ | ||
authority = string.Format("https://{0}.ciamlogin.com/", labResponse.User.LabName); | ||
|
@@ -117,7 +108,7 @@ private async Task RunCiamCCATest(string authority, string appId) | |
//Acquire tokens | ||
var msalConfidentialClientBuilder = ConfidentialClientApplicationBuilder | ||
.Create(appId) | ||
.WithCertificate(CertificateHelper.FindCertificateByName(TestConstants.AutomationTestCertName)) | ||
.WithCertificate(CertificateFinder.FindCertificateByName(TestConstants.AutomationTestCertName)) | ||
.WithExperimentalFeatures(); | ||
|
||
if (authority.Contains(Constants.CiamAuthorityHostSuffix)) | ||
|
@@ -157,11 +148,7 @@ public async Task OBOCiam_CustomDomain_ReturnsValidTokens() | |
string ciamWebApi = "634de702-3173-4a71-b336-a4fab786a479"; | ||
|
||
//Get lab details | ||
LabResponse labResponse = await LabUserHelper.GetLabUserDataAsync(new UserQuery() | ||
{ | ||
FederationProvider = FederationProvider.CIAMCUD, | ||
SignInAudience = SignInAudience.AzureAdMyOrg | ||
}).ConfigureAwait(false); | ||
var labResponse = await LabUserHelper.GetCiamUserAync().ConfigureAwait(false); | ||
|
||
//Acquire tokens | ||
var msalPublicClient = PublicClientApplicationBuilder | ||
|
@@ -184,7 +171,7 @@ public async Task OBOCiam_CustomDomain_ReturnsValidTokens() | |
//Acquire tokens for OBO | ||
var msalConfidentialClient = ConfidentialClientApplicationBuilder | ||
.Create(ciamWebApi) | ||
.WithCertificate(CertificateHelper.FindCertificateByName(TestConstants.AutomationTestCertName)) | ||
.WithCertificate(CertificateFinder.FindCertificateByName(TestConstants.AutomationTestCertName)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we create a new self signed cert for this purpose? and move away from the SNI cert for lab apps? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It still makes sense to have a single cert secure all our tests apps. |
||
.WithAuthority(authorityCud, false) | ||
.WithRedirectUri(_ciamRedirectUri) | ||
.BuildConcrete(); | ||
|
@@ -212,11 +199,5 @@ public async Task OBOCiam_CustomDomain_ReturnsValidTokens() | |
Assert.AreEqual(atHash, userCacheRecorder.LastAfterAccessNotificationArgs.SuggestedCacheKey); | ||
Assert.AreEqual(TokenSource.Cache, resultObo.AuthenticationResultMetadata.TokenSource); | ||
} | ||
|
||
private string GetCiamSecret() | ||
{ | ||
KeyVaultSecretsProvider provider = new KeyVaultSecretsProvider(); | ||
return provider.GetSecretByName("msidlabciam2-cc").Value; | ||
} | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,15 @@ | |
|
||
namespace Microsoft.Identity.Test.LabInfrastructure | ||
{ | ||
public class LabApiConstants | ||
public static class LabApiConstants | ||
{ | ||
public const string LabClientId = "f62c5ae3-bf3a-4af5-afa8-a68b800396e9"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we move to use Visual Studio credential for DevBox and UAMI based acccess for CI, we do not need this app flow anymore |
||
public const string LabScope = "https://request.msidlab.com/.default"; | ||
public const string LabClientInstance = "https://login.microsoftonline.com/"; | ||
public const string LabClientTenantId = "72f988bf-86f1-41af-91ab-2d7cd011db47"; | ||
} | ||
|
||
internal static class InternalConstants | ||
{ | ||
// constants for Lab api | ||
public const string MobileDeviceManagementWithConditionalAccess = "mdmca"; | ||
|
Uh oh!
There was an error while loading. Please reload this page.