Skip to content

Add test hook to PopKeyAttestor for MSI v2 attestation tests#5694

Merged
gladjohn merged 5 commits intomainfrom
copilot/add-test-hook-popkeyattestor
Feb 6, 2026
Merged

Add test hook to PopKeyAttestor for MSI v2 attestation tests#5694
gladjohn merged 5 commits intomainfrom
copilot/add-test-hook-popkeyattestor

Conversation

Copy link
Contributor

Copilot AI commented Jan 31, 2026

Changes proposed in this request

Unit tests calling .WithAttestationSupport() fail because PopKeyAttestor.AttestCredentialGuardAsync() loads AttestationClientLib.dll, which throws TaskCanceledException in test environments and makes network calls that bypass MockHttpManager.

Solution: Test hook pattern to inject mock attestation provider.

Core changes:

  • PopKeyAttestor.cs: Added s_testAttestationProvider static field checked before native DLL loading
  • TestAttestationProviders.cs: Replaced unused CreateFakeProvider() with CreateFakeAttestationResultProvider() returning AttestationResult
  • ImdsV2Tests.cs: Inject mock in TestInitialize, reset in TestCleanup
// In PopKeyAttestor.AttestCredentialGuardAsync()
if (s_testAttestationProvider != null)
{
    return s_testAttestationProvider(endpoint, keyHandle, clientId, cancellationToken);
}
// Otherwise proceed with native DLL...

All 27+ existing test calls to .WithAttestationSupport() now bypass native DLL without modification.

Testing

Test infrastructure updated. Existing unit tests in ImdsV2Tests now use the mock provider automatically. No new tests added—fix enables existing tests to run.

Performance impact

None. Production code path unchanged. Test-only hook accessed via InternalsVisibleTo.

Documentation

  • All relevant documentation is updated.

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits January 31, 2026 14:57
- Add s_testAttestationOverride static field in PopKeyAttestor.cs
- Update AttestCredentialGuardAsync to check test override before loading native DLL
- Update TestAttestationProviders.cs to add CreateFakeAttestationResultProvider
- Update ImdsV2Tests to inject and cleanup test override

Co-authored-by: gladjohn <90415114+gladjohn@users.noreply.github.com>
- Add documentation about InternalsVisibleTo and thread-safety concerns
- Remove trailing whitespace in test cleanup method

Co-authored-by: gladjohn <90415114+gladjohn@users.noreply.github.com>
Copilot AI changed the title [WIP] Add test hook in PopKeyAttestor for mocking attestation Add test hook to PopKeyAttestor for MSI v2 attestation tests Jan 31, 2026
Copilot AI requested a review from gladjohn January 31, 2026 15:02
@gladjohn gladjohn marked this pull request as ready for review January 31, 2026 15:15
@gladjohn gladjohn requested a review from a team as a code owner January 31, 2026 15:15
Copy link
Member

@bgavrilMS bgavrilMS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too much test code in the product code for 1 trivial test.

Address feedback from @bgavrilMS to improve naming consistency

Co-authored-by: gladjohn <90415114+gladjohn@users.noreply.github.com>
@gladjohn gladjohn merged commit 984ad24 into main Feb 6, 2026
11 checks passed
@gladjohn gladjohn deleted the copilot/add-test-hook-popkeyattestor branch February 6, 2026 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants