]> git.saurik.com Git - apple/security.git/blobdiff - keychain/ckks/tests/MockCloudKit.h
Security-59306.41.2.tar.gz
[apple/security.git] / keychain / ckks / tests / MockCloudKit.h
index 5bc654fd4b7256ac1317e10aec384cf8b4a782a6..b551e87a2ca55f2211836f204fbf6430fc901bed 100644 (file)
  * @APPLE_LICENSE_HEADER_END@
  */
 
+#if OCTAGON
 
 #import <CloudKit/CloudKit.h>
+#import <CloudKit/CloudKit_Private.h>
 #import <Foundation/Foundation.h>
 
 #import "keychain/ckks/CKKSNotifier.h"
@@ -35,35 +37,55 @@ NS_ASSUME_NONNULL_BEGIN
 
 typedef NSMutableDictionary<CKRecordZoneID*, FakeCKZone*> FakeCKDatabase;
 
+@interface FakeCKOperation : NSBlockOperation
+@property (nonatomic, assign, readonly) BOOL isFinishingOnCallbackQueue;
+@end
+
 
-@interface FakeCKModifyRecordZonesOperation : NSBlockOperation <CKKSModifyRecordZonesOperation>
+@interface FakeCKModifyRecordZonesOperation : FakeCKOperation <CKKSModifyRecordZonesOperation> {
+    CKOperationConfiguration* _configuration;
+}
 @property (nullable) NSError* creationError;
 @property (nonatomic, nullable) NSMutableArray<CKRecordZone*>* recordZonesSaved;
 @property (nonatomic, nullable) NSMutableArray<CKRecordZoneID*>* recordZoneIDsDeleted;
+@property (nonatomic, copy, null_resettable) CKOperationConfiguration *configuration;
+
 + (FakeCKDatabase*)ckdb;
+
++ (NSError* _Nullable)shouldFailModifyRecordZonesOperation;
+
++ (void)ensureZoneDeletionAllowed:(FakeCKZone*)zone;
 @end
 
-@interface FakeCKModifySubscriptionsOperation : NSBlockOperation <CKKSModifySubscriptionsOperation>
+@interface FakeCKModifySubscriptionsOperation : FakeCKOperation <CKKSModifySubscriptionsOperation> {
+    CKOperationConfiguration* _configuration;
+}
 @property (nullable) NSError* subscriptionError;
 @property (nonatomic, nullable) NSMutableArray<CKSubscription*>* subscriptionsSaved;
 @property (nonatomic, nullable) NSMutableArray<NSString*>* subscriptionIDsDeleted;
+@property (nonatomic, copy, null_resettable) CKOperationConfiguration *configuration;
 + (FakeCKDatabase*)ckdb;
 @end
 
-@interface FakeCKFetchRecordZoneChangesOperation : NSOperation <CKKSFetchRecordZoneChangesOperation>
+@interface FakeCKFetchRecordZoneChangesOperation : FakeCKOperation <CKKSFetchRecordZoneChangesOperation> {
+    CKOperationConfiguration* _configuration;
+}
+
 + (FakeCKDatabase*)ckdb;
-@property (nullable) void (^blockAfterFetch)();
+@property (nonatomic, copy) NSString *operationID;
+@property (nonatomic, readonly, strong, nullable) CKOperationConfiguration *resolvedConfiguration;
+@property (nullable) void (^blockAfterFetch)(void);
 @end
 
-@interface FakeCKFetchRecordsOperation : NSBlockOperation <CKKSFetchRecordsOperation>
+@interface FakeCKFetchRecordsOperation : FakeCKOperation <CKKSFetchRecordsOperation>
 + (FakeCKDatabase*)ckdb;
 @end
 
-@interface FakeCKQueryOperation : NSBlockOperation <CKKSQueryOperation>
+@interface FakeCKQueryOperation : FakeCKOperation <CKKSQueryOperation>
 + (FakeCKDatabase*)ckdb;
 @end
 
-@interface FakeAPSConnection : NSObject <CKKSAPSConnection>
+@interface FakeAPSConnection : NSObject <OctagonAPSConnection>
 @end
 
 @interface FakeNSNotificationCenter : NSObject <CKKSNSNotificationCenter>
@@ -71,6 +93,9 @@ typedef NSMutableDictionary<CKRecordZoneID*, FakeCKZone*> FakeCKDatabase;
 - (void)addObserver:(id)observer selector:(SEL)aSelector name:(nullable NSNotificationName)aName object:(nullable id)anObject;
 @end
 
+@interface FakeNSDistributedNotificationCenter : NSObject <CKKSNSDistributedNotificationCenter>
+@end
+
 @interface FakeCKZone : NSObject
 // 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
 @property CKRecordZoneID* zoneID;
@@ -78,6 +103,10 @@ typedef NSMutableDictionary<CKRecordZoneID*, FakeCKZone*> FakeCKDatabase;
 @property NSMutableDictionary<CKRecordID*, CKRecord*>* currentDatabase;
 @property NSMutableDictionary<CKServerChangeToken*, NSMutableDictionary<CKRecordID*, CKRecord*>*>* pastDatabases;
 @property bool flag;  // used however you'd like in a test
+@property (nullable) CKServerChangeToken* limitFetchTo; // Only return partial results up until here (if asking for current change token)
+@property (nullable) NSError* limitFetchError; // If limitFetchTo fires, finish the operation with this error (likely a network timeout)
+@property int fetchRecordZoneChangesOperationCount;
+@property NSMutableArray<NSDate*>* fetchRecordZoneChangesTimestamps;
 
 // Usually nil. If set, trying to 'create' this zone should fail.
 @property (nullable) NSError* creationError;
@@ -88,14 +117,19 @@ typedef NSMutableDictionary<CKRecordZoneID*, FakeCKZone*> FakeCKDatabase;
 // Usually nil. If set, trying to subscribe to this zone should fail.
 @property (nullable) NSError* subscriptionError;
 
-- (instancetype)initZone:(CKRecordZoneID*)zoneID;
+// Serial queue. Use this for transactionality.
+@property dispatch_queue_t queue;
 
-- (void)rollChangeToken;
+- (instancetype)initZone:(CKRecordZoneID*)zoneID;
 
 // Always Succeed
 - (void)addToZone:(CKKSCKRecordHolder*)item zoneID:(CKRecordZoneID*)zoneID;
 - (void)addToZone:(CKRecord*)record;
 
+// If you want a transaction of adding, use these
+- (CKRecord*)_onqueueAddToZone:(CKKSCKRecordHolder*)item zoneID:(CKRecordZoneID*)zoneID;
+- (CKRecord*)_onqueueAddToZone:(CKRecord*)record;
+
 // Removes this record from all versions of the CK database, without changing the change tag
 - (void)deleteFromHistory:(CKRecordID*)recordID;
 
@@ -116,3 +150,5 @@ typedef NSMutableDictionary<CKRecordZoneID*, FakeCKZone*> FakeCKDatabase;
 @end
 
 NS_ASSUME_NONNULL_END
+
+#endif /* OCTAGON */