digidem / digidem/comapeo-core-react-native

iOS: test the locked-keychain path in RootKeyStore

Open
#40 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area: ios priority: P2 testing
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 = kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly on a simulator without a passcode, but the resulting error is errSecAuthFailed, not errSecInteractionNotAllowed.
  • The cleanest approach is probably a small protocol-based mock injected at RootKeyStore construction (e.g. a KeychainAccessor typealias), with the production path going through the real SecItem* 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

  • RootKeyStore accepts 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.