From fddffcebd1f3e5a17550e3c85d339b58a100b44b Mon Sep 17 00:00:00 2001 From: Max Goedjen Date: Mon, 14 Sep 2026 21:11:13 -0700 Subject: [PATCH] WIP --- .../Types/AuthenticationContext.swift | 9 ++- .../AuthenticationHandlerTests.swift | 76 ++++++++++++++++++- 2 files changed, 79 insertions(+), 6 deletions(-) diff --git a/Sources/Packages/Sources/SecretKit/Types/AuthenticationContext.swift b/Sources/Packages/Sources/SecretKit/Types/AuthenticationContext.swift index e1204e7..c8439bc 100644 --- a/Sources/Packages/Sources/SecretKit/Types/AuthenticationContext.swift +++ b/Sources/Packages/Sources/SecretKit/Types/AuthenticationContext.swift @@ -28,10 +28,13 @@ public struct SignatureRequest: Identifiable, Hashable, Sendable, Comparable { public var batchID: Int { var hasher = Hasher() - provenance.batchID.hash(into: &hasher) - if let target { - target.batchID.hash(into: &hasher) + guard let target else { + // Requests without target are not permitted to be batched. + id.hash(into: &hasher) + return hasher.finalize() } + provenance.batchID.hash(into: &hasher) + target.batchID.hash(into: &hasher) secret.id.hash(into: &hasher) return hasher.finalize() } diff --git a/Sources/Packages/Tests/SecretAgentKitTests/AuthenticationHandlerTests.swift b/Sources/Packages/Tests/SecretAgentKitTests/AuthenticationHandlerTests.swift index c9ef71d..e54ddfc 100644 --- a/Sources/Packages/Tests/SecretAgentKitTests/AuthenticationHandlerTests.swift +++ b/Sources/Packages/Tests/SecretAgentKitTests/AuthenticationHandlerTests.swift @@ -1,13 +1,83 @@ import Testing +import Foundation +import LocalAuthentication +import SecretKit import SecretAgentKit -@Suite @MainActor struct AuthenticationHandlerTests { +public struct TestSecret: Secret { - @Test func singleImmediatelyRequests() async throws { + public let id: UUID + public let name: String + public let publicKey: Data + public var attributes: Attributes + +} + +@MainActor final class TestContext: AuthenticationContextProtocol, Sendable { + + let id = UUID() + private var testEvaluationResult: Bool + + var evaluated: Bool + var canceled: Bool + var evaluationResult: Bool + + let secret: AnySecret + let laContext: LAContext? = nil + + + init(authenticationRequirement: AuthenticationRequirement, testEvaluationResult: Bool) { + self.evaluated = false + self.canceled = false + self.testEvaluationResult = testEvaluationResult + self.secret = AnySecret(TestSecret(id: UUID(), name: "Test Secret", publicKey: Data(), attributes: .init(keyType: .ecdsa256, authentication: authenticationRequirement))) } - @Test func authRequiredDoesntBlockNoAuthRequired() async throws { + nonisolated func valid(for request: SecretKit.SignatureRequest) -> Bool { + true } + + + func evaluate() async throws -> Bool { + evaluationResult = testEvaluationResult + evaluated = true + } + + func cancel() async { + canceled = true + } + } + +@MainActor @Suite struct AuthenticationHandlerTests { + + let handler = AuthenticationHandler() + + @Test func singleImmediatelyRequests() async throws { + var calledBatch = false + handler.setBatchAuthHandler { + calledBatch = true + } +// handler.waitForAuthentication(for: .init(secret: <#T##AnySecret#>, provenance: ., target: <#T##SigningRequestTarget?#>)) + #expect(!calledBatch) + } + + @Test func secondRetractsAndPresentsBatch() async throws { + + } + + @Test func authRequiredDoesntBlockNoAuthRequired() async throws { + + } + + @Test func batching() async throws { + + } + + @Test func batching() async throws { + + } + +}