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