Extract reusable MSAL test infrastructure into Microsoft.Identity.Lab.API#5864
Extract reusable MSAL test infrastructure into Microsoft.Identity.Lab.API#5864
Conversation
…e into Microsoft.Identity.Client.TestOnly Co-authored-by: gladjohn <90415114+gladjohn@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR consolidates shared test infrastructure (previously spread across Microsoft.Identity.Test.Common and Microsoft.Identity.Test.LabInfrastructure) into a new packable library under src/client (Microsoft.Identity.Client.TestOnly), then updates unit/integration/perf/devapp test projects to reference it. It also standardizes several test constants (e.g., placeholder credentials, s_-prefixed static fields) and wires the new package into the signing/packing pipeline.
Changes:
- Introduces
src/client/Microsoft.Identity.Client.TestOnlyas the new home for shared test helpers/mocks and lab infra code; updatesInternalsVisibleToaccordingly. - Updates multiple test projects and solutions to reference
Microsoft.Identity.Client.TestOnlyand removes direct references to older test common/lab infra projects. - Replaces several test password usages with placeholder credentials and renames a handful of test constants (
ExtraHttpHeader→s_extraHttpHeader,ClientCapabilities→s_clientCapabilities, iOS constants casing, etc.).
Reviewed changes
Copilot reviewed 86 out of 101 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Microsoft.Identity.Test.Unit/TelemetryTests/HttpTelemetryTests.cs | Switches ROPC password usage to placeholder credential constant. |
| tests/Microsoft.Identity.Test.Unit/PublicApiTests/TestIdentityLogger.cs | Removes old test logger (moved into TestOnly helpers). |
| tests/Microsoft.Identity.Test.Unit/PublicApiTests/PublicClientApplicationTests.cs | Updates extra header constant usage (now s_extraHttpHeader). |
| tests/Microsoft.Identity.Test.Unit/PublicApiTests/ConfidentialClientApplicationTests.cs | Updates client capabilities constant usage (now s_clientCapabilities). |
| tests/Microsoft.Identity.Test.Unit/PublicApiTests/ClientCredentialWithCertTest.cs | Replaces cert password + ROPC password constants with placeholder credentials. |
| tests/Microsoft.Identity.Test.Unit/PublicApiTests/ClientAssertionTests.cs | Updates client capabilities constant usage (now s_clientCapabilities). |
| tests/Microsoft.Identity.Test.Unit/PublicApiTests/AdfsAcceptanceTests.cs | Switches ROPC password usage to placeholder credential constant. |
| tests/Microsoft.Identity.Test.Unit/Microsoft.Identity.Test.Unit.csproj | Replaces project reference to old test common with new TestOnly project reference. |
| tests/Microsoft.Identity.Test.Unit/ManagedIdentityTests/ServiceFabricTests.cs | Updates test certificate password constant usage. |
| tests/Microsoft.Identity.Test.Unit/ManagedIdentityTests/ManagedIdentityTests.cs | Removes blank lines + updates client capabilities constant usage. |
| tests/Microsoft.Identity.Test.Unit/ManagedIdentityTests/ImdsV2Tests.cs | Removes reference to old PublicApiTests namespace import. |
| tests/Microsoft.Identity.Test.Unit/CryptographyTests.cs | Updates test certificate password constant usage. |
| tests/Microsoft.Identity.Test.Unit/CoreTests/OAuth2Tests/ClaimsTest.cs | Updates client capabilities constant usage (now s_clientCapabilities). |
| tests/Microsoft.Identity.Test.Unit/BrokerTests/BrokerRequestTests.cs | Renames iOS broker constant identifiers to IOS... casing. |
| tests/Microsoft.Identity.Test.Unit/AppConfigTests/ConfidentialClientApplicationExtensibilityApiTests.cs | Updates test certificate password constant usage. |
| tests/Microsoft.Identity.Test.Unit/AppConfigTests/ConfidentialClientApplicationBuilderTests.cs | Updates test certificate password + client capabilities constant usage. |
| tests/Microsoft.Identity.Test.Performance/Microsoft.Identity.Test.Performance.csproj | Replaces project reference to old test common with new TestOnly project reference. |
| tests/Microsoft.Identity.Test.LabInfrastructure/UserConfig.cs | Removes old lab infra type (moved into TestOnly). |
| tests/Microsoft.Identity.Test.LabInfrastructure/Microsoft.Identity.Test.LabInfrastructure.csproj | Removes old lab infra project (replaced by TestOnly). |
| tests/Microsoft.Identity.Test.LabInfrastructure/LabConstants.cs | Removes old lab infra constants (moved into TestOnly). |
| tests/Microsoft.Identity.Test.LabInfrastructure/KeyVaultSecretsProvider.cs | Removes old Key Vault provider implementation (moved into TestOnly). |
| tests/Microsoft.Identity.Test.LabInfrastructure/KeyVaultSecrets.cs | Removes old Key Vault secret name constants (moved into TestOnly). |
| tests/Microsoft.Identity.Test.LabInfrastructure/CertificateHelper.cs | Removes old cert helper (moved into TestOnly). |
| tests/Microsoft.Identity.Test.LabInfrastructure/AppConfig.cs | Removes old app config model (moved into TestOnly). |
| tests/Microsoft.Identity.Test.Integration.netfx/Microsoft.Identity.Test.Integration.NetFx.csproj | Replaces references to old lab infra/test common with TestOnly. |
| tests/Microsoft.Identity.Test.Integration.netcore/SeleniumTests/ConfidentialClientAuthorizationTests.cs | Updates extra header constant usage (now s_extraHttpHeader). |
| tests/Microsoft.Identity.Test.Integration.netcore/Microsoft.Identity.Test.Integration.NetCore.csproj | Replaces references to old lab infra/test common with TestOnly. |
| tests/Microsoft.Identity.Test.E2e/Microsoft.Identity.Test.E2E.MSI.csproj | Replaces reference to old test common with TestOnly. |
| tests/Microsoft.Identity.Test.Common/TestCategories.cs | Removes old test categories (moved into TestOnly). |
| tests/Microsoft.Identity.Test.Common/Core/Mocks/TestTimeService.cs | Removes old mock time service (moved into TestOnly). |
| tests/Microsoft.Identity.Test.Common/Core/Mocks/TestLegacyCachePersistance.cs | Removes old legacy cache persistence mock (moved into TestOnly). |
| tests/Microsoft.Identity.Test.Common/Core/Mocks/MockHttpManager.cs | Removes old mock HTTP manager implementation (moved into TestOnly). |
| tests/Microsoft.Identity.Test.Common/Core/Helpers/TokenCacheAccessRecorder.cs | Removes old cache access recorder (moved into TestOnly). |
| tests/Microsoft.Identity.Test.Common/Core/Helpers/RunOnPlatformAttribute.cs | Removes old platform test attributes (moved into TestOnly). |
| tests/Microsoft.Identity.Test.Common/Core/Helpers/RSACertificatePopCryptoProvider.cs | Removes old RSA PoP crypto provider (moved into TestOnly). |
| tests/Microsoft.Identity.Test.Common/Core/Helpers/RecordingHandler.cs | Removes old recording handler (moved into TestOnly). |
| tests/Microsoft.Identity.Test.Common/Core/Helpers/RandomDataUtils.cs | Removes old random data helper (moved into TestOnly). |
| tests/Microsoft.Identity.Test.Common/Core/Helpers/JsonTestUtils.cs | Removes old JSON helpers (moved into TestOnly). |
| tests/Microsoft.Identity.Test.Common/Core/Helpers/ECDCertificatePopCryptoProvider.cs | Removes old ECDSA PoP crypto provider (moved into TestOnly). |
| tests/Microsoft.Identity.Test.Common/AuthorityWithExpectedTenantId.cs | Removes old authority/tenant test model (moved into TestOnly). |
| tests/devapps/DesktopTestApp/DesktopTestApp.csproj | Replaces references to old test common/lab infra with TestOnly. |
| tests/CacheCompat/CommonCache.Test.Unit/CommonCache.Test.Unit.csproj | Replaces lab infra reference with TestOnly. |
| src/client/Microsoft.Identity.Client/Properties/InternalsVisibleTo.cs | Switches internals visibility from Microsoft.Identity.Test.Common to Microsoft.Identity.Client.TestOnly. |
| src/client/Microsoft.Identity.Client.TestOnly/UI/MsalMockHelpers.cs | Adds service bundle extension methods to configure mocked Web UI. |
| src/client/Microsoft.Identity.Client.TestOnly/UI/MockWebUI.cs | Adds mocked Web UI implementation for auth flows. |
| src/client/Microsoft.Identity.Client.TestOnly/TestData.cs | Updates client capabilities data source to use s_clientCapabilities. |
| src/client/Microsoft.Identity.Client.TestOnly/TestCategories.cs | Adds test category constants into TestOnly package. |
| src/client/Microsoft.Identity.Client.TestOnly/PublicAPI.Shipped.txt | Adds initial shipped API tracking file for TestOnly package. |
| src/client/Microsoft.Identity.Client.TestOnly/Microsoft.Identity.Client.TestOnly.csproj | Makes TestOnly project packable; adds references and content (CredScan suppressions). |
| src/client/Microsoft.Identity.Client.TestOnly/LabInfra/UserConfig.cs | Adds lab user config model into TestOnly package. |
| src/client/Microsoft.Identity.Client.TestOnly/LabInfra/LabResponseHelper.cs | Enhances docs; includes Key Vault secret retrieval helpers and caches. |
| src/client/Microsoft.Identity.Client.TestOnly/LabInfra/LabConstants.cs | Adds lab constants + Cloud enum into TestOnly package. |
| src/client/Microsoft.Identity.Client.TestOnly/LabInfra/LabAuthenticationHelper.cs | Adds/updates lab auth helper docs and token acquisition helpers. |
| src/client/Microsoft.Identity.Client.TestOnly/LabInfra/KeyVaultSecretsProvider.cs | Adds Key Vault secret/cert provider into TestOnly package. |
| src/client/Microsoft.Identity.Client.TestOnly/LabInfra/KeyVaultSecrets.cs | Adds Key Vault secret name constants into TestOnly package. |
| src/client/Microsoft.Identity.Client.TestOnly/LabInfra/data.txt | Carries lab infra data file into TestOnly structure. |
| src/client/Microsoft.Identity.Client.TestOnly/LabInfra/CertificateHelper.cs | Adds cross-platform cert lookup/loading helper into TestOnly package. |
| src/client/Microsoft.Identity.Client.TestOnly/LabInfra/AppConfig.cs | Adds lab app config model into TestOnly package. |
| src/client/Microsoft.Identity.Client.TestOnly/InternalsVisibleTo.cs | Normalizes file header/formatting. |
| src/client/Microsoft.Identity.Client.TestOnly/Internal/TestCommon.cs | Reflows formatting/whitespace for TestCommon helper. |
| src/client/Microsoft.Identity.Client.TestOnly/Http/TokenCacheHelper.cs | Adds cache population helpers into TestOnly package. |
| src/client/Microsoft.Identity.Client.TestOnly/Http/TestTimeService.cs | Adds test time service into TestOnly package. |
| src/client/Microsoft.Identity.Client.TestOnly/Http/TestLegacyCachePersistance.cs | Adds legacy cache persistence mock into TestOnly package. |
| src/client/Microsoft.Identity.Client.TestOnly/Http/TestGuidQueueFactory.cs | Adds deterministic GUID queue factory for tests. |
| src/client/Microsoft.Identity.Client.TestOnly/Http/TestGuidFactory.cs | Adds deterministic single GUID factory for tests. |
| src/client/Microsoft.Identity.Client.TestOnly/Http/MockHttpMessageHandler.cs | Makes mock HTTP handler public + adds extensive XML docs. |
| src/client/Microsoft.Identity.Client.TestOnly/Http/MockHttpManagerExtensions.cs | Updates enum docs/formatting for token response types. |
| src/client/Microsoft.Identity.Client.TestOnly/Http/MockHttpManager.cs | Adds mock IHttpManager and client factories into TestOnly package. |
| src/client/Microsoft.Identity.Client.TestOnly/Http/MockHttpAndServiceBundle.cs | Adds combined HTTP manager + service bundle test harness. |
| src/client/Microsoft.Identity.Client.TestOnly/Http/LegacyTokenCacheHelper.cs | Adds helpers to populate ADAL legacy cache for tests. |
| src/client/Microsoft.Identity.Client.TestOnly/Http/InMemoryTokenCache.cs | Adds XML docs to in-memory token cache binding helpers. |
| src/client/Microsoft.Identity.Client.TestOnly/Http/InMemoryPartitionedTokenCache.cs | Adds in-memory partitioned token cache implementation. |
| src/client/Microsoft.Identity.Client.TestOnly/Helpers/UserAccessorWithPartitionAsserts.cs | Adds partition key assertion accessor for user cache. |
| src/client/Microsoft.Identity.Client.TestOnly/Helpers/TraceLogger.cs | Adds ILoggerAdapter implementation writing to Trace. |
| src/client/Microsoft.Identity.Client.TestOnly/Helpers/TokenCacheExtensions.cs | Adds token cache extension helpers (record access, clear tokens). |
| src/client/Microsoft.Identity.Client.TestOnly/Helpers/TokenCacheAccessRecorder.cs | Adds token cache access recorder helper into TestOnly package. |
| src/client/Microsoft.Identity.Client.TestOnly/Helpers/TestIdentityLogger.cs | Adds test identity logger into TestOnly package. |
| src/client/Microsoft.Identity.Client.TestOnly/Helpers/RunOnPlatformAttribute.cs | Adds platform-based MSTest attributes into TestOnly package. |
| src/client/Microsoft.Identity.Client.TestOnly/Helpers/RSACertificatePopCryptoProvider.cs | Adds RSA PoP crypto provider helper into TestOnly package. |
| src/client/Microsoft.Identity.Client.TestOnly/Helpers/RecordingHandler.cs | Adds delegating handler to record HTTP interactions in tests. |
| src/client/Microsoft.Identity.Client.TestOnly/Helpers/RandomDataUtils.cs | Adds random byte generation utility into TestOnly package. |
| src/client/Microsoft.Identity.Client.TestOnly/Helpers/PerformanceValidator.cs | Adds XML docs for timing validator utility. |
| src/client/Microsoft.Identity.Client.TestOnly/Helpers/OsHelper.cs | Changes visibility + adds conditional import for NET8+; expands docs. |
| src/client/Microsoft.Identity.Client.TestOnly/Helpers/ManagedIdentityTestUtil.cs | Adds extensive docs; fixes param doc mismatch. |
| src/client/Microsoft.Identity.Client.TestOnly/Helpers/JsonTestUtils.cs | Adds JSON helpers into TestOnly package. |
| src/client/Microsoft.Identity.Client.TestOnly/Helpers/HttpSnifferClientFactory.cs | Adds docs for request/response recording factory and mTLS support. |
| src/client/Microsoft.Identity.Client.TestOnly/Helpers/EnvVariableContext.cs | Adds docs for env var snapshot/restore helper. |
| src/client/Microsoft.Identity.Client.TestOnly/Helpers/ECDCertificatePopCryptoProvider.cs | Adds ECDSA PoP crypto provider helper into TestOnly package. |
| src/client/Microsoft.Identity.Client.TestOnly/Helpers/CoreAssert.cs | Adds/updates assertion helpers; includes reflection-based immutability checker. |
| src/client/Microsoft.Identity.Client.TestOnly/Helpers/AssertException.cs | Adds extensive docs to exception assertion helpers. |
| src/client/Microsoft.Identity.Client.TestOnly/Helpers/AppConfigTestExtensions.cs | Adds builder extension to enable cache partitioning asserts. |
| src/client/Microsoft.Identity.Client.TestOnly/Helpers/AppAccessorWithPartitionAsserts.cs | Adds partition key assertion accessor for app cache. |
| src/client/Microsoft.Identity.Client.TestOnly/AuthorityWithExpectedTenantId.cs | Adds authority/tenant test model into TestOnly package. |
| src/client/Microsoft.Identity.Client.TestOnly/.config/CredScanSuppressions.json | Adds CredScan suppression for placeholder credentials in PublicAPI files. |
| PerformanceTests.sln | Updates solution to include TestOnly project (and remove old Test.Common). |
| docs/cache_extensibility.md | Minor wording clarification (“capital” → “uppercase”). |
| build/template-pack-and-sign-all-nugets.yaml | Adds packing/signing step for Microsoft.Identity.Client.TestOnly. |
Comments suppressed due to low confidence (2)
src/client/Microsoft.Identity.Client.TestOnly/Helpers/CoreAssert.cs:143
- This helper uses reflection (Type.GetFields / BindingFlags) while living under /src. Repo guidelines discourage reflection in /src code; if this must remain, consider relocating it to the test projects instead of the packaged TestOnly library, or document/centralize the exception (and ensure it won't be used by production builds).
src/client/Microsoft.Identity.Client.TestOnly/LabInfra/LabResponseHelper.cs:160 - The XML doc says password caching is intentionally not implemented for security reasons, but the method immediately includes a TODO to implement caching. This is contradictory and makes intended behavior unclear. Either remove the TODO or update the doc comment to reflect the actual intended approach (e.g., allow in-memory caching for test runs with appropriate caveats).
You can also share your feedback on Copilot code review. Take the survey.
tests/Microsoft.Identity.Test.Unit/PublicApiTests/PublicClientApplicationTests.cs
Show resolved
Hide resolved
bgavrilMS
left a comment
There was a problem hiding this comment.
Let's try to reuse the lab API package?
src/client/Microsoft.Identity.Lab.Api/Internal/TestConstants.cs
Outdated
Show resolved
Hide resolved
…ithub.com/AzureAD/microsoft-authentication-library-for-dotnet into copilot/copy-reusable-test-infrastructure
Removed CredScanSuppressions.json from project file.
This pull request makes several updates to the solution and build configuration, primarily focused on removing MSAL specific test projects and introducing a new shared
Microsoft.Identity.Lab.Apiproject. This will enable higher level SDKs to use the shared test project for both Lab Infra and for unit test mocks.Project and Solution Structure Updates:
Microsoft.Identity.Test.LabInfrastructureandMicrosoft.Identity.Test.Commonprojects from theLibsAndSamples.slnsolution file, including their configuration and project mapping entries. [1] [2] [3]Microsoft.Identity.Lab.Apiproject to theLibsAndSamples.slnsolution file, including its build configurations and mapping. [1] [2] [3]PerformanceTests.slnsolution to replace theMicrosoft.Identity.Test.Commonproject withMicrosoft.Identity.Lab.Api, and adjusted related build configuration entries. [1] [2]Build and Packaging Configuration:
build/template-pack-and-sign-all-nugets.yaml) to sign and pack the newMicrosoft.Identity.Lab.Apiassembly.Internal Visibility and Documentation:
InternalsVisibleTo.csto grant access toMicrosoft.Identity.Lab.Apiinstead ofMicrosoft.Identity.Test.Common.docs/cache_extensibility.md.New Code Addition:
AuthorityWithExpectedTenantIdto theMicrosoft.Identity.Lab.Apiproject, providing a utility for authority URI and tenant ID testing.