Add unit tests with HTTP mocking for vanilla dSTS + fix Authority par…#3805
Open
XiaoxinMS2 wants to merge 5 commits intomasterfrom
Open
Add unit tests with HTTP mocking for vanilla dSTS + fix Authority par…#3805XiaoxinMS2 wants to merge 5 commits intomasterfrom
XiaoxinMS2 wants to merge 5 commits intomasterfrom
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”),
|
Adds 7 HTTP-mocked unit tests for the vanilla dSTS (Dedicated Security Token Service) token-acquisition path in Microsoft.Identity.Web.
Per PR review feedback, dSTS users MUST configure 'Instance' (e.g. "https://{host}/dstsv2") and 'TenantId' separately. The single-string 'Authority' option is reserved for vanilla OIDC / CIAM scenarios and routes through MSAL.WithOidcAuthority(), which is incompatible with dSTS; configuring a dSTS-style URL there now throws an InvalidOperationException with a clear, actionable error message instead of letting MSAL surface its opaque "DSTS authority URI should have at least 2 segments..." error later.
Tests cover (canonical Instance + TenantId shape):
1. Token endpoint URI lock (POST to https://{host}/dstsv2/{tenant}/oauth2/v2.0/token)
2. Client_credentials grant body (grant_type, scope, client_id, client_secret)
3. Second-call cache hit (only one mock handler registered)
4. OAuth2 token-endpoint error -> MsalServiceException mapping
5. SendX5C=true -> client_assertion JWT header includes x5c
6. SendX5C=false -> x5c omitted
Plus 1 negative test:
7. Configuring dSTS URL via 'Authority' option -> InvalidOperationException with clear guidance to use Instance + TenantId
All tests use the existing MockHttpClientFactory infrastructure (no real network / Key Vault / cert) and run in any CI environment.
Implementation change in MergedOptions.ParseAuthorityIfNecessary: detects dSTS-shaped Authority (path segment "dstsv2") and throws an InvalidOperationException with a message that points users to the canonical Instance+TenantId shape. No public API changes.
eedbd53 to
c625531
Compare
cpp11nullptr
reviewed
May 7, 2026
| int indexEndOfTenant = indexVersion == -1 ? authoritySpan.Length : indexVersion + indexTenant + 1; | ||
|
|
||
| // dSTS authorities have the shape https://{host}/dstsv2/{tenantGuid}, i.e. TWO path | ||
| // segments instead of the AAD-style single segment. By design (cf. PR review), |
Contributor
There was a problem hiding this comment.
nit: once it's merged, it'd be not obvious which PR is meant there (without using git blame), perhaps, we remove avoid this part - cf. PR review.
cpp11nullptr
approved these changes
May 7, 2026
…ithub.com/AzureAD/microsoft-identity-web into zhanli1/dsts-unit-tests-with-http-mocking
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…sing
Adds 6 HTTP-mocked unit tests for the vanilla dSTS (Dedicated Security Token Service) token-acquisition path in Microsoft.Identity.Web, and fixes MergedOptions.ParseAuthorityIfNecessary so that the natural / documented dSTS configuration form works end-to-end:
Without the fix, the AAD-style parser took the literal "dstsv2" as the tenant and dropped the actual tenant GUID, producing an authority MSAL rejected with "The DSTS authority URI should have at least 2 segments...".
Tests cover: token endpoint URI; client_credentials grant body; second-call cache hit; OAuth2 error -> MsalServiceException mapping; SendX5C=true includes x5c JWT header; SendX5C=false omits it. All tests use the existing MockHttpClientFactory infrastructure (no real network / Key Vault / cert) and run in any CI environment.
No public API changes.
Add unit tests with HTTP mocking for vanilla dSTS scenarios + fix
Authority-only configurationSummary of the changes (Less than 80 chars)
Description
Adds 6 HTTP-mocked unit tests covering the vanilla dSTS (Dedicated Security Token Service) token-acquisition path in Microsoft.Identity.Web, and fixes a parser bug in
MergedOptions.ParseAuthorityIfNecessarythat prevented the natural / documented dSTS configuration form (options.Authority = "https://{host}/dstsv2/{tenantGuid}") from working.Both changes ship together because the new tests use the natural configuration form, which is the form the parser fix unblocks.
Vanilla dSTS support in Id.Web previously had zero unit-test coverage — the only assertion lived in integration tests that required a real dSTS deployment + Key Vault certificate, so they couldn't run in CI. Anyone refactoring
MergedOptions/TokenAcquirerFactorycould silently break dSTS token acquisition without any signal.Fixes #{bug number} (in this specific format)