2 * Copyright (c) 2016 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
24 #import <XCTest/XCTest.h>
25 #import <CloudKit/CloudKit.h>
26 #import <CloudKit/CloudKit_Private.h>
28 #import <Foundation/Foundation.h>
30 #import "keychain/ckks/tests/MockCloudKit.h"
31 #import "keychain/ckks/CKKSCKAccountStateTracker.h"
34 @
class CKKSCKRecordHolder
;
35 @
class CKKSKeychainView
;
36 @
class CKKSViewManager
;
38 @
class CKKSLockStateTracker
;
40 @interface CloudKitMockXCTest
: XCTestCase
44 @property CKRecordZoneID
* testZoneID
;
46 @property id mockDatabase
;
47 @property id mockContainer
;
48 @property id mockFakeCKModifyRecordZonesOperation
;
49 @property id mockFakeCKModifySubscriptionsOperation
;
50 @property id mockFakeCKFetchRecordZoneChangesOperation
;
52 @property id mockAccountStateTracker
;
54 @property CKAccountStatus accountStatus
;
55 @property BOOL supportsDeviceToDeviceEncryption
;
56 @property SOSCCStatus circleStatus
;
57 @
property (readonly
) NSString
* ckDeviceID
;
58 @
property (readonly
) CKKSCKAccountStateTracker
* accountStateTracker
;
60 @property NSString
* circlePeerID
;
62 @property
bool aksLockState
; // The current 'AKS lock state'
63 @
property (readonly
) CKKSLockStateTracker
* lockStateTracker
;
64 @property id mockLockStateTracker
;
66 @property NSMutableDictionary
<CKRecordZoneID
*, FakeCKZone
*>* zones
;
68 @property NSOperationQueue
* operationQueue
;
69 @property NSBlockOperation
* ckksHoldOperation
;
70 @property NSBlockOperation
* ckaccountHoldOperation
;
72 @property NSBlockOperation
* ckModifyHoldOperation
;
74 @property
bool silentFetchesAllowed
;
76 @property id mockCKKSViewManager
;
77 @property CKKSViewManager
* injectedManager
;
79 - (CKKSKey
*) fakeTLK
: (CKRecordZoneID
*)zoneID
;
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
;
89 - (void)expectCKModifyItemRecords
:(NSUInteger
)expectedNumberOfModifiedRecords
90 deletedRecords
:(NSUInteger
)expectedNumberOfDeletedRecords
91 currentKeyPointerRecords
:(NSUInteger
)expectedCurrentKeyRecords
92 zoneID
:(CKRecordZoneID
*)zoneID
93 checkItem
:(BOOL (^)(CKRecord
*))checkItem
;
95 - (void)expectCKDeleteItemRecords
: (NSUInteger
) expectedNumberOfRecords zoneID
: (CKRecordZoneID
*) zoneID
;
97 - (void)expectCKModifyKeyRecords
: (NSUInteger
) expectedNumberOfRecords
98 currentKeyPointerRecords
: (NSUInteger
) expectedCurrentKeyRecords
99 zoneID
: (CKRecordZoneID
*) zoneID
;
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
;
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
;
112 - (void)failNextZoneCreation
:(CKRecordZoneID
*)zoneID
;
113 - (void)failNextZoneCreationSilently
:(CKRecordZoneID
*)zoneID
;
114 - (void)failNextZoneSubscription
:(CKRecordZoneID
*)zoneID
;
115 - (void)failNextZoneSubscription
:(CKRecordZoneID
*)zoneID withError
:(NSError
*)error
;
117 // Use this to assert that a fetch occurs (especially if silentFetchesAllowed = false)
118 - (void)expectCKFetch
;
120 // Wait until all scheduled cloudkit operations are reflected in the currentDatabase
121 - (void)waitForCKModifications
;
123 // Unblocks the CKKS subsystem only.
124 - (void)startCKKSSubsystemOnly
;
126 // Unblocks the CKAccount mock subsystem. Until this is called, the tests believe cloudd hasn't returned any account status yet.
127 - (void)startCKAccountStatusMock
;
129 // Starts everything.
130 - (void)startCKKSSubsystem
;
132 // Blocks the completion (partial or full) of CloudKit modifications
133 -(void)holdCloudKitModifications
;
135 // Unblocks the hold you've added with holdCloudKitModifications; CloudKit modifications will finish
136 -(void)releaseCloudKitModificationHold
;