Repository navigation
fix(tracker-core): [#3051] return an error when a random key duration overflows the clock - #3064
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
…he random key duration overflow Four tests fail for the reported bug: a KeysHandler test, a generate_auth_key_handler test and two REST contract tests. The red runs are recorded in the evidence file (V2b). No production change yet. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…uration overflows the clock key::generate_key returns Result<PeerKey, key::DurationOverflow> instead of unwrapping the clock addition, so an overflowing seconds_valid no longer panics. KeysHandler::generate_expiring_peer_key and the pub(crate) generate_permanent_peer_key return PeerKeyError, with a From conversion from DurationOverflow. The REST generate-key adapter reuses map_peer_key_error and generate_auth_key_handler answers 400 for an overflow, like the add-key endpoint. Breaking public API (allowed before tracker-core 4.0.0): generate_key and generate_expiring_peer_key change their return type. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…r recheck Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…idence Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…e_key returning a Result The tests added by torrust#3056 call generate_key, whose return type changes in this branch. The evidence notes the rerun after the rebase. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
40a1ae0 to
ff5ae2c
Compare
|
ACK ff5ae2c |
da2ce7
left a comment
There was a problem hiding this comment.
Reviewed at ff5ae2c4ca9235296774fe47e9abdf25b3752cb0. Recomputed from the bytes at this head, against the merge base 082ad2452; git merge-tree against develop a94c3ced8 writes a clean tree: develop gained only documentation and agent-tooling changes since the merge base, none in a file this change touches.
Process: a bug fix, governed by fix-bug (red then green regression tests, a real-tracker recheck after the last production change, commits cited by subject), write-unit-test (test-design-review.md) and commit-changes with open-pull-request. The spec from #3054 is an ancestor of the merge base.
The change against its claim: generate_key returns Result<PeerKey, DurationOverflow> instead of unwrapping now_add; generate_expiring_peer_key and generate_permanent_peer_key return PeerKeyError, with database failures mapped as before; the adapter's generate path reuses map_peer_key_error, whose Database text is unchanged; the deprecated handler answers the add endpoint's 400 body. Every caller in the workspace is updated or already unwraps. Recomputed: the merge-base panic site is key/mod.rs:111:79, the unwrap(); the control key's valid_until 1795637631 is 19:13:51 UTC plus 3600 s; the changes from #3056 sit in test modules only, so the claim that the rebase left the production code unchanged holds. With the fix reverted, the contract tests and the handler test fail.
Consistency: no links added; the in-folder issue-spec keys match the clarification now on develop; no dictionary words added; nothing moved or renamed.
Hygiene: Conventional subjects carry [#3051]; author equals committer on all five commits; git diff --check is clean; the commit-id check prints nothing; only the body's Closes #3051 matches the closing-keyword pattern. Each commit carries an AI attribution footer; no rule in the tree forbids it.
Findings
- Minor: the tracker-core tests do not compile at 0e44bc9, 085687e or 5c2100e; ff5ae2c repairs them.
- Minor: the new overflow tests depend on the stopped clock's default not being the epoch.
- Nit: the doc comment of
generate_auth_key_handlerstill lists only200and500.
Checked, no finding: DurationOverflow's message equals PeerKeyError::DurationOverflow's; the doctest overflows under the working clock; the benchmark callers; the renamed handler test; the spec checkboxes and AC table against the evidence; frontmatter.
Checks
On the loop's compute node at this head, against the merge base 082ad2452: the repository's pre-commit gate and lint roster exit 0; cargo test --workspace passes 4860 tests with 0 failed and 5 ignored across 140 binaries with default features; and cargo clippy --workspace --all-targets --all-features -- -D warnings exits 0 (2026-11-26). Checked against the bytes at posting: the doc comment of generate_auth_key_handler (lines 53 to 58) still lists only the 200 and 500 responses. The head was confirmed with git ls-remote before posting. GitHub checks at this head at posting time: "Publish (Development): completed/skipped; Publish (Release): completed/skipped; Context: completed/success; Package Coverage Regression: completed/success; Package Coverage (torrust-tracker-persistence-benchmark): completed/success; Package Coverage (torrust-tracker-http-core): completed/success; Package Coverage (torrust-tracker-core): completed/success; Package Coverage (torrust-tracker-rest-api-runtime-adapter): completed/success; Package Coverage (torrust-tracker-axum-rest-api-server): completed/success; Docker E2E: completed/skipped; Layer Boundary Bans: completed/success; Source Locations: completed/success; Unit (nightly): completed/success; Unit (stable): completed/success; Documented Clippy Allows: completed/success; Workspace Packaging: completed/success; Shipped Features: completed/success; Docs Lint: completed/success; Build on macos-latest (stable): completed/success; Build on ubuntu-latest (nightly): completed/success; Build on windows-latest (nightly): completed/success; Build on windows-latest (stable): completed/success; Build on ubuntu-latest (stable): completed/success; Build on macos-latest (nightly): completed/success; Test (Docker) (release): completed/success; Database Compatibility PostgreSQL (16): completed/success; Database Compatibility PostgreSQL (14): completed/success; Database Compatibility MySQL (8.0): completed/success; Database Compatibility PostgreSQL (15): completed/success; Database Compatibility PostgreSQL (17): completed/success; Database Compatibility MySQL (8.4): completed/success; Persistence Benchmark PostgreSQL: completed/success; Persistence Benchmark MySQL: completed/success; Persistence Benchmark SQLite3: completed/success; Generate Coverage Report: completed/success; Discover Package Coverage: completed/success; CodeRabbit: completed/success". At posting, develop is b32179f23.
| async fn it_should_keep_the_key_in_memory_when_removing_it_from_the_database_fails() { | ||
| // Arrange | ||
| let peer_key = generate_key(None); | ||
| let peer_key = generate_key(None).unwrap(); |
There was a problem hiding this comment.
[Minor] The tracker-core tests do not compile at three commits of this branch.
0e44bc9 changes generate_key to return a Result. The tests that #3056 added still bind its value as a PeerKey at 0e44bc9, 085687e and 5c2100e: here, at lines 850, 880 and 881, and at key/mod.rs lines 419 and 456. This commit repairs them. AGENTS.md requires linter all to pass before every commit, and the merge keeps the branch's commits, so a bisect on develop would stop on a build error at those three commits. Moving the caller update into the fix commit during the rebase that brought in #3056 keeps every change and leaves each commit buildable. If the history stays as it is, a line in the PR body saying so would help a later reader.
|
|
||
| #[test] | ||
| fn it_should_return_an_error_with_the_requested_seconds_instead_of_panicking() { | ||
| let result = generate_key(Some(Duration::from_secs(u64::MAX))); |
There was a problem hiding this comment.
[Minor] This test arranges no clock, yet the overflow it asserts depends on the clock.
u64::MAX seconds overflow only when the current time is past the epoch: Duration::ZERO plus Duration::from_secs(u64::MAX) fits, so at a zero clock generate_key returns Ok and unwrap_err panics. The test passes because the stopped clock's default in this crate's tests is not the epoch, as the recorded red run's panic at now_add shows. The write-unit-test skill states that Stopped::now() defaults to Duration::ZERO, so a reader following it would expect this test to fail. The same holds for the new KeysHandler test at handler.rs:418, which at a zero clock would reach the store instead. test-design-review.md:15 calls u64::MAX seconds a lifetime "which no clock can add", but a clock at the epoch can. Pinning the clock first, as it_should_generate_a_key_that_expires_at_now_plus_its_lifetime does with clock::Stopped::local_set(&Duration::from_secs(1_000)), makes the causal state visible and the test independent of the default.
| }; | ||
| match auth_key_service.generate_key(seconds_valid).await { | ||
| Ok(auth_key) => auth_key_response(&auth_key), | ||
| Err(AuthKeyError::DurationOverflow { seconds_valid }) => invalid_auth_key_duration_response(seconds_valid), |
There was a problem hiding this comment.
[Nit] The doc comment of generate_auth_key_handler no longer lists every response.
With this arm the deprecated endpoint answers 400 for an overflowing duration, but the comment (lines 53 to 58) still says it returns two types of responses, 200 and 500. The 400 for a segment that is not a number was already missing. Listing the 400 cases, as the comment of add_auth_key_handler does, would keep it accurate.
|
ACK ff5ae2c — verified that a random key whose duration overflows the clock now returns DurationOverflow and a 400 on both REST endpoints, with every caller updated and the merge into develop clean. |
…ssues/closed 0ac4829 docs(pr-reviews): [#3051] record the replies to review 6079505913 in the PR 3072 audit (josecelano-bot) 70a3f89 docs(pr-reviews): [#3051] record review 6079505913 in the PR 3072 audit (josecelano-bot) 0196ad3 docs(pr-reviews): [#3051] record the replies to review 6078748782 in the PR 3072 audit (josecelano-bot) 828414b docs(pr-reviews): [#3051] record review 6078748782 in the PR 3072 audit (josecelano-bot) 4a84d47 docs(issues): [#3051] leave the remaining criteria for a reviewer to tick (josecelano-bot) 9a1b9aa docs(pr-reviews): [#3051] record the replies to review 6077711472 in the PR 3072 audit (josecelano-bot) ac62b23 docs(pr-reviews): [#3051] record review 6077711472 in the PR 3072 audit (josecelano-bot) 157aff7 docs(issues): [#3051] leave the acceptance criteria for a reviewer to tick (josecelano-bot) 119ee6b docs(pr-reviews): [#3051] record the replies to review 6075748165 in the PR 3072 audit (josecelano-bot) 65f43b0 docs(pr-reviews): [#3051] add the PR 3072 review audit (josecelano-bot) eb5671e docs(issues): [#3051] make the archived spec agree with its record (josecelano-bot) 6a6fbb9 chore(issues): archive closed issue #3051 spec to docs/issues/closed (josecelano-bot) Pull request description: Related to #3051 ## Summary Archives the spec of issue #3051, which is closed: its spec PR (#3054) and fix PR (#3064) are merged. The folder moves from `docs/issues/open/` to `docs/issues/closed/` as the `cleanup-completed-issues` skill describes. The ISSUE.md frontmatter now has `status: done`, the new `spec-path` and `related-pr: 3064`; the checkpoints the merged work satisfies are ticked and the progress log records the archival. The branch also carries the audit record of the reviews of this pull request. ## Files - `docs/issues/closed/3051-random-expiring-key-duration-overflow-panic/` (moved from `open/`: `ISSUE.md`, `manual-verification-evidence.md`, `test-design-review.md`, `evidence/`). - `docs/pr-reviews/pr-3072-review/PR-REVIEW.md` (the audit record of the reviews of this pull request). ## Validation `linter markdown` and `linter cspell` pass, `git diff --cached --check` is clean, and a search for the folder name finds no live reference to the old path (the PR 3054 audit record keeps the path that existed at the time). No code is changed. The checkpoint "Reviewer validated acceptance criteria" is left unticked on purpose. ACKs for top commit: da2ce7: ACK 0ac4829 — the #3051 spec archived to docs/issues/closed with its references repaired, and an audit record that answers every review finding and passes its validator josecelano: ACK 0ac4829 Tree-SHA512: a8367619601e0db1162b6b85c85d92535fd90bd10b26623abee55aee6f7cd71c2abffa2a701846d7769e9d4d0f9a3b035b8bb71c9fa1766cf01a2b43b3f8ba2c
Closes #3051
Summary
Creating a random expiring authentication key with a
seconds_validthat overflows the clock no longer panics.key::generate_keyreturned the key and unwrapped the clock addition, soPOST /api/v1/keys(random key) andPOST /api/v1/key/{seconds}with18446744073709551615dropped the connection and logged a panic atkey/mod.rs:111. They now answer400"invalid auth key duration", as the pre-generated key path already did. The design is the one the maintainer decided on the spec PR (#3054): fix at the seam, with a dedicatedkey::DurationOverflowtype converted intoPeerKeyError::DurationOverflow.Breaking public API change (
torrust-tracker-core, allowed before 4.0.0)authentication::key::generate_key(lifetime) -> Result<PeerKey, key::DurationOverflow>(wasPeerKey).KeysHandler::generate_expiring_peer_key(lifetime) -> Result<PeerKey, PeerKeyError>(wasResult<PeerKey, databases::error::Error>); thepub(crate)generate_permanent_peer_keychanges the same way.key::DurationOverflow { seconds_valid: u64 }andimpl From<DurationOverflow> for PeerKeyError.All callers in the workspace are updated:
tracker-core,http-coretests, the REST adapter, the REST handler and the persistence benchmark binary.Files
packages/tracker-core/src/authentication/key/mod.rs,handler.rsanderror.rs: the fix and its unit tests.packages/rest-api-runtime-adapter/src/v1/adapters/auth_key.rs: the generate-key adapter reusesmap_peer_key_error.packages/axum-rest-api-server/src/v1/context/auth_key/handlers.rsand its contract tests: aDurationOverflowarm ingenerate_auth_key_handler; the existing test of the other errors is renamed.packages/http-core(tests) andpackages/persistence-benchmark: callers.docs/issues/open/3051-random-expiring-key-duration-overflow-panic/: spec progress,manual-verification-evidence.md(red before the fix, green after, real-tracker recheck) andtest-design-review.md.Validation
generate_keyunit test fails when the oldunwrap()is restored.linter allexits0; the tests oftracker-core,axum-rest-api-server,http-core,axum-http-server,rest-api-runtime-adapterandpersistence-benchmarkpass, and so do the workspace doc tests.400instead of an empty reply, the control answers200, and the log holds no panic.i64::MAXseconds that still fits the clock returns a500from the stores, tracked in Key duration above i64::MAX seconds returns 500 instead of a duration error #3055;PeerKeyErroris not split or renamed.Summary by CodeRabbit
Bug Fixes
Tests