Added the catalogue models and seed to support phase 4 of the POC prototype in the Persistence package.
This commit is contained in:
1 parent
0dc3fe6bea
commit
95e0a455e8
14 files changed
+743
-9
No files matched your search
@@ -33,3 +33,61 @@ struct AccountRepositoryTests {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Passkeys
|
||||
|
||||
extension AccountRepositoryTests {
|
||||
|
||||
@Test
|
||||
func `joins an account together with its first passkey`() async throws {
|
||||
try await withDatabase { fluent in
|
||||
let accounts = AccountRepository(fluent: fluent)
|
||||
let free = try await accounts.isUnregistered(credentialID: "cred-1")
|
||||
let sam = try #require(try await accounts.join(email: "sam@example.com", credentialID: "cred-1", publicKey: [1, 2, 3], signCount: 0))
|
||||
let passkey = try await accounts.passkey(credentialID: "cred-1")
|
||||
let byEmail = try await accounts.passkeys(email: "sam@example.com")
|
||||
let taken = try await accounts.isUnregistered(credentialID: "cred-1")
|
||||
|
||||
#expect(free)
|
||||
#expect(!taken)
|
||||
#expect(sam.displayName == "sam")
|
||||
#expect(passkey == Passkey(credentialID: "cred-1", publicKey: [1, 2, 3], signCount: 0, user: sam))
|
||||
#expect(byEmail == [passkey])
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
func `never adds a passkey to an account that already exists`() async throws {
|
||||
try await withDatabase { fluent in
|
||||
let accounts = AccountRepository(fluent: fluent)
|
||||
let hijack = try await accounts.join(email: AccountRepository.demoEmail, credentialID: "cred-x", publicKey: [9], signCount: 0)
|
||||
let passkeys = try await accounts.passkeys(email: AccountRepository.demoEmail)
|
||||
let stillFree = try await accounts.isUnregistered(credentialID: "cred-x")
|
||||
|
||||
#expect(hijack == nil)
|
||||
#expect(passkeys.isEmpty)
|
||||
#expect(stillFree)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
func `records a passkey's signature counter, and finds accounts without creating them`() async throws {
|
||||
try await withDatabase { fluent in
|
||||
let accounts = AccountRepository(fluent: fluent)
|
||||
|
||||
_ = try await accounts.join(email: "sam@example.com", credentialID: "cred-1", publicKey: [1], signCount: 0)
|
||||
try await accounts.recordUse(ofPasskey: "cred-1", signCount: 7)
|
||||
|
||||
let passkey = try await accounts.passkey(credentialID: "cred-1")
|
||||
let known = try await accounts.existingAccount(email: "sam@example.com")
|
||||
let unknown = try await accounts.existingAccount(email: "nobody@example.com")
|
||||
let stillUnknown = try await accounts.existingAccount(email: "nobody@example.com")
|
||||
|
||||
#expect(passkey?.signCount == 7)
|
||||
#expect(known?.email == "sam@example.com")
|
||||
#expect(unknown == nil)
|
||||
#expect(stillUnknown == nil)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user