]> git.saurik.com Git - apple/security.git/blob - keychain/ckks/tests/CloudKitMockXCTest.h
Security-58286.200.222.tar.gz
[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 #if OCTAGON
25
26 #import <CloudKit/CloudKit.h>
27 #import <CloudKit/CloudKit_Private.h>
28 #import <XCTest/XCTest.h>
29
30 #import <Foundation/Foundation.h>
31 #import <SystemConfiguration/SystemConfiguration.h>
32
33 #import "keychain/ckks/CKKSCKAccountStateTracker.h"
34 #import "keychain/ckks/tests/MockCloudKit.h"
35
36 NS_ASSUME_NONNULL_BEGIN
37
38 @class CKKSKey;
39 @class CKKSCKRecordHolder;
40 @class CKKSKeychainView;
41 @class CKKSViewManager;
42 @class FakeCKZone;
43 @class CKKSLockStateTracker;
44 @class CKKSReachabilityTracker;
45
46 @interface CloudKitMockXCTest : XCTestCase
47
48 @property CKRecordZoneID* testZoneID;
49
50 @property (nullable) id mockDatabase;
51 @property (nullable) id mockDatabaseExceptionCatcher;
52 @property (nullable) id mockContainer;
53 @property (nullable) id mockContainerExpectations;
54 @property (nullable) id mockFakeCKModifyRecordZonesOperation;
55 @property (nullable) id mockFakeCKModifySubscriptionsOperation;
56 @property (nullable) id mockFakeCKFetchRecordZoneChangesOperation;
57 @property (nullable) id mockFakeCKFetchRecordsOperation;
58 @property (nullable) id mockFakeCKQueryOperation;
59
60 @property (nullable) id mockAccountStateTracker;
61
62 @property CKAccountStatus accountStatus;
63 @property BOOL supportsDeviceToDeviceEncryption;
64 @property BOOL iCloudHasValidCredentials;
65 @property SOSAccountStatus* circleStatus;
66 @property (readonly) NSString* ckDeviceID;
67 @property (readonly) CKKSCKAccountStateTracker* accountStateTracker;
68
69 @property NSString* apsEnvironment;
70
71 @property NSString* circlePeerID;
72
73 @property bool aksLockState; // The current 'AKS lock state'
74 @property (readonly) CKKSLockStateTracker* lockStateTracker;
75 @property (nullable) id mockLockStateTracker;
76
77 @property SCNetworkReachabilityFlags reachabilityFlags; // The current 'network reachability flags'
78 @property (readonly) CKKSReachabilityTracker *reachabilityTracker;
79 @property (nullable) id mockReachabilityTracker;
80
81 @property (nullable) NSMutableDictionary<CKRecordZoneID*, FakeCKZone*>* zones;
82
83 @property (nullable) NSOperationQueue* operationQueue;
84 @property (nullable) NSBlockOperation* ckaccountHoldOperation;
85
86 @property (nullable) NSBlockOperation* ckModifyHoldOperation;
87 @property (nullable) NSBlockOperation* ckFetchHoldOperation;
88
89 @property bool silentFetchesAllowed;
90 @property bool silentZoneDeletesAllowed;
91
92 @property (nullable) id mockCKKSViewManager;
93 @property (nullable) CKKSViewManager* injectedManager;
94
95 - (CKKSKey*)fakeTLK:(CKRecordZoneID*)zoneID;
96
97 - (void)expectCKModifyItemRecords:(NSUInteger)expectedNumberOfRecords
98 currentKeyPointerRecords:(NSUInteger)expectedCurrentKeyRecords
99 zoneID:(CKRecordZoneID*)zoneID;
100 - (void)expectCKModifyItemRecords:(NSUInteger)expectedNumberOfRecords
101 currentKeyPointerRecords:(NSUInteger)expectedCurrentKeyRecords
102 zoneID:(CKRecordZoneID*)zoneID
103 checkItem:(BOOL (^_Nullable)(CKRecord*))checkItem;
104
105 - (void)expectCKModifyItemRecords:(NSUInteger)expectedNumberOfModifiedRecords
106 deletedRecords:(NSUInteger)expectedNumberOfDeletedRecords
107 currentKeyPointerRecords:(NSUInteger)expectedCurrentKeyRecords
108 zoneID:(CKRecordZoneID*)zoneID
109 checkItem:(BOOL (^_Nullable)(CKRecord*))checkItem;
110
111 - (void)expectCKDeleteItemRecords:(NSUInteger)expectedNumberOfRecords zoneID:(CKRecordZoneID*)zoneID;
112
113 - (void)expectCKModifyKeyRecords:(NSUInteger)expectedNumberOfRecords
114 currentKeyPointerRecords:(NSUInteger)expectedCurrentKeyRecords
115 tlkShareRecords:(NSUInteger)expectedTLKShareRecords
116 zoneID:(CKRecordZoneID*)zoneID;
117 - (void)expectCKModifyKeyRecords:(NSUInteger)expectedNumberOfRecords
118 currentKeyPointerRecords:(NSUInteger)expectedCurrentKeyRecords
119 tlkShareRecords:(NSUInteger)expectedTLKShareRecords
120 zoneID:(CKRecordZoneID*)zoneID
121 checkModifiedRecord:(BOOL (^_Nullable)(CKRecord*))checkModifiedRecord;
122
123 - (void)expectCKModifyRecords:(NSDictionary<NSString*, NSNumber*>*)expectedRecordTypeCounts
124 deletedRecordTypeCounts:(NSDictionary<NSString*, NSNumber*>* _Nullable)expectedDeletedRecordTypeCounts
125 zoneID:(CKRecordZoneID*)zoneID
126 checkModifiedRecord:(BOOL (^_Nullable)(CKRecord*))checkRecord
127 runAfterModification:(void (^_Nullable)(void))afterModification;
128
129 - (void)failNextCKAtomicModifyItemRecordsUpdateFailure:(CKRecordZoneID*)zoneID;
130 - (void)failNextCKAtomicModifyItemRecordsUpdateFailure:(CKRecordZoneID*)zoneID
131 blockAfterReject:(void (^_Nullable)(void))blockAfterReject;
132 - (void)failNextCKAtomicModifyItemRecordsUpdateFailure:(CKRecordZoneID*)zoneID
133 blockAfterReject:(void (^_Nullable)(void))blockAfterReject
134 withError:(NSError* _Nullable)error;
135 - (void)expectCKAtomicModifyItemRecordsUpdateFailure:(CKRecordZoneID*)zoneID;
136
137 - (void)failNextZoneCreation:(CKRecordZoneID*)zoneID;
138 - (void)failNextZoneCreationSilently:(CKRecordZoneID*)zoneID;
139 - (void)failNextZoneSubscription:(CKRecordZoneID*)zoneID;
140 - (void)failNextZoneSubscription:(CKRecordZoneID*)zoneID withError:(NSError*)error;
141
142 // Use this to assert that a fetch occurs (especially if silentFetchesAllowed = false)
143 - (void)expectCKFetch;
144
145 // 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'.
146 // This way, you can modify the CK zone to cause later collisions.
147 - (void)expectCKFetchAndRunBeforeFinished:(void (^_Nullable)(void))blockAfterFetch;
148
149 // Use this to assert that a FakeCKFetchRecordsOperation occurs.
150 - (void)expectCKFetchByRecordID;
151
152 // Use this to assert that a FakeCKQueryOperation occurs.
153 - (void)expectCKFetchByQuery;
154
155 // Wait until all scheduled cloudkit operations are reflected in the currentDatabase
156 - (void)waitForCKModifications;
157
158 // Unblocks the CKAccount mock subsystem. Until this is called, the tests believe cloudd hasn't returned any account status yet.
159 - (void)startCKAccountStatusMock;
160
161 // Starts everything.
162 - (void)startCKKSSubsystem;
163
164 // Blocks the completion (partial or full) of CloudKit modifications
165 - (void)holdCloudKitModifications;
166
167 // Unblocks the hold you've added with holdCloudKitModifications; CloudKit modifications will finish
168 - (void)releaseCloudKitModificationHold;
169
170 // Blocks the CloudKit fetches from beginning (similar to network latency)
171 - (void)holdCloudKitFetches;
172 // Unblocks the hold you've added with holdCloudKitFetches; CloudKit fetches will finish
173 - (void)releaseCloudKitFetchHold;
174
175 // Make a CK internal server extension error with a given code and description.
176 - (NSError*)ckInternalServerExtensionError:(NSInteger)code description:(NSString*)desc;
177
178 // Schedule an operation for execution (and failure), with some existing record errors.
179 // Other records in the operation but not in failedRecords will have CKErrorBatchRequestFailed errors created.
180 - (void)rejectWrite:(CKModifyRecordsOperation*)op failedRecords:(NSMutableDictionary<CKRecordID*, NSError*>*)failedRecords;
181
182 @end
183
184 NS_ASSUME_NONNULL_END
185
186 #endif /* OCTAGON */