]> git.saurik.com Git - apple/security.git/blob - keychain/ckks/tests/CloudKitMockXCTest.h
ea3519f0349238dfd0c9d1fe07bc865b251a2d8b
[apple/security.git] / keychain / ckks / tests / CloudKitMockXCTest.h
1 /*
2 * Copyright (c) 2016 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #import <XCTest/XCTest.h>
25 #import <CloudKit/CloudKit.h>
26 #import <CloudKit/CloudKit_Private.h>
27
28 #import <Foundation/Foundation.h>
29
30 #import "keychain/ckks/tests/MockCloudKit.h"
31 #import "keychain/ckks/CKKSCKAccountStateTracker.h"
32
33 @class CKKSKey;
34 @class CKKSCKRecordHolder;
35 @class CKKSKeychainView;
36 @class CKKSViewManager;
37 @class FakeCKZone;
38 @class CKKSLockStateTracker;
39
40 @interface CloudKitMockXCTest : XCTestCase
41
42 #if OCTAGON
43
44 @property CKRecordZoneID* testZoneID;
45
46 @property id mockDatabase;
47 @property id mockContainer;
48 @property id mockFakeCKModifyRecordZonesOperation;
49 @property id mockFakeCKModifySubscriptionsOperation;
50 @property id mockFakeCKFetchRecordZoneChangesOperation;
51 @property id mockFakeCKFetchRecordsOperation;
52 @property id mockFakeCKQueryOperation;
53
54 @property id mockAccountStateTracker;
55
56 @property CKAccountStatus accountStatus;
57 @property BOOL supportsDeviceToDeviceEncryption;
58 @property SOSCCStatus circleStatus;
59 @property (readonly) NSString* ckDeviceID;
60 @property (readonly) CKKSCKAccountStateTracker* accountStateTracker;
61
62 @property NSString* circlePeerID;
63
64 @property bool aksLockState; // The current 'AKS lock state'
65 @property (readonly) CKKSLockStateTracker* lockStateTracker;
66 @property id mockLockStateTracker;
67
68 @property NSMutableDictionary<CKRecordZoneID*, FakeCKZone*>* zones;
69
70 @property NSOperationQueue* operationQueue;
71 @property NSBlockOperation* ckksHoldOperation;
72 @property NSBlockOperation* ckaccountHoldOperation;
73
74 @property NSBlockOperation* ckModifyHoldOperation;
75 @property NSBlockOperation* ckFetchHoldOperation;
76
77 @property bool silentFetchesAllowed;
78
79 @property id mockCKKSViewManager;
80 @property CKKSViewManager* injectedManager;
81
82 - (CKKSKey*) fakeTLK: (CKRecordZoneID*)zoneID;
83
84 - (void)expectCKModifyItemRecords: (NSUInteger) expectedNumberOfRecords
85 currentKeyPointerRecords: (NSUInteger) expectedCurrentKeyRecords
86 zoneID: (CKRecordZoneID*) zoneID;
87 - (void)expectCKModifyItemRecords: (NSUInteger) expectedNumberOfRecords
88 currentKeyPointerRecords: (NSUInteger) expectedCurrentKeyRecords
89 zoneID: (CKRecordZoneID*) zoneID
90 checkItem: (BOOL (^)(CKRecord*)) checkItem;
91
92 - (void)expectCKModifyItemRecords:(NSUInteger)expectedNumberOfModifiedRecords
93 deletedRecords:(NSUInteger)expectedNumberOfDeletedRecords
94 currentKeyPointerRecords:(NSUInteger)expectedCurrentKeyRecords
95 zoneID:(CKRecordZoneID*)zoneID
96 checkItem:(BOOL (^)(CKRecord*))checkItem;
97
98 - (void)expectCKDeleteItemRecords: (NSUInteger) expectedNumberOfRecords zoneID: (CKRecordZoneID*) zoneID;
99
100 - (void)expectCKModifyKeyRecords:(NSUInteger)expectedNumberOfRecords
101 currentKeyPointerRecords:(NSUInteger)expectedCurrentKeyRecords
102 tlkShareRecords:(NSUInteger)expectedTLKShareRecords
103 zoneID:(CKRecordZoneID*)zoneID;
104
105 - (void)expectCKModifyRecords:(NSDictionary<NSString*, NSNumber*>*) expectedRecordTypeCounts
106 deletedRecordTypeCounts:(NSDictionary<NSString*, NSNumber*>*) expectedDeletedRecordTypeCounts
107 zoneID:(CKRecordZoneID*) zoneID
108 checkModifiedRecord:(BOOL (^)(CKRecord*)) checkRecord
109 runAfterModification:(void (^) ())afterModification;
110
111 - (void)failNextCKAtomicModifyItemRecordsUpdateFailure:(CKRecordZoneID*)zoneID;
112 - (void)failNextCKAtomicModifyItemRecordsUpdateFailure:(CKRecordZoneID*)zoneID blockAfterReject: (void (^)())blockAfterReject;
113 - (void)failNextCKAtomicModifyItemRecordsUpdateFailure:(CKRecordZoneID*)zoneID blockAfterReject: (void (^)())blockAfterReject withError:(NSError*)error;
114 - (void)expectCKAtomicModifyItemRecordsUpdateFailure: (CKRecordZoneID*) zoneID;
115
116 - (void)failNextZoneCreation:(CKRecordZoneID*)zoneID;
117 - (void)failNextZoneCreationSilently:(CKRecordZoneID*)zoneID;
118 - (void)failNextZoneSubscription:(CKRecordZoneID*)zoneID;
119 - (void)failNextZoneSubscription:(CKRecordZoneID*)zoneID withError:(NSError*)error;
120
121 // Use this to assert that a fetch occurs (especially if silentFetchesAllowed = false)
122 - (void)expectCKFetch;
123
124 // Use this to 1) assert that a fetch occurs and 2) cause a block to run _after_ all changes have been delivered but _before_ the fetch 'completes'.
125 // This way, you can modify the CK zone to cause later collisions.
126 - (void)expectCKFetchAndRunBeforeFinished: (void (^)())blockAfterFetch;
127
128 // Use this to assert that a FakeCKFetchRecordsOperation occurs.
129 -(void)expectCKFetchByRecordID;
130
131 // Use this to assert that a FakeCKQueryOperation occurs.
132 - (void)expectCKFetchByQuery;
133
134 // Wait until all scheduled cloudkit operations are reflected in the currentDatabase
135 - (void)waitForCKModifications;
136
137 // Unblocks the CKKS subsystem only.
138 - (void)startCKKSSubsystemOnly;
139
140 // Unblocks the CKAccount mock subsystem. Until this is called, the tests believe cloudd hasn't returned any account status yet.
141 - (void)startCKAccountStatusMock;
142
143 // Starts everything.
144 - (void)startCKKSSubsystem;
145
146 // Blocks the completion (partial or full) of CloudKit modifications
147 -(void)holdCloudKitModifications;
148
149 // Unblocks the hold you've added with holdCloudKitModifications; CloudKit modifications will finish
150 -(void)releaseCloudKitModificationHold;
151
152 // Blocks the CloudKit fetches from beginning (similar to network latency)
153 -(void)holdCloudKitFetches;
154 // Unblocks the hold you've added with holdCloudKitFetches; CloudKit fetches will finish
155 -(void)releaseCloudKitFetchHold;
156
157 // Make a CK internal server extension error with a given code and description.
158 - (NSError*)ckInternalServerExtensionError:(NSInteger)code description:(NSString*)desc;
159
160 // Schedule an operation for execution (and failure), with some existing record errors.
161 // Other records in the operation but not in failedRecords will have CKErrorBatchRequestFailed errors created.
162 -(void)rejectWrite:(CKModifyRecordsOperation*)op failedRecords:(NSMutableDictionary<CKRecordID*, NSError*>*)failedRecords;
163
164 #endif // OCTAGON
165 @end