digidem / digidem/comapeo-core-react-native
iOS: test the locked-keychain path in RootKeyStore
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 1
- Forks
- 0
- Avg merge
- 8h 24m
- Merged PRs (30d)
- 9
Description
Context
PR #36 added RootKeyStore.swift which throws RootKeyError.interactionNotAllowed when SecItemCopyMatching returns errSecInteractionNotAllowed — the case where the device has been booted but never unlocked since.
The XCTest suite added in PR #36 covers round-trip and wrong-length, but not the locked-keychain path. That branch is reachable in production (cold reboot, app launches via background trigger before user has unlocked once) and has its own native ERROR transition (phase: "rootkey"), so it's worth pinning down with a test.
Why deferred
Simulating errSecInteractionNotAllowed in XCTest is fiddly:
- The simulator's keychain is always "unlocked" once the simulator has booted. There's no public API to lock it.
- One workaround is creating an item with
kSecAttrAccessible = kSecAttrAccessibleWhenPasscodeSetThisDeviceOnlyon a simulator without a passcode, but the resulting error iserrSecAuthFailed, noterrSecInteractionNotAllowed. - The cleanest approach is probably a small protocol-based mock injected at
RootKeyStoreconstruction (e.g. aKeychainAccessortypealias), with the production path going through the realSecItem*functions and the test using a fake that returns the desired OSStatus.
That refactor is a couple of hundred lines and changes the public API of RootKeyStore. PR #36 review explicitly deferred it.
Acceptance
-
RootKeyStoreaccepts a keychain-accessor seam (protocol or closure) for tests. - XCTest covers: load returns nil + locked → throws
.interactionNotAllowed. - XCTest covers: store while locked → throws
.interactionNotAllowed. - Production callers continue to use the real Keychain by default (no behaviour change).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with RootKeyStore.swift and the XCTest suite added in PR #36, then review the production SecItem* path and RootKeyStore construction. Add the test seam without changing the default Keychain behavior, and cover locked load and store cases returning .interactionNotAllowed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- mobile-dev, testing
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100