]> git.saurik.com Git - apple/security.git/blob - keychain/ckks/tests/CloudKitMockXCTest.h
Security-58286.20.16.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 #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
52 @property id mockAccountStateTracker;
53
54 @property CKAccountStatus accountStatus;
55 @property BOOL supportsDeviceToDeviceEncryption;
56 @property SOSCCStatus circleStatus;
57 @property (readonly) NSString* ckDeviceID;
58 @property (readonly) CKKSCKAccountStateTracker* accountStateTracker;
59
60 @property NSString* circlePeerID;
61
62 @property bool aksLockState; // The current 'AKS lock state'
63 @property (readonly) CKKSLockStateTracker* lockStateTracker;
64 @property id mockLockStateTracker;
65
66 @property NSMutableDictionary<CKRecordZoneID*, FakeCKZone*>* zones;
67
68 @property NSOperationQueue* operationQueue;
69 @property NSBlockOperation* ckksHoldOperation;
70 @property NSBlockOperation* ckaccountHoldOperation;
71
72 @property NSBlockOperation* ckModifyHoldOperation;
73
74 @property bool silentFetchesAllowed;
75
76 @property id mockCKKSViewManager;
77 @property CKKSViewManager* injectedManager;
78
79 - (CKKSKey*) fakeTLK: (CKRecordZoneID*)zoneID;
80
81 - (void)expectCKModifyItemRecords: (NSUInteger) expectedNumberOfRecords
82 currentKeyPointerRecords: (NSUInteger) expectedCurrentKeyRecords
83 zoneID: (CKRecordZoneID*) zoneID;
84 - (void)expectCKModifyItemRecords: (NSUInteger) expectedNumberOfRecords
85 currentKeyPointerRecords: (NSUInteger) expectedCurrentKeyRecords
86 zoneID: (CKRecordZoneID*) zoneID
87 checkItem: (BOOL (^)(CKRecord*)) checkItem;
88
89 - (void)expectCKModifyItemRecords:(NSUInteger)expectedNumberOfModifiedRecords
90 deletedRecords:(NSUInteger)expectedNumberOfDeletedRecords
91 currentKeyPointerRecords:(NSUInteger)expectedCurrentKeyRecords
92 zoneID:(CKRecordZoneID*)zoneID
93 checkItem:(BOOL (^)(CKRecord*))checkItem;
94
95 - (void)expectCKDeleteItemRecords: (NSUInteger) expectedNumberOfRecords zoneID: (CKRecordZoneID*) zoneID;
96
97 - (void)expectCKModifyKeyRecords: (NSUInteger) expectedNumberOfRecords
98 currentKeyPointerRecords: (NSUInteger) expectedCurrentKeyRecords
99 zoneID: (CKRecordZoneID*) zoneID;
100
101 - (void)expectCKModifyRecords:(NSDictionary<NSString*, NSNumber*>*) expectedRecordTypeCounts
102 deletedRecordTypeCounts:(NSDictionary<NSString*, NSNumber*>*) expectedDeletedRecordTypeCounts
103 zoneID:(CKRecordZoneID*) zoneID
104 checkModifiedRecord:(BOOL (^)(CKRecord*)) checkRecord
105 runAfterModification:(void (^) ())afterModification;
106
107 - (void)failNextCKAtomicModifyItemRecordsUpdateFailure:(CKRecordZoneID*)zoneID;
108 - (void)failNextCKAtomicModifyItemRecordsUpdateFailure:(CKRecordZoneID*)zoneID blockAfterReject: (void (^)())blockAfterReject;
109 - (void)failNextCKAtomicModifyItemRecordsUpdateFailure:(CKRecordZoneID*)zoneID blockAfterReject: (void (^)())blockAfterReject withError:(NSError*)error;
110 - (void)expectCKAtomicModifyItemRecordsUpdateFailure: (CKRecordZoneID*) zoneID;
111
112 - (void)failNextZoneCreation:(CKRecordZoneID*)zoneID;
113 - (void)failNextZoneCreationSilently:(CKRecordZoneID*)zoneID;
114 - (void)failNextZoneSubscription:(CKRecordZoneID*)zoneID;
115 - (void)failNextZoneSubscription:(CKRecordZoneID*)zoneID withError:(NSError*)error;
116
117 // Use this to assert that a fetch occurs (especially if silentFetchesAllowed = false)
118 - (void)expectCKFetch;
119
120 // Wait until all scheduled cloudkit operations are reflected in the currentDatabase
121 - (void)waitForCKModifications;
122
123 // Unblocks the CKKS subsystem only.
124 - (void)startCKKSSubsystemOnly;
125
126 // Unblocks the CKAccount mock subsystem. Until this is called, the tests believe cloudd hasn't returned any account status yet.
127 - (void)startCKAccountStatusMock;
128
129 // Starts everything.
130 - (void)startCKKSSubsystem;
131
132 // Blocks the completion (partial or full) of CloudKit modifications
133 -(void)holdCloudKitModifications;
134
135 // Unblocks the hold you've added with holdCloudKitModifications; CloudKit modifications will finish
136 -(void)releaseCloudKitModificationHold;
137
138 #endif // OCTAGON
139 @end