You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improves test quality by re-enabling a previously disabled test, adding negative parser coverage, cleaning up debug prints, moving shared test helpers, and adding an offline mock-KAS rewrap test.
Changes
Re-enabled testVerifyPolicyBinding in KASServiceTests.swift and fixed it to pass the serialized embedded policy body.
Added BinaryParserTests.swift with negative tests for invalid magic numbers, unsupported versions, truncated headers, and malformed resource locators.
Replaced debug print calls in unit tests with meaningful assertions in:
NanoTDFTests.swift
NanoTDFCreationTests.swift
InitializationTests.swift
KeyStoreTests.swift
Moved CryptoHelper test helpers from CryptoHelperTests.swift to a new Helpers/CryptoHelper+TestHelpers.swift file.
Added offline mock-KAS rewrap test (testRewrapKeyMockResponse) using MockURLProtocol.
Fixed a GMAC binding bug discovered while re-enabling the policy-binding test: createGMACBinding and verifyPolicyBinding now use a deterministic zero nonce so bindings can be reproduced and verified.
Fixed KASServiceBenchmarkTests to use the same deterministic binding for the policy-binding benchmark and assert validity before measuring.
Verification
swift test: 227 tests, 0 failures
swiftformat --swiftversion 6.2 .: clean
Related
Part of the test-quality quick-wins identified in recent review feedback.
Enhances test suite reliability by re-enabling policy binding tests, improving negative parser coverage, and replacing debug statements with assertions. The previously identified tautological assertions and GMAC nonce issues have been resolved.
✅ 2 resolved✅ Quality: Tautological assertion compares header.toData() to itself
📄 OpenTDFKitTests/NanoTDFCreationTests.swift:35
In NanoTDFCreationTests.swift:35, XCTAssertEqual(header.toData(), header.toData(), "Header should serialize consistently") compares a value against itself, so it can never fail and verifies nothing. The apparent intent was to confirm the parsed header re-serializes to the same bytes as the original. Capture the original serialized header before parsing and compare against that, or rely on the existing full round-trip assertion at line 38 and remove this line.
✅ Security: Fixed zero nonce in createGMACBinding relies on per-message key uniqueness
📄 OpenTDFKit/CryptoHelper.swift:220-227 createGMACBinding (CryptoHelper.swift:223-224) now seals with a deterministic all-zero AES-GCM nonce, and the same symmetric key is also used to encrypt the payload via encryptPayload with a separately generated nonce (confirmed in NanoTDFCollectionBuilder). This change is necessary for reproducible/verifiable bindings and is safe as long as each NanoTDF derives a unique symmetric key (from a fresh ephemeral ECDH key) and the random payload nonce never collides with the zero nonce under the same key. AES-GCM nonce reuse under a shared key is catastrophic (authentication-key recovery / forgery), so this invariant must be preserved. Recommend adding a code comment documenting this assumption and ensuring ephemeral key pairs are never reused across NanoTDFs, so a future refactor (e.g., key caching) cannot silently reuse a key with both the zero GMAC nonce and a colliding payload nonce.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Improves test quality by re-enabling a previously disabled test, adding negative parser coverage, cleaning up debug prints, moving shared test helpers, and adding an offline mock-KAS rewrap test.
Changes
testVerifyPolicyBindinginKASServiceTests.swiftand fixed it to pass the serialized embedded policy body.BinaryParserTests.swiftwith negative tests for invalid magic numbers, unsupported versions, truncated headers, and malformed resource locators.printcalls in unit tests with meaningful assertions in:NanoTDFTests.swiftNanoTDFCreationTests.swiftInitializationTests.swiftKeyStoreTests.swiftCryptoHelperTests.swiftto a newHelpers/CryptoHelper+TestHelpers.swiftfile.testRewrapKeyMockResponse) usingMockURLProtocol.createGMACBindingandverifyPolicyBindingnow use a deterministic zero nonce so bindings can be reproduced and verified.KASServiceBenchmarkTeststo use the same deterministic binding for the policy-binding benchmark and assert validity before measuring.Verification
swift test: 227 tests, 0 failuresswiftformat --swiftversion 6.2 .: cleanRelated
Part of the test-quality quick-wins identified in recent review feedback.