mirror of
https://github.com/maxgoedjen/secretive.git
synced 2025-08-19 11:40:56 +00:00
Fixed tests.
This commit is contained in:
parent
e0c2775971
commit
1196530e27
@ -2,7 +2,7 @@ import Foundation
|
|||||||
import AppKit
|
import AppKit
|
||||||
|
|
||||||
/// Describes the chain of applications that requested a signature operation.
|
/// Describes the chain of applications that requested a signature operation.
|
||||||
public struct SigningRequestProvenance: Equatable {
|
public struct SigningRequestProvenance: Equatable, Sendable {
|
||||||
|
|
||||||
/// A list of processes involved in the request.
|
/// A list of processes involved in the request.
|
||||||
/// - Note: A chain will typically consist of many elements even for a simple request. For example, running `git fetch` in Terminal.app would generate a request chain of `ssh` -> `git` -> `zsh` -> `login` -> `Terminal.app`
|
/// - Note: A chain will typically consist of many elements even for a simple request. For example, running `git fetch` in Terminal.app would generate a request chain of `ssh` -> `git` -> `zsh` -> `login` -> `Terminal.app`
|
||||||
@ -30,7 +30,7 @@ extension SigningRequestProvenance {
|
|||||||
extension SigningRequestProvenance {
|
extension SigningRequestProvenance {
|
||||||
|
|
||||||
/// Describes a process in a `SigningRequestProvenance` chain.
|
/// Describes a process in a `SigningRequestProvenance` chain.
|
||||||
public struct Process: Equatable {
|
public struct Process: Equatable, Sendable {
|
||||||
|
|
||||||
/// The pid of the process.
|
/// The pid of the process.
|
||||||
public let pid: Int32
|
public let pid: Int32
|
||||||
|
@ -2,7 +2,6 @@ import Testing
|
|||||||
import Foundation
|
import Foundation
|
||||||
@testable import Brief
|
@testable import Brief
|
||||||
|
|
||||||
|
|
||||||
@Suite struct ReleaseParsingTests {
|
@Suite struct ReleaseParsingTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import Testing
|
import Testing
|
||||||
import CryptoKit
|
import CryptoKit
|
||||||
|
import Synchronization
|
||||||
@testable import SecretKit
|
@testable import SecretKit
|
||||||
@testable import SecretAgentKit
|
@testable import SecretAgentKit
|
||||||
|
|
||||||
@ -90,34 +91,35 @@ import CryptoKit
|
|||||||
@Test func witnessSignature() async {
|
@Test func witnessSignature() async {
|
||||||
let stubReader = StubFileHandleReader(availableData: Constants.Requests.requestSignature)
|
let stubReader = StubFileHandleReader(availableData: Constants.Requests.requestSignature)
|
||||||
let list = storeList(with: [Constants.Secrets.ecdsa256Secret])
|
let list = storeList(with: [Constants.Secrets.ecdsa256Secret])
|
||||||
var witnessed = false
|
let witnessed: Mutex<Bool> = .init(false)
|
||||||
let witness = StubWitness(speakNow: { _, trace in
|
let witness = StubWitness(speakNow: { _, trace in
|
||||||
return false
|
return false
|
||||||
}, witness: { _, trace in
|
}, witness: { _, trace in
|
||||||
witnessed = true
|
witnessed.lockedValue = true
|
||||||
})
|
})
|
||||||
let agent = Agent(storeList: list, witness: witness)
|
let agent = Agent(storeList: list, witness: witness)
|
||||||
await agent.handle(reader: stubReader, writer: stubWriter)
|
await agent.handle(reader: stubReader, writer: stubWriter)
|
||||||
#expect(witnessed)
|
let value = witnessed.lockedValue
|
||||||
|
#expect(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test func requestTracing() async {
|
@Test func requestTracing() async {
|
||||||
let stubReader = StubFileHandleReader(availableData: Constants.Requests.requestSignature)
|
let stubReader = StubFileHandleReader(availableData: Constants.Requests.requestSignature)
|
||||||
let list = storeList(with: [Constants.Secrets.ecdsa256Secret])
|
let list = storeList(with: [Constants.Secrets.ecdsa256Secret])
|
||||||
var speakNowTrace: SigningRequestProvenance! = nil
|
let speakNowTrace: Mutex<SigningRequestProvenance?> = .init(nil)
|
||||||
var witnessTrace: SigningRequestProvenance! = nil
|
let witnessTrace: Mutex<SigningRequestProvenance?> = .init(nil)
|
||||||
let witness = StubWitness(speakNow: { _, trace in
|
let witness = StubWitness(speakNow: { _, trace in
|
||||||
speakNowTrace = trace
|
speakNowTrace.lockedValue = trace
|
||||||
return false
|
return false
|
||||||
}, witness: { _, trace in
|
}, witness: { _, trace in
|
||||||
witnessTrace = trace
|
witnessTrace.lockedValue = trace
|
||||||
})
|
})
|
||||||
let agent = Agent(storeList: list, witness: witness)
|
let agent = Agent(storeList: list, witness: witness)
|
||||||
await agent.handle(reader: stubReader, writer: stubWriter)
|
await agent.handle(reader: stubReader, writer: stubWriter)
|
||||||
#expect(witnessTrace == speakNowTrace)
|
#expect(witnessTrace.lockedValue == speakNowTrace.lockedValue)
|
||||||
#expect(witnessTrace.origin.displayName == "Finder")
|
#expect(witnessTrace.lockedValue?.origin.displayName == "Finder")
|
||||||
#expect(witnessTrace.origin.validSignature == true)
|
#expect(witnessTrace.lockedValue?.origin.validSignature == true)
|
||||||
#expect(witnessTrace.origin.parentPID == 1)
|
#expect(witnessTrace.lockedValue?.origin.parentPID == 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Exception Handling
|
// MARK: Exception Handling
|
||||||
@ -143,6 +145,19 @@ import CryptoKit
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension Mutex where Value: Sendable {
|
||||||
|
|
||||||
|
var lockedValue: Value {
|
||||||
|
get {
|
||||||
|
withLock { $0 }
|
||||||
|
}
|
||||||
|
nonmutating set {
|
||||||
|
withLock { $0 = newValue }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
extension AgentTests {
|
extension AgentTests {
|
||||||
|
|
||||||
func storeList(with secrets: [Stub.Secret]) -> SecretStoreList {
|
func storeList(with secrets: [Stub.Secret]) -> SecretStoreList {
|
||||||
|
@ -3,8 +3,8 @@ import SecretAgentKit
|
|||||||
|
|
||||||
struct StubWitness {
|
struct StubWitness {
|
||||||
|
|
||||||
let speakNow: (AnySecret, SigningRequestProvenance) -> Bool
|
let speakNow: @Sendable (AnySecret, SigningRequestProvenance) -> Bool
|
||||||
let witness: (AnySecret, SigningRequestProvenance) -> ()
|
let witness: @Sendable (AnySecret, SigningRequestProvenance) -> ()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user