]> git.saurik.com Git - apple/security.git/blob - keychain/ckks/tests/MockCloudKit.h
Security-58286.240.4.tar.gz
[apple/security.git] / keychain / ckks / tests / MockCloudKit.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 <Foundation/Foundation.h>
28
29 #import "keychain/ckks/CKKSNotifier.h"
30 #import "keychain/ckks/CloudKitDependencies.h"
31
32 NS_ASSUME_NONNULL_BEGIN
33
34 @class CKKSCKRecordHolder;
35 @class FakeCKZone;
36
37 typedef NSMutableDictionary<CKRecordZoneID*, FakeCKZone*> FakeCKDatabase;
38
39
40 @interface FakeCKModifyRecordZonesOperation : NSBlockOperation <CKKSModifyRecordZonesOperation> {
41 CKOperationConfiguration* _configuration;
42 }
43 @property (nullable) NSError* creationError;
44 @property (nonatomic, nullable) NSMutableArray<CKRecordZone*>* recordZonesSaved;
45 @property (nonatomic, nullable) NSMutableArray<CKRecordZoneID*>* recordZoneIDsDeleted;
46 @property (nonatomic, copy, null_resettable) CKOperationConfiguration *configuration;
47
48 + (FakeCKDatabase*)ckdb;
49 +(void)ensureZoneDeletionAllowed:(FakeCKZone*)zone;
50 @end
51
52 @interface FakeCKModifySubscriptionsOperation : NSBlockOperation <CKKSModifySubscriptionsOperation> {
53 CKOperationConfiguration* _configuration;
54 }
55 @property (nullable) NSError* subscriptionError;
56 @property (nonatomic, nullable) NSMutableArray<CKSubscription*>* subscriptionsSaved;
57 @property (nonatomic, nullable) NSMutableArray<NSString*>* subscriptionIDsDeleted;
58 @property (nonatomic, copy, null_resettable) CKOperationConfiguration *configuration;
59 + (FakeCKDatabase*)ckdb;
60 @end
61
62 @interface FakeCKFetchRecordZoneChangesOperation : NSOperation <CKKSFetchRecordZoneChangesOperation> {
63 CKOperationConfiguration* _configuration;
64 }
65
66 + (FakeCKDatabase*)ckdb;
67 @property (nonatomic, copy) NSString *operationID;
68 @property (nonatomic, readonly, strong, nullable) CKOperationConfiguration *resolvedConfiguration;
69 @property (nullable) void (^blockAfterFetch)(void);
70 @end
71
72 @interface FakeCKFetchRecordsOperation : NSBlockOperation <CKKSFetchRecordsOperation>
73 + (FakeCKDatabase*)ckdb;
74 @end
75
76 @interface FakeCKQueryOperation : NSBlockOperation <CKKSQueryOperation>
77 + (FakeCKDatabase*)ckdb;
78 @end
79
80 @interface FakeAPSConnection : NSObject <CKKSAPSConnection>
81 @end
82
83 @interface FakeNSNotificationCenter : NSObject <CKKSNSNotificationCenter>
84 + (instancetype)defaultCenter;
85 - (void)addObserver:(id)observer selector:(SEL)aSelector name:(nullable NSNotificationName)aName object:(nullable id)anObject;
86 @end
87
88 @interface FakeCKZone : NSObject
89 // Used while mocking: database is the contents of the current current CloudKit database, pastDatabase is the state of the world in the past at different change tokens
90 @property CKRecordZoneID* zoneID;
91 @property CKServerChangeToken* currentChangeToken;
92 @property NSMutableDictionary<CKRecordID*, CKRecord*>* currentDatabase;
93 @property NSMutableDictionary<CKServerChangeToken*, NSMutableDictionary<CKRecordID*, CKRecord*>*>* pastDatabases;
94 @property bool flag; // used however you'd like in a test
95
96 // Usually nil. If set, trying to 'create' this zone should fail.
97 @property (nullable) NSError* creationError;
98
99 // Usually false. If set, trying to 'create' this should should 1) pretend to succeed but 2) delete this zone from existence
100 @property bool failCreationSilently;
101
102 // Usually nil. If set, trying to subscribe to this zone should fail.
103 @property (nullable) NSError* subscriptionError;
104
105 // Serial queue. Use this for transactionality.
106 @property dispatch_queue_t queue;
107
108 - (instancetype)initZone:(CKRecordZoneID*)zoneID;
109
110 // Always Succeed
111 - (void)addToZone:(CKKSCKRecordHolder*)item zoneID:(CKRecordZoneID*)zoneID;
112 - (void)addToZone:(CKRecord*)record;
113
114 // If you want a transaction of adding, use these
115 - (void)_onqueueAddToZone:(CKKSCKRecordHolder*)item zoneID:(CKRecordZoneID*)zoneID;
116 - (void)_onqueueAddToZone:(CKRecord*)record;
117
118 // Removes this record from all versions of the CK database, without changing the change tag
119 - (void)deleteFromHistory:(CKRecordID*)recordID;
120
121 - (void)addCKRecordToZone:(CKRecord*)record;
122 - (NSError* _Nullable)deleteCKRecordIDFromZone:(CKRecordID*)recordID;
123
124 // Sets up the next fetchChanges to fail with this error
125 - (void)failNextFetchWith:(NSError*)fetchChangesError;
126
127 // Get the next fetchChanges error. Returns NULL if the fetchChanges should succeed.
128 - (NSError* _Nullable)popFetchChangesError;
129
130 // Checks if this record add/modification should fail
131 - (NSError* _Nullable)errorFromSavingRecord:(CKRecord*)record;
132 @end
133
134 @interface FakeCKKSNotifier : NSObject <CKKSNotifier>
135 @end
136
137 NS_ASSUME_NONNULL_END
138
139 #endif /* OCTAGON */