Skip to content

Add unit tests for pruneExpiredKeys() fallback when SYMMETRIC_KEY_MAX_AGE_DAYS returns 0 or negative#3054

Merged
fadidurah merged 2 commits into
fadi/secret-key-rotationfrom
copilot/sub-pr-3048
Mar 24, 2026
Merged

Add unit tests for pruneExpiredKeys() fallback when SYMMETRIC_KEY_MAX_AGE_DAYS returns 0 or negative#3054
fadidurah merged 2 commits into
fadi/secret-key-rotationfrom
copilot/sub-pr-3048

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 24, 2026

The pruneExpiredKeys() fallback path for invalid ECS values (maxAgeDays <= 0) had no test coverage, meaning regressions (e.g., pruning all keys when the flight returns 0) would go unnoticed.

Changes

  • Two new tests in KeyVersionRegistryTest:

    • pruneExpiredKeys_usesDefaultWhenFlightReturnsZero — asserts a recently-created key survives when the flight returns 0
    • pruneExpiredKeys_usesDefaultWhenFlightReturnsNegative — same for -1
  • buildFlightsManagerWithMaxAgeDays(int) helper — concrete IFlightsManager/IFlightsProvider implementation that returns the specified value for SYMMETRIC_KEY_MAX_AGE_DAYS and each flight's own default otherwise; injected via CommonFlightsManager.INSTANCE.initializeCommonFlightsManager(...)

  • tearDown() now calls CommonFlightsManager.INSTANCE.resetFlightsManager() to prevent test pollution

@Test
public void pruneExpiredKeys_usesDefaultWhenFlightReturnsZero() throws ClientException {
    registry.generateNewKey();
    CommonFlightsManager.INSTANCE.initializeCommonFlightsManager(buildFlightsManagerWithMaxAgeDays(0));
    registry.pruneExpiredKeys();
    assertNotNull("Key should not be pruned when flight returns 0; default should be used",
            registry.getKeyByVersion("K001"));
}

💡 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.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 24, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • www.puppycrawl.com
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.24.3/x64/codeql/tools/linux64/java/bin/java /opt/hostedtoolcache/CodeQL/2.24.3/x64/codeql/tools/linux64/java/bin/java -jar /opt/hostedtoolcache/CodeQL/2.24.3/x64/codeql/xml/tools/xml-extractor.jar --fileList=/tmp/codeql-scratch-b2678d0398b00160/dbs/java/working/files-to-index12340156876576948957.list --sourceArchiveDir=/tmp/codeql-scratch-b2678d0398b00160/dbs/java/src --outputDir=/tmp/codeql-scratch-b2678d0398b00160/dbs/java/trap/java (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] [WIP] Address feedback on Broker Secret Key Rotation PR Add unit tests for pruneExpiredKeys() fallback when SYMMETRIC_KEY_MAX_AGE_DAYS returns 0 or negative Mar 24, 2026
Copilot AI requested a review from fadidurah March 24, 2026 20:17
@fadidurah fadidurah marked this pull request as ready for review March 24, 2026 21:49
@fadidurah fadidurah requested a review from a team as a code owner March 24, 2026 21:49
@fadidurah fadidurah merged commit b07ef7d into fadi/secret-key-rotation Mar 24, 2026
7 of 16 checks passed
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