Skip to content

Generate test certificates at runtime#67325

Open
BrennanConroy wants to merge 2 commits into
mainfrom
brennanconroy/generate-test-certs
Open

Generate test certificates at runtime#67325
BrennanConroy wants to merge 2 commits into
mainfrom
brennanconroy/generate-test-certs

Conversation

@BrennanConroy

Copy link
Copy Markdown
Member

Some tests relied on checked-in PFX and CER files that can expire and break future test runs. This replaces those expiring binaries with runtime-generated certificates while preserving the certificate shapes that the tests exercise.

Summary

  • Add a shared TestCertificateFactory for generating RSA, ECDSA, EKU-specific, ASP.NET Core dev-cert, and public-key-only test certificates.
  • Update shared Kestrel/HttpSys resources, DataProtection tests, SignalR tests, Autobahn, and Negotiate tests to generate certificates at runtime.
  • Remove the affected checked-in certificate files plus stale content globs and CredScan suppressions.

Validation

  • restore.cmd
  • Targeted DataProtection certificate tests
  • Targeted Kestrel HTTPS configuration and certificate tests
  • Autobahn, Negotiate, SignalR, Kestrel, and HttpSys project builds for projects that link the shared factory
  • git diff --check

Copilot AI review requested due to automatic review settings June 19, 2026 19:58
@BrennanConroy BrennanConroy requested review from a team, halter73 and wtgodbe as code owners June 19, 2026 19:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR removes reliance on checked-in, expiring certificate binaries in tests by introducing a shared runtime certificate generator and updating multiple test/samples to consume generated certificates (either in-memory or via on-demand PFX materialization through TestResources).

Changes:

  • Added TestCertificateFactory to generate RSA/ECDSA/EKU/dev-cert/public-key-only certificates at runtime.
  • Updated SignalR, Kestrel, HttpSys, DataProtection, Autobahn, and Negotiate tests/apps to use generated certificates instead of checked-in .pfx content.
  • Cleaned up removed certificate content globs and associated CredScan suppressions.
Show a summary per file
File Description
src/SignalR/common/Shared/TestCertificates.cs Switch SignalR shared test cert loading from PFX files to runtime-generated RSA/ECDSA certs.
src/SignalR/clients/ts/FunctionalTests/SignalR.Client.FunctionalTestApp.csproj Link in TestCertificateFactory and stop copying shared .pfx content.
src/SignalR/clients/csharp/Client/test/FunctionalTests/Microsoft.AspNetCore.SignalR.Client.FunctionalTests.csproj Link in TestCertificateFactory and stop copying shared .pfx content.
src/Shared/TestResources.cs Generate specific shared test PFX files on-demand when callers request known cert names.
src/Shared/TestCertificateFactory.cs New shared certificate generation utilities used across tests/projects.
src/Servers/Kestrel/Transport.Quic/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.Tests.csproj Link in TestCertificateFactory and remove .pfx content copy.
src/Servers/Kestrel/Transport.NamedPipes/test/Microsoft.AspNetCore.Server.Kestrel.Transport.NamedPipes.Tests.csproj Link in TestCertificateFactory and remove .pfx content copy.
src/Servers/Kestrel/test/Sockets.FunctionalTests/Sockets.FunctionalTests.csproj Link in TestCertificateFactory and remove .pfx content copy.
src/Servers/Kestrel/test/Sockets.BindTests/Sockets.BindTests.csproj Link in TestCertificateFactory and remove .pfx content copy.
src/Servers/Kestrel/test/Interop.FunctionalTests/Interop.FunctionalTests.csproj Link in TestCertificateFactory and remove .pfx content copy.
src/Servers/Kestrel/test/Interop.FunctionalTests/Http3/Http3TlsTests.cs Use TestResources.GetCertPath(...) to ensure dev-cert PFX exists at runtime.
src/Servers/Kestrel/test/InMemory.FunctionalTests/InMemory.FunctionalTests.csproj Link in TestCertificateFactory and remove .pfx content copy.
src/Servers/Kestrel/samples/HttpClientApp/HttpClientApp.csproj Link in TestCertificateFactory and remove .pfx content copy for sample usage.
src/Servers/Kestrel/Kestrel/test/Microsoft.AspNetCore.Server.Kestrel.Tests.csproj Link in TestCertificateFactory and remove .pfx content copy.
src/Servers/Kestrel/Kestrel/test/HttpsConfigurationTests.cs Replace direct PFX file loads with TestResources helpers for runtime generation.
src/Servers/Kestrel/Core/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj Link in TestCertificateFactory and remove .pfx content copy.
src/Servers/HttpSys/test/FunctionalTests/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests.csproj Link in TestCertificateFactory and remove .pfx content copy.
src/Security/Authentication/Negotiate/test/Negotiate.FunctionalTest/NegotiateHandlerFunctionalTests.cs Generate the Negotiate HTTPS cert at runtime and use its path.
src/Security/Authentication/Negotiate/test/Negotiate.FunctionalTest/Microsoft.AspNetCore.Authentication.Negotiate.FunctionalTest.csproj Link in TestCertificateFactory and stop copying the checked-in PFX.
src/Middleware/WebSockets/test/ConformanceTests/AutobahnTestApp/Program.cs Ensure the Autobahn SSL cert exists by generating it at startup.
src/Middleware/WebSockets/test/ConformanceTests/AutobahnTestApp/AutobahnTestApp.csproj Link in TestCertificateFactory and stop copying the checked-in PFX.
src/DefaultBuilder/test/Microsoft.AspNetCore.FunctionalTests/Microsoft.AspNetCore.FunctionalTests.csproj Remove copying a checked-in test cert PFX (now unused).
src/DataProtection/Extensions/test/Microsoft.AspNetCore.DataProtection.Extensions.Tests.csproj Link in TestCertificateFactory and stop copying removed TestFiles content.
src/DataProtection/Extensions/test/DataProtectionProviderTests.cs Replace file-based certificate dependencies with runtime-generated certs.
src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/XmlEncryption/EncryptedXmlDecryptorTests.cs Replace file-based certs with runtime-generated certs for encryption/decryption tests.
src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Microsoft.AspNetCore.DataProtection.Tests.csproj Link in TestCertificateFactory and stop copying removed TestFiles content.
.config/CredScanSuppressions.json Remove suppressions for deleted certificate binaries.

Copilot's findings

  • Files reviewed: 27/47 changed files
  • Comments generated: 1

Comment thread src/Shared/TestCertificateFactory.cs
Replace checked-in test certificates with runtime-generated equivalents so test cert expiration is controlled by test code. Add shared certificate generation helpers, including server certificate helpers that avoid ephemeral private keys on Windows where SslStream cannot use them.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@BrennanConroy BrennanConroy force-pushed the brennanconroy/generate-test-certs branch from 3c1f7ca to e2603ab Compare June 25, 2026 18:39
Avoid contending on the Windows PFX import mutex while generating shared test certificate files, and use a non-ephemeral import for certificates that are added to the Windows certificate store.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

2 participants