]> git.saurik.com Git - apple/security.git/blob - keychain/ckks/tests/MockCloudKit.h
Security-58286.51.6.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 @property (nullable) NSError* creationError;
42 @property (nonatomic, nullable) NSMutableArray<CKRecordZone*>* recordZonesSaved;
43 @property (nonatomic, nullable) NSMutableArray<CKRecordZoneID*>* recordZoneIDsDeleted;
44 + (FakeCKDatabase*)ckdb;
45 +(void)ensureZoneDeletionAllowed:(FakeCKZone*)zone;
46 @end
47
48 @interface FakeCKModifySubscriptionsOperation : NSBlockOperation <CKKSModifySubscriptionsOperation>
49 @property (nullable) NSError* subscriptionError;
50 @property (nonatomic, nullable) NSMutableArray<CKSubscription*>* subscriptionsSaved;
51 @property (nonatomic, nullable) NSMutableArray<NSString*>* subscriptionIDsDeleted;
52 + (FakeCKDatabase*)ckdb;
53 @end
54
55 @interface FakeCKFetchRecordZoneChangesOperation : NSOperation <CKKSFetchRecordZoneChangesOperation>
56 + (FakeCKDatabase*)ckdb;
57 @property (nullable) void (^blockAfterFetch)();
58 @end
59
60 @interface FakeCKFetchRecordsOperation : NSBlockOperation <CKKSFetchRecordsOperation>
61 + (FakeCKDatabase*)ckdb;
62 @end
63
64 @interface FakeCKQueryOperation : NSBlockOperation <CKKSQueryOperation>
65 + (FakeCKDatabase*)ckdb;
66 @end
67
68 @interface FakeAPSConnection : NSObject <CKKSAPSConnection>
69 @end
70
71 @interface FakeNSNotificationCenter : NSObject <CKKSNSNotificationCenter>
72 + (instancetype)defaultCenter;
73 - (void)addObserver:(id)observer selector:(SEL)aSelector name:(nullable NSNotificationName)aName object:(nullable id)anObject;
74 @end
75
76 @interface FakeCKZone : NSObject
77 // 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
78 @property CKRecordZoneID* zoneID;
79 @property CKServerChangeToken* currentChangeToken;
80 @property NSMutableDictionary<CKRecordID*, CKRecord*>* currentDatabase;
81 @property NSMutableDictionary<CKServerChangeToken*, NSMutableDictionary<CKRecordID*, CKRecord*>*>* pastDatabases;
82 @property bool flag; // used however you'd like in a test
83
84 // Usually nil. If set, trying to 'create' this zone should fail.
85 @property (nullable) NSError* creationError;
86
87 // Usually false. If set, trying to 'create' this should should 1) pretend to succeed but 2) delete this zone from existence
88 @property bool failCreationSilently;
89
90 // Usually nil. If set, trying to subscribe to this zone should fail.
91 @property (nullable) NSError* subscriptionError;
92
93 - (instancetype)initZone:(CKRecordZoneID*)zoneID;
94
95 - (void)rollChangeToken;
96
97 // Always Succeed
98 - (void)addToZone:(CKKSCKRecordHolder*)item zoneID:(CKRecordZoneID*)zoneID;
99 - (void)addToZone:(CKRecord*)record;
100
101 // Removes this record from all versions of the CK database, without changing the change tag
102 - (void)deleteFromHistory:(CKRecordID*)recordID;
103
104 - (void)addCKRecordToZone:(CKRecord*)record;
105 - (NSError* _Nullable)deleteCKRecordIDFromZone:(CKRecordID*)recordID;
106
107 // Sets up the next fetchChanges to fail with this error
108 - (void)failNextFetchWith:(NSError*)fetchChangesError;
109
110 // Get the next fetchChanges error. Returns NULL if the fetchChanges should succeed.
111 - (NSError* _Nullable)popFetchChangesError;
112
113 // Checks if this record add/modification should fail
114 - (NSError* _Nullable)errorFromSavingRecord:(CKRecord*)record;
115 @end
116
117 @interface FakeCKKSNotifier : NSObject <CKKSNotifier>
118 @end
119
120 NS_ASSUME_NONNULL_END
121
122 #endif /* OCTAGON */