7 #import "SecKeybagSupport.h"
8 #import "SecDbKeychainItem.h"
9 #import "SecdTestKeychainUtilities.h"
11 #import "SecItemPriv.h"
12 #import "SecItemServer.h"
14 #import <utilities/SecCFWrappers.h>
15 #import <utilities/SecFileLocations.h>
16 #import <SecurityFoundation/SFEncryptionOperation.h>
17 #import <XCTest/XCTest.h>
18 #import <OCMock/OCMock.h>
22 #import "mockaksxcbase.h"
24 NSString* homeDirUUID;
26 @implementation mockaksxcbase
34 * Disable all of SOS syncing since that triggers retains of database
35 * and these tests muck around with the database over and over again, so
36 * that leads to the vnode delete kevent trap triggering for sqlite
37 * over and over again.
40 SecCKKSTestSetDisableSOS(true);
42 // Give this test run a UUID within which each test has a directory
43 homeDirUUID = [[NSUUID UUID] UUIDString];
46 - (NSString*)createKeychainDirectoryWithSubPath:(NSString*)suffix
49 NSString* dir = suffix ? [NSString stringWithFormat:@"%@/%@/", self.testHomeDirectory, suffix] : self.testHomeDirectory;
50 [[NSFileManager defaultManager] createDirectoryAtPath:dir
51 withIntermediateDirectories:YES
54 XCTAssertNil(error, "Unable to create directory: %@", error);
58 - (void)createKeychainDirectory
60 [self createKeychainDirectoryWithSubPath:nil];
66 NSString* testName = [self.name componentsSeparatedByString:@" "][1];
67 testName = [testName stringByReplacingOccurrencesOfString:@"]" withString:@""];
68 secnotice("ckkstest", "Beginning test %@", testName);
70 self.testHomeDirectory = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@/%@/", homeDirUUID, testName]];
71 [self createKeychainDirectory];
73 SetCustomHomeURLString((__bridge CFStringRef) self.testHomeDirectory);
74 static dispatch_once_t onceToken;
75 dispatch_once(&onceToken, ^{
78 SecKeychainDbReset(NULL);
80 // Actually load the database.
81 kc_with_dbt(true, NULL, ^bool (SecDbConnectionRef dbt) { return false; });
86 SetCustomHomeURLString(NULL);
87 SecKeychainDbReset(NULL);