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