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