test(kas): fix stale unwrapKey HKDF salt round-trip test#40
Conversation
testKeyUnwrappingWithValidKeys sealed the wrapped key with an empty HKDF salt (the Standard TDF convention) but called unwrapKey() with no salt arg, which since 0ee0797 defaults to CryptoConstants.hkdfSalt (the NanoTDF v12 session-key salt). The salt mismatch produced different AES-GCM keys, so tag verification failed with authenticationFailure — a stale test, not a product bug (unwrapKey's default matches the real KAS rewrap_dek derivation). Replace the single ambiguous test with a DRY helper and two explicit, self-consistent round-trips: - testKeyUnwrappingNanoTDFDefaultSalt: seal+unwrap with the v12 default salt - testKeyUnwrappingStandardTDFEmptySalt: seal+unwrap with empty salt Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
CI failed: The CI build failed due to numerous SwiftFormat linting violations, primarily related to the use of force unwrapping in tests and improper code formatting.OverviewThe build failed because the codebase does not currently adhere to the required Swift style guidelines. SwiftFormat identified multiple violations across 28 files, including common anti-patterns like force unwrapping in test files and incorrect keyword placement. FailuresSwiftFormat Linting Violations (confidence: high)
Summary
Code Review ✅ ApprovedRefactors the stale KAS unwrapKey test into a DRY helper covering both NanoTDF and Standard TDF salt conventions, while adding safety checks to decoding logic. No issues found.
Tip Comment OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change:
Important Your trial ends in 4 days — upgrade now to keep code review, CI analysis, auto-apply, custom automations, and more. Was this helpful? React with 👍 / 👎 | Gitar |
|
Superseded by #39, which now includes this exact fix (cherry-picked commit) plus the repo-wide lint fix, per the maintainer's request to combine. Closing to avoid a merge conflict on the shared test file. |
Summary
Fixes the long-failing
KASRewrapClientTests.testKeyUnwrappingWithValidKeys(authenticationFailure).Root cause — a stale test, not a product bug. The test sealed the wrapped key with an empty HKDF salt (the Standard/Base TDF convention) but called
unwrapKey()with no salt argument, which since commit0ee0797defaults toCryptoConstants.hkdfSalt(the NanoTDF v12 session-key salt). Mismatched salts → different AES-GCM keys → GCM tag verification fails withauthenticationFailure.unwrapKey's default is correct (it matches the real KASrewrap_dekderivation, and the NanoTDF round-trip is exercised byKASServiceTests); the test was simply never updated when the salt default changed.No network involved — this is a purely local ECDH → HKDF → AES-GCM round-trip.
Change
Replaced the single ambiguous test with a DRY helper (
assertUnwrapRoundTrip(sealSalt:unwrapSalt:)) and two explicit, self-consistent tests covering both documented salt conventions:testKeyUnwrappingNanoTDFDefaultSalt— seal + unwrap with the v12 default salt (salt: nil)testKeyUnwrappingStandardTDFEmptySalt— seal + unwrap with an empty saltTest Plan
swift test— 181 tests, 8 skipped, 0 failures (verified across repeated runs)🤖 Generated with Claude Code
Summary by Gitar
XCTUnwrapto severalJSONSerializationand data decoding calls inKASRewrapClientTeststo prevent forced-unwrap crashes.testRewrapRequestEntryWithDefaultAlgorithmto avoid unnecessary error handling throws.This will update automatically on new commits.