Add dSTS integration tests#5669
Conversation
|
@XiaoxinMS2 please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
a305500 to
f2c6311
Compare
b22e69d to
17d1ae2
Compare
- Add 7 comprehensive integration tests for dSTS authority - Tests cover certificate authentication, token caching, tenant switching, correlation ID, and error handling - Store dSTS configuration securely in Key Vault (MISE-dSTS-CustomAppConfig) - Remove hardcoded sensitive information for security - All tests pass successfully (7/7)
17d1ae2 to
c377d4d
Compare
There was a problem hiding this comment.
Pull request overview
Adds new integration coverage for MSAL.NET’s dSTS (Distributed STS) authority by introducing a dedicated test suite that validates client-credentials scenarios and by wiring in a Key Vault secret name for retrieving dSTS app configuration.
Changes:
- Added a new
DstsIntegrationTestsheadless integration test suite covering token acquisition, cache behavior, tenant override, correlation ID propagation, and error handling. - Added a new Key Vault secret constant to retrieve dSTS app configuration from the lab Key Vault.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 10 comments.
| File | Description |
|---|---|
| tests/Microsoft.Identity.Test.LabInfrastructure/KeyVaultSecrets.cs | Adds a new Key Vault secret name constant for retrieving dSTS app configuration JSON. |
| tests/Microsoft.Identity.Test.Integration.netcore/HeadlessTests/DstsIntegrationTests.cs | Introduces new dSTS headless integration tests for confidential client flows and related behaviors. |
You can also share your feedback on Copilot code review. Take the survey.
| [TestMethod] | ||
| [TestCategory(DstsTestCategory)] | ||
| public async Task DstsAuthority_EndpointsAreCorrectlyFormatted_SuccessAsync() | ||
| { | ||
| // Arrange - Get dSTS configuration from Key Vault | ||
| var dstsApp = await LabResponseHelper.GetAppConfigAsync(KeyVaultSecrets.AppDsts).ConfigureAwait(false); | ||
| var cert = CertificateHelper.FindCertificateByName(TestConstants.AutomationTestCertName); |
| } | ||
|
|
||
| // Build authority URL without tenant, then specify tenant at request time | ||
| string dstsAuthorityTenantless = dstsApp.Authority.Replace($"/{dstsApp.TenantId}/", "/common/"); |
|
|
||
| string dstsAuthorityTenanted = dstsApp.Authority; | ||
| string dstsAuthorityCommon = dstsApp.Authority.Replace($"/{dstsApp.TenantId}/", "/common/"); | ||
|
|
| .Build(); | ||
|
|
||
| var app2 = ConfidentialClientApplicationBuilder | ||
| .Create(dstsApp.AppId) | ||
| .WithAuthority(dstsAuthorityCommon, validateAuthority: false) | ||
| .WithClientSecret("secret") | ||
| .Build(); | ||
|
|
||
| // Assert | ||
| var appImpl1 = app1 as ConfidentialClientApplication; | ||
| var appImpl2 = app2 as ConfidentialClientApplication; | ||
|
|
||
| Assert.AreEqual(AuthorityType.Dsts, appImpl1.AuthorityInfo.AuthorityType); | ||
| Assert.AreEqual(AuthorityType.Dsts, appImpl2.AuthorityInfo.AuthorityType); | ||
|
|
||
| Assert.IsTrue(appImpl1.AuthorityInfo.CanBeTenanted, "dSTS authority should support tenanting"); | ||
| Assert.IsTrue(appImpl1.AuthorityInfo.IsClientInfoSupported, "dSTS should support client info"); | ||
| Assert.IsTrue(appImpl1.AuthorityInfo.IsWsTrustFlowSupported, "dSTS should support WS-Trust"); | ||
| Assert.IsFalse(appImpl1.AuthorityInfo.IsInstanceDiscoverySupported, |
| /// Tests that dSTS authority endpoints are correctly formatted. | ||
| /// Validates token, authorization, and device code endpoints. |
| var confidentialApp = ConfidentialClientApplicationBuilder | ||
| .Create(dstsApp.AppId) | ||
| .WithAuthority(dstsApp.Authority, validateAuthority: false) | ||
| .WithCertificate(cert) | ||
| .Build(); | ||
|
|
||
| var appImpl = confidentialApp as ConfidentialClientApplication; | ||
| var authority = appImpl.AuthorityInfo; | ||
|
|
| [TestMethod] | ||
| [TestCategory(DstsTestCategory)] | ||
| public async Task DstsAuthority_Configuration_IsValidAsync() | ||
| { | ||
| // Arrange - Get dSTS configuration from Key Vault | ||
| var dstsApp = await LabResponseHelper.GetAppConfigAsync(KeyVaultSecrets.AppDsts).ConfigureAwait(false); |
|
|
||
| // Name of key vault secrets for app secrets and certificates | ||
| public const string DefaultAppSecret = "MSAL-App-Default"; | ||
|
|
||
| // dSTS configuration | ||
| public const string AppDsts = "MISE-App-DSTS-JSON"; |
| // dSTS configuration | ||
| public const string AppDsts = "MISE-App-DSTS-JSON"; |
| using System.Linq; | ||
| using System.Security.Cryptography.X509Certificates; |
Fixes #
Changes proposed in this request
Testing
Performance impact
Documentation