7 #import "SecKeybagSupport.h"
8 #import "SecDbKeychainItem.h"
9 #import "SecdTestKeychainUtilities.h"
11 #import "SecItemPriv.h"
12 #import "SecItemServer.h"
14 #include <ipc/server_security_helpers.h>
15 #import <utilities/SecCFWrappers.h>
16 #import <utilities/SecFileLocations.h>
17 #import <SecurityFoundation/SFEncryptionOperation.h>
18 #import <XCTest/XCTest.h>
19 #import <OCMock/OCMock.h>
23 #import "mockaksxcbase.h"
25 NSString* homeDirUUID;
27 @interface mockaksxcbase ()
28 @property NSArray<NSString *>* originalAccessGroups;
29 @property NSMutableArray<NSString *>* currentAccessGroups;
33 @implementation mockaksxcbase
39 securityd_init_local_spi();
44 * Disable all of SOS syncing since that triggers retains of database
45 * and these tests muck around with the database over and over again, so
46 * that leads to the vnode delete kevent trap triggering for sqlite
47 * over and over again.
50 SecCKKSTestSetDisableSOS(true);
53 // Give this test run a UUID within which each test has a directory
54 homeDirUUID = [[NSUUID UUID] UUIDString];
57 - (void)addAccessGroup:(NSString *)accessGroup
59 [self.currentAccessGroups addObject:accessGroup];
60 SecAccessGroupsSetCurrent((__bridge CFArrayRef)self.currentAccessGroups);
63 - (NSString*)createKeychainDirectoryWithSubPath:(NSString*)suffix
66 NSString* dir = suffix ? [NSString stringWithFormat:@"%@/%@/", self.testHomeDirectory, suffix] : self.testHomeDirectory;
67 [[NSFileManager defaultManager] createDirectoryAtPath:dir
68 withIntermediateDirectories:YES
71 XCTAssertNil(error, "Unable to create directory: %@", error);
75 - (void)createKeychainDirectory
77 [self createKeychainDirectoryWithSubPath:nil];
82 self.originalAccessGroups = (__bridge NSArray *)SecAccessGroupsGetCurrent();
83 self.currentAccessGroups = [self.originalAccessGroups mutableCopy];
85 NSString* testName = [self.name componentsSeparatedByString:@" "][1];
86 testName = [testName stringByReplacingOccurrencesOfString:@"]" withString:@""];
87 secnotice("ckkstest", "Beginning test %@", testName);
89 self.testHomeDirectory = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@/%@/", homeDirUUID, testName]];
90 [self createKeychainDirectory];
92 SetCustomHomeURLString((__bridge CFStringRef) self.testHomeDirectory);
93 SecKeychainDbReset(NULL);
95 // Actually load the database.
96 kc_with_dbt(true, NULL, ^bool (SecDbConnectionRef dbt) { return false; });
101 SecAccessGroupsSetCurrent((__bridge CFArrayRef)self.originalAccessGroups);
107 SetCustomHomeURLString(NULL);
108 SecKeychainDbReset(NULL);