FakePasskeys
Drop-in Passkeys for unit tests: real WebAuthn responses, no device.
Behaves like a platform implementation: operations fail with PasskeyError.NotSupported when the matching capability flag is off, signals validate and compare ids by their bytes, and the RP ID is checked against origin (see FakeAuthenticator).
Operations are safe to call from concurrent coroutines. The public mutable collections savedPasswords and receivedSignals are not synchronised: mutate or inspect them from test code before or after calls, not concurrently with them.
Logs like the platform implementations do, through com.alirezaiyan.passki.PassKi.logHandler, so a test can assert what your app's users would see in logcat. A test that changes PassKi.logLevel or PassKi.logHandler should restore them in @AfterTest: they are process-wide.
Parameters
the web origin written into clientDataJSON, e.g. https://example.com.
source for credential ids; pass a seeded Random for deterministic ids.
Samples
runTest {
val device = FakePasskeys(origin = "https://example.com") // your server's allowed origin
val created = device.register(TestOptions.creation("example.com")).getOrThrow()
// send created.json to your server's verifier here
val assertion = device.signIn(TestOptions.request("example.com")).getOrThrow()
assertEquals(created.credentialId, assertion.credentialId)
}Properties
The backing authenticator; inspect FakeAuthenticator.storedCredentials in assertions.
SignInMode.Autofill is available (PasskeyCapabilities.autofill). When false, signIn(mode = Autofill) fails with PasskeyError.NotSupported. Default true.
upgrade (conditional create) is available (PasskeyCapabilities.conditionalCreate). When false, it fails with PasskeyError.NotSupported. Default true.
SignInMode.ImmediateOnly is available (PasskeyCapabilities.immediateSignIn). When false, signIn(mode = ImmediateOnly) fails with PasskeyError.NotSupported. Default true.
Passkeys can be used at all (PasskeyCapabilities.isSupported). When false, every operation fails with PasskeyError.NotSupported and capabilities reports every capability as false. Default true.
Every signal received through signals, in call order (only signals that passed validation). Inspect from test code before/after calls, not concurrently with them.
Username → password offered by signInOrPassword when no passkey matches. Mutate from test code before/after calls, not concurrently with them.
signals are available (PasskeyCapabilities.signals). When false, every signal returns SignalOutcome.Skipped and is not recorded, as on a device without the Signal API. Default true.
signInOrPassword is available (PasskeyCapabilities.unifiedPasswordSignIn). When false, it fails with PasskeyError.NotSupported. Default true.
Functions
The next operation fails with error; later ones behave normally. Calls queue up in order. A queued error takes precedence over the capability flags. Call from test code before/after operations, not concurrently with them.