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: TPPolicyVersion? = nil,
56 policySecrets: [String: Data]? = nil,
57 signingPrivateKeyPersistentRef: Data? = nil,
58 encryptionPrivateKeyPersistentRef: Data? = nil
59 ) -> (String?, Data?, Data?, Data?, Data?, Set<String>?, TPPolicy?, Error?) {
60 let expectation = XCTestExpectation(description: "prepare replied")
61 var reta: String?, retb: Data?, retc: Data?, retd: Data?, rete: Data?, reterr: Error?
62 var retviews: Set<String>?
63 var retpolicy: TPPolicy?
64 self.prepare(epoch: epoch,
66 bottleSalt: bottleSalt,
69 deviceName: deviceName,
70 serialNumber: serialNumber,
72 policyVersion: policyVersion,
73 policySecrets: policySecrets,
74 signingPrivateKeyPersistentRef: signingPrivateKeyPersistentRef,
75 encryptionPrivateKeyPersistentRef: encryptionPrivateKeyPersistentRef
76 ) { a, b, c, d, e, f, g, err in
87 test.wait(for: [expectation], timeout: 10.0)
88 return (reta, retb, retc, retd, rete, retviews, retpolicy, reterr)
91 func establishSync(test: XCTestCase,
92 ckksKeys: [CKKSKeychainBackedKeySet],
93 tlkShares: [CKKSTLKShare],
94 preapprovedKeys: [Data]?) -> (String?, [CKRecord], Error?) {
95 let expectation = XCTestExpectation(description: "prepare replied")
96 var reta: String?, retkhr: [CKRecord]?, reterr: Error?
97 self.establish(ckksKeys: ckksKeys,
99 preapprovedKeys: preapprovedKeys) { a, khr, err in
103 expectation.fulfill()
105 test.wait(for: [expectation], timeout: 10.0)
106 return (reta, retkhr!, reterr)
109 func vouchSync(test: XCTestCase,
112 permanentInfoSig: Data,
115 ckksKeys: [CKKSKeychainBackedKeySet]) -> (Data?, Data?, Error?) {
116 let expectation = XCTestExpectation(description: "vouch replied")
117 var reta: Data?, retb: Data?, reterr: Error?
118 self.vouch(peerID: peerID,
119 permanentInfo: permanentInfo,
120 permanentInfoSig: permanentInfoSig,
121 stableInfo: stableInfo,
122 stableInfoSig: stableInfoSig,
123 ckksKeys: ckksKeys) { a, b, err in
127 expectation.fulfill()
129 test.wait(for: [expectation], timeout: 10.0)
130 return (reta, retb, reterr)
133 func preflightVouchWithBottleSync(test: XCTestCase, bottleID: String) -> (String?, Set<String>?, TPPolicy?, Error?) {
134 let expectation = XCTestExpectation(description: "preflightVouchWithBottle replied")
135 var reta: String?, reterr: Error?
136 var retviews: Set<String>?, retpolicy: TPPolicy?
137 self.preflightVouchWithBottle(bottleID: bottleID) { a, views, policy, err in
142 expectation.fulfill()
144 test.wait(for: [expectation], timeout: 10.0)
145 return (reta, retviews, retpolicy, reterr)
148 func vouchWithBottleSync(test: XCTestCase, b: String, entropy: Data, bottleSalt: String, tlkShares: [CKKSTLKShare]) -> (Data?, Data?, Int64, Int64, Error?) {
149 let expectation = XCTestExpectation(description: "vouchWithBottle replied")
150 var reta: Data?, retb: Data?, retc: Int64 = 0, retd: Int64 = 0, reterr: Error?
151 self.vouchWithBottle(bottleID: b, entropy: entropy, bottleSalt: bottleSalt, tlkShares: tlkShares) { a, b, c, d, err in
157 expectation.fulfill()
159 test.wait(for: [expectation], timeout: 10.0)
160 return (reta, retb, retc, retd, reterr)
163 func joinSync(test: XCTestCase,
166 ckksKeys: [CKKSKeychainBackedKeySet],
167 tlkShares: [CKKSTLKShare],
168 preapprovedKeys: [Data]? = nil) -> (String?, [CKRecord]?, Set<String>?, TPPolicy?, Error?) {
169 let expectation = XCTestExpectation(description: "join replied")
170 var reta: String?, retkhr: [CKRecord]?, reterr: Error?
171 var retviews: Set<String>?, retpolicy: TPPolicy?
172 self.join(voucherData: voucherData,
173 voucherSig: voucherSig,
175 tlkShares: tlkShares,
176 preapprovedKeys: preapprovedKeys) { a, khr, views, policy, err in
182 expectation.fulfill()
184 test.wait(for: [expectation], timeout: 10.0)
185 return (reta, retkhr, retviews, retpolicy, reterr)
188 func preapprovedJoinSync(test: XCTestCase,
189 ckksKeys: [CKKSKeychainBackedKeySet],
190 tlkShares: [CKKSTLKShare],
191 preapprovedKeys: [Data]? = nil) -> (String?, [CKRecord]?, Set<String>?, TPPolicy?, Error?) {
192 let expectation = XCTestExpectation(description: "preapprovedjoin replied")
194 var retkhr: [CKRecord]?
195 var retviews: Set<String>?
196 var retpolicy: TPPolicy?
198 self.preapprovedJoin(ckksKeys: ckksKeys,
199 tlkShares: tlkShares,
200 preapprovedKeys: preapprovedKeys) { a, khr, views, policy, err in
206 expectation.fulfill()
208 test.wait(for: [expectation], timeout: 10.0)
209 return (reta, retkhr, retviews, retpolicy, reterr)
212 func updateSync(test: XCTestCase,
213 deviceName: String? = nil,
214 serialNumner: String? = nil,
215 osVersion: String? = nil,
216 policyVersion: UInt64? = nil,
217 policySecrets: [String: Data]? = nil) -> (TrustedPeersHelperPeerState?, Error?) {
218 let expectation = XCTestExpectation(description: "update replied")
220 var retstate: TrustedPeersHelperPeerState?
221 self.update(deviceName: deviceName,
222 serialNumber: serialNumner,
223 osVersion: osVersion,
224 policyVersion: policyVersion,
225 policySecrets: policySecrets) { state, err in
228 expectation.fulfill()
230 test.wait(for: [expectation], timeout: 10.0)
231 return (retstate, reterr)
234 func setAllowedMachineIDsSync(test: XCTestCase, allowedMachineIDs: Set<String>, accountIsDemo: Bool, listDifference: Bool = true) -> (Error?) {
235 let expectation = XCTestExpectation(description: "setAllowedMachineIDs replied")
237 let honorIDMSListChanges = accountIsDemo ? false : true
238 self.setAllowedMachineIDs(allowedMachineIDs, honorIDMSListChanges: honorIDMSListChanges) { differences, err in
239 XCTAssertEqual(differences, listDifference, "Reported list difference should match expectation")
241 expectation.fulfill()
243 test.wait(for: [expectation], timeout: 10.0)
247 func addAllowedMachineIDsSync(test: XCTestCase, machineIDs: [String]) -> Error? {
248 let expectation = XCTestExpectation(description: "addAllow replied")
250 self.addAllow(machineIDs) { err in
252 expectation.fulfill()
254 test.wait(for: [expectation], timeout: 10.0)
258 func removeAllowedMachineIDsSync(test: XCTestCase, machineIDs: [String]) -> Error? {
259 let expectation = XCTestExpectation(description: "removeAllow replied")
261 self.removeAllow(machineIDs) { err in
263 expectation.fulfill()
265 test.wait(for: [expectation], timeout: 10.0)
269 func fetchAllowedMachineIDsSync(test: XCTestCase) -> (Set<String>?, Error?) {
270 let expectation = XCTestExpectation(description: "fetchMIDList replied")
271 var retlist: Set<String>?
273 self.fetchAllowedMachineIDs { list, err in
276 expectation.fulfill()
278 test.wait(for: [expectation], timeout: 10.0)
279 return (retlist, reterr)
282 func departByDistrustingSelfSync(test: XCTestCase) -> Error? {
283 let expectation = XCTestExpectation(description: "departByDistrustingSelf replied")
285 self.departByDistrustingSelf { error in
287 expectation.fulfill()
289 test.wait(for: [expectation], timeout: 10.0)
293 func distrustSync(test: XCTestCase, peerIDs: Set<String>) -> Error? {
294 let expectation = XCTestExpectation(description: "distrustSync replied")
296 self.distrust(peerIDs: peerIDs) { error in
298 expectation.fulfill()
300 test.wait(for: [expectation], timeout: 10.0)
304 func getStateSync(test: XCTestCase) -> ContainerState {
305 let expectation = XCTestExpectation(description: "getState replied")
306 var retstate: ContainerState?
307 self.getState { state in
309 expectation.fulfill()
311 test.wait(for: [expectation], timeout: 10.0)
315 func loadSecretSync(test: XCTestCase,
316 label: String) -> (Data?) {
319 secret = try loadSecret(label: label)
326 func setRecoveryKeySync(test: XCTestCase, recoveryKey: String, recoverySalt: String, ckksKeys: [CKKSKeychainBackedKeySet]) -> (Error?) {
327 let expectation = XCTestExpectation(description: "setRecoveryKey replied")
330 self.setRecoveryKey(recoveryKey: recoveryKey, salt: recoverySalt, ckksKeys: ckksKeys) { error in
332 expectation.fulfill()
334 test.wait(for: [expectation], timeout: 10.0)
338 func fetchViableBottlesSync(test: XCTestCase) -> ([String]?, [String]?, Error?) {
339 let expectation = XCTestExpectation(description: "fetchViableBottles replied")
340 var retescrowRecordIDs: [String]?
341 var retpartialEscrowRecordIDs: [String]?
343 self.fetchViableBottles { escrowRecordIDs, partialEscrowRecordIDs, error in
344 retescrowRecordIDs = escrowRecordIDs
345 retpartialEscrowRecordIDs = partialEscrowRecordIDs
347 expectation.fulfill()
349 test.wait(for: [expectation], timeout: 10.0)
350 return (retescrowRecordIDs, retpartialEscrowRecordIDs, reterror)
353 func trustStatusSync(test: XCTestCase) -> (TrustedPeersHelperEgoPeerStatus, Error?) {
354 let expectation = XCTestExpectation(description: "trustStatus replied")
355 var retEgoStatus = TrustedPeersHelperEgoPeerStatus(egoPeerID: nil,
357 viablePeerCountsByModelID: [:],
358 peerCountsByMachineID: [:],
362 self.trustStatus { egoStatus, error in
363 retEgoStatus = egoStatus
365 expectation.fulfill()
367 test.wait(for: [expectation], timeout: 10.0)
368 return (retEgoStatus, reterror)
371 func fetchPolicyDocumentsSync(test: XCTestCase,
372 versions: Set<TPPolicyVersion>) -> ([TPPolicyVersion: Data]?, Error?) {
373 let expectation = XCTestExpectation(description: "fetchPolicyDocuments replied")
374 var reta: [TPPolicyVersion: Data]?, reterr: Error?
375 self.fetchPolicyDocuments(versions: versions) { a, err in
378 expectation.fulfill()
380 test.wait(for: [expectation], timeout: 10.0)
381 return (reta, reterr)
384 func fetchEscrowContentsSync(test: XCTestCase) -> (Data?, String?, Data?, Error?) {
385 let expectation = XCTestExpectation(description: "fetchEscrowContents replied")
386 var retentropy: Data?
387 var retbottleID: String?
391 self.fetchEscrowContents { entropy, bottleID, spki, error in
393 retbottleID = bottleID
397 expectation.fulfill()
399 test.wait(for: [expectation], timeout: 10.0)
400 return (retentropy, retbottleID, retspki, reterror)
403 func requestHealthCheckSync(requiresEscrowCheck: Bool, test: XCTestCase) -> (Bool, Bool, Bool, Bool, Error?) {
404 let expectation = XCTestExpectation(description: "requestHealthCheck replied")
405 var retrepairaccount: Bool = false
406 var retrepairescrow: Bool = false
407 var retresetoctagon: Bool = false
408 var retleavetrust: Bool = false
411 self.requestHealthCheck(requiresEscrowCheck: requiresEscrowCheck) { repairAccount, repairEscrow, resetOctagon, leaveTrust, error in
412 retrepairaccount = repairAccount
413 retrepairescrow = repairEscrow
414 retresetoctagon = resetOctagon
415 retleavetrust = leaveTrust
418 expectation.fulfill()
420 test.wait(for: [expectation], timeout: 10.0)
421 return (retrepairaccount, retrepairescrow, retresetoctagon, retleavetrust, reterror)