5 // Created by Ben Williamson on 6/8/18.
12 func dumpSync(test: XCTestCase) -> ([AnyHashable: Any]?, Error?) {
13 let expectation = XCTestExpectation(description: "dump replied")
14 var reta: [AnyHashable: Any]?, reterr: Error?
20 test.wait(for: [expectation], timeout: 10.0)
24 func resetSync(resetReason: CuttlefishResetReason, test: XCTestCase) -> Error? {
25 let expectation = XCTestExpectation(description: "reset replied")
27 self.reset(resetReason: resetReason) { error in
31 test.wait(for: [expectation], timeout: 10.0)
35 func localResetSync(test: XCTestCase) -> Error? {
36 let expectation = XCTestExpectation(description: "reset replied")
38 self.localReset { error in
42 test.wait(for: [expectation], timeout: 10.0)
46 func prepareSync(test: XCTestCase,
52 deviceName: String = "test device name",
53 serialNumber: String = "456",
54 osVersion: String = "123",
55 policyVersion: UInt64? = nil,
56 policySecrets: [String: Data]? = nil,
57 signingPrivateKeyPersistentRef: Data? = nil,
58 encryptionPrivateKeyPersistentRef: Data? = nil
59 ) -> (String?, Data?, Data?, Data?, Data?, Error?) {
60 let expectation = XCTestExpectation(description: "prepare replied")
61 var reta: String?, retb: Data?, retc: Data?, retd: Data?, rete: Data?, reterr: Error?
62 self.prepare(epoch: epoch,
64 bottleSalt: bottleSalt,
67 deviceName: deviceName,
68 serialNumber: serialNumber,
70 policyVersion: policyVersion,
71 policySecrets: policySecrets,
72 signingPrivateKeyPersistentRef: signingPrivateKeyPersistentRef,
73 encryptionPrivateKeyPersistentRef: encryptionPrivateKeyPersistentRef
74 ) { a, b, c, d, e, err in
83 test.wait(for: [expectation], timeout: 10.0)
84 return (reta, retb, retc, retd, rete, reterr)
87 func establishSync(test: XCTestCase,
88 ckksKeys: [CKKSKeychainBackedKeySet],
89 tlkShares: [CKKSTLKShare],
90 preapprovedKeys: [Data]?) -> (String?, [CKRecord], Error?) {
91 let expectation = XCTestExpectation(description: "prepare replied")
92 var reta: String?, retkhr: [CKRecord]?, reterr: Error?
93 self.establish(ckksKeys: ckksKeys,
95 preapprovedKeys: preapprovedKeys) { a, khr, err in
101 test.wait(for: [expectation], timeout: 10.0)
102 return (reta, retkhr!, reterr)
105 func vouchSync(test: XCTestCase,
108 permanentInfoSig: Data,
111 ckksKeys: [CKKSKeychainBackedKeySet]) -> (Data?, Data?, Error?) {
112 let expectation = XCTestExpectation(description: "vouch replied")
113 var reta: Data?, retb: Data?, reterr: Error?
114 self.vouch(peerID: peerID,
115 permanentInfo: permanentInfo,
116 permanentInfoSig: permanentInfoSig,
117 stableInfo: stableInfo,
118 stableInfoSig: stableInfoSig,
119 ckksKeys: ckksKeys) { a, b, err in
123 expectation.fulfill()
125 test.wait(for: [expectation], timeout: 10.0)
126 return (reta, retb, reterr)
129 func preflightVouchWithBottleSync(test: XCTestCase, bottleID: String) -> (String?, Error?) {
130 let expectation = XCTestExpectation(description: "preflightVouchWithBottle replied")
131 var reta: String?, reterr: Error?
132 self.preflightVouchWithBottle(bottleID: bottleID) { a, err in
135 expectation.fulfill()
137 test.wait(for: [expectation], timeout: 10.0)
138 return (reta, reterr)
141 func vouchWithBottleSync(test: XCTestCase, b: String, entropy: Data, bottleSalt: String, tlkShares: [CKKSTLKShare]) -> (Data?, Data?, Error?) {
142 let expectation = XCTestExpectation(description: "vouchWithBottle replied")
143 var reta: Data?, retb: Data?, reterr: Error?
144 self.vouchWithBottle(bottleID: b, entropy: entropy, bottleSalt: bottleSalt, tlkShares: tlkShares) { a, b, err in
148 expectation.fulfill()
150 test.wait(for: [expectation], timeout: 10.0)
151 return (reta, retb, reterr)
154 func joinSync(test: XCTestCase,
157 ckksKeys: [CKKSKeychainBackedKeySet],
158 tlkShares: [CKKSTLKShare],
159 preapprovedKeys: [Data]? = nil) -> (String?, [CKRecord]?, Error?) {
160 let expectation = XCTestExpectation(description: "join replied")
161 var reta: String?, retkhr: [CKRecord]?, reterr: Error?
162 self.join(voucherData: voucherData,
163 voucherSig: voucherSig,
165 tlkShares: tlkShares,
166 preapprovedKeys: preapprovedKeys) { a, khr, err in
170 expectation.fulfill()
172 test.wait(for: [expectation], timeout: 10.0)
173 return (reta, retkhr, reterr)
176 func preapprovedJoinSync(test: XCTestCase,
177 ckksKeys: [CKKSKeychainBackedKeySet],
178 tlkShares: [CKKSTLKShare],
179 preapprovedKeys: [Data]? = nil) -> (String?, [CKRecord]?, Error?) {
180 let expectation = XCTestExpectation(description: "preapprovedjoin replied")
182 var retkhr: [CKRecord]?
184 self.preapprovedJoin(ckksKeys: ckksKeys,
185 tlkShares: tlkShares,
186 preapprovedKeys: preapprovedKeys) { a, khr, err in
190 expectation.fulfill()
192 test.wait(for: [expectation], timeout: 10.0)
193 return (reta, retkhr, reterr)
196 func updateSync(test: XCTestCase,
197 deviceName: String? = nil,
198 serialNumner: String? = nil,
199 osVersion: String? = nil,
200 policyVersion: UInt64? = nil,
201 policySecrets: [String: Data]? = nil) -> (TrustedPeersHelperPeerState?, Error?) {
202 let expectation = XCTestExpectation(description: "update replied")
204 var retstate: TrustedPeersHelperPeerState?
205 self.update(deviceName: deviceName,
206 serialNumber: serialNumner,
207 osVersion: osVersion,
208 policyVersion: policyVersion,
209 policySecrets: policySecrets) { state, err in
212 expectation.fulfill()
214 test.wait(for: [expectation], timeout: 10.0)
215 return (retstate, reterr)
218 func setAllowedMachineIDsSync(test: XCTestCase, allowedMachineIDs: Set<String>, listDifference: Bool = true) -> (Error?) {
219 let expectation = XCTestExpectation(description: "setAllowedMachineIDs replied")
221 self.setAllowedMachineIDs(allowedMachineIDs) { differences, err in
222 XCTAssertEqual(differences, listDifference, "Reported list difference should match expectation")
224 expectation.fulfill()
226 test.wait(for: [expectation], timeout: 10.0)
230 func addAllowedMachineIDsSync(test: XCTestCase, machineIDs: [String]) -> Error? {
231 let expectation = XCTestExpectation(description: "addAllow replied")
233 self.addAllow(machineIDs) { err in
235 expectation.fulfill()
237 test.wait(for: [expectation], timeout: 10.0)
241 func removeAllowedMachineIDsSync(test: XCTestCase, machineIDs: [String]) -> Error? {
242 let expectation = XCTestExpectation(description: "removeAllow replied")
244 self.removeAllow(machineIDs) { err in
246 expectation.fulfill()
248 test.wait(for: [expectation], timeout: 10.0)
252 func fetchAllowedMachineIDsSync(test: XCTestCase) -> (Set<String>?, Error?) {
253 let expectation = XCTestExpectation(description: "fetchMIDList replied")
254 var retlist: Set<String>?
256 self.fetchAllowedMachineIDs() { list, err in
259 expectation.fulfill()
261 test.wait(for: [expectation], timeout: 10.0)
262 return (retlist, reterr)
265 func departByDistrustingSelfSync(test: XCTestCase) -> Error? {
266 let expectation = XCTestExpectation(description: "departByDistrustingSelf replied")
268 self.departByDistrustingSelf { error in
270 expectation.fulfill()
272 test.wait(for: [expectation], timeout: 10.0)
276 func distrustSync(test: XCTestCase, peerIDs: Set<String>) -> Error? {
277 let expectation = XCTestExpectation(description: "distrustSync replied")
279 self.distrust(peerIDs: peerIDs) { error in
281 expectation.fulfill()
283 test.wait(for: [expectation], timeout: 10.0)
287 func getStateSync(test: XCTestCase) -> ContainerState {
288 let expectation = XCTestExpectation(description: "getState replied")
289 var retstate: ContainerState?
290 self.getState { state in
292 expectation.fulfill()
294 test.wait(for: [expectation], timeout: 10.0)
298 func loadSecretSync(test: XCTestCase,
299 label: String) -> (Data?) {
302 secret = try loadSecret(label: label)
309 func setRecoveryKeySync(test: XCTestCase, recoveryKey: String, recoverySalt: String, ckksKeys: [CKKSKeychainBackedKeySet]) -> (Error?) {
310 let expectation = XCTestExpectation(description: "setRecoveryKey replied")
313 self.setRecoveryKey(recoveryKey: recoveryKey, salt: recoverySalt, ckksKeys: ckksKeys) { error in
315 expectation.fulfill()
317 test.wait(for: [expectation], timeout: 10.0)
321 func fetchViableBottlesSync(test: XCTestCase) -> ([String]?, [String]?, Error?) {
322 let expectation = XCTestExpectation(description: "fetchViableBottles replied")
323 var retescrowRecordIDs: [String]?
324 var retpartialEscrowRecordIDs: [String]?
326 self.fetchViableBottles { escrowRecordIDs, partialEscrowRecordIDs, error in
327 retescrowRecordIDs = escrowRecordIDs
328 retpartialEscrowRecordIDs = partialEscrowRecordIDs
330 expectation.fulfill()
332 test.wait(for: [expectation], timeout: 10.0)
333 return (retescrowRecordIDs, retpartialEscrowRecordIDs, reterror)
336 func trustStatusSync(test: XCTestCase) -> (TrustedPeersHelperEgoPeerStatus, Error?) {
337 let expectation = XCTestExpectation(description: "trustStatus replied")
338 var retEgoStatus = TrustedPeersHelperEgoPeerStatus(egoPeerID: nil,
340 viablePeerCountsByModelID: [:],
341 peerCountsByMachineID: [:],
345 self.trustStatus { egoStatus, error in
346 retEgoStatus = egoStatus
348 expectation.fulfill()
350 test.wait(for: [expectation], timeout: 10.0)
351 return (retEgoStatus, reterror)
354 func fetchPolicyDocumentsSync(test: XCTestCase,
355 keys: [NSNumber: String]) -> ([NSNumber: [String]]?, Error?) {
356 let expectation = XCTestExpectation(description: "fetchPolicyDocuments replied")
357 var reta: [NSNumber: [String]]?, reterr: Error?
358 self.fetchPolicyDocuments(keys: keys) { a, err in
361 expectation.fulfill()
363 test.wait(for: [expectation], timeout: 10.0)
364 return (reta, reterr)
367 func fetchEscrowContentsSync(test: XCTestCase) -> (Data?, String?, Data?, Error?) {
368 let expectation = XCTestExpectation(description: "fetchEscrowContents replied")
369 var retentropy: Data?
370 var retbottleID: String?
374 self.fetchEscrowContents { entropy, bottleID, spki, error in
376 retbottleID = bottleID
380 expectation.fulfill()
382 test.wait(for: [expectation], timeout: 10.0)
383 return (retentropy, retbottleID, retspki, reterror)
386 func requestHealthCheckSync(requiresEscrowCheck: Bool, test: XCTestCase) -> (Bool, Bool, Bool, Error?) {
387 let expectation = XCTestExpectation(description: "requestHealthCheck replied")
388 var retrepairaccount: Bool = false
389 var retrepairescrow: Bool = false
390 var retresetoctagon: Bool = false
393 self.requestHealthCheck(requiresEscrowCheck: requiresEscrowCheck) { repairAccount, repairEscrow, resetOctagon, error in
394 retrepairaccount = repairAccount
395 retrepairescrow = repairEscrow
396 retresetoctagon = resetOctagon
399 expectation.fulfill()
401 test.wait(for: [expectation], timeout: 10.0)
402 return (retrepairaccount, retrepairescrow, retresetoctagon, reterror)