mirror of
https://github.com/maxgoedjen/secretive.git
synced 2026-09-19 14:48:01 +02:00
WIP
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
@@ -1,13 +1,83 @@
|
||||
import Testing
|
||||
import Foundation
|
||||
import LocalAuthentication
|
||||
import SecretKit
|
||||
import SecretAgentKit
|
||||
|
||||
@Suite @MainActor struct AuthenticationHandlerTests {
|
||||
public struct TestSecret: Secret {
|
||||
|
||||
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)))
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user