]> git.saurik.com Git - apple/security.git/blob - tests/secdmockaks/mockaksxcbase.m
Security-59306.11.20.tar.gz
[apple/security.git] / tests / secdmockaks / mockaksxcbase.m
1
2 //
3 // mocksecdbase.m
4 // Security
5 //
6
7 #import "SecKeybagSupport.h"
8 #import "SecDbKeychainItem.h"
9 #import "SecdTestKeychainUtilities.h"
10 #import "CKKS.h"
11 #import "SecItemPriv.h"
12 #import "SecItemServer.h"
13 #import "spi.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>
19 #import <sqlite3.h>
20 #import "mockaks.h"
21
22 #import "mockaksxcbase.h"
23
24 NSString* homeDirUUID;
25
26 @implementation mockaksxcbase
27
28 + (void)setUp
29 {
30 [super setUp];
31
32 SecCKKSDisable();
33 /*
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.
38 */
39 #if OCTAGON
40 SecCKKSTestSetDisableSOS(true);
41 #endif
42 // Give this test run a UUID within which each test has a directory
43 homeDirUUID = [[NSUUID UUID] UUIDString];
44 }
45
46 - (NSString*)createKeychainDirectoryWithSubPath:(NSString*)suffix
47 {
48 NSError* error;
49 NSString* dir = suffix ? [NSString stringWithFormat:@"%@/%@/", self.testHomeDirectory, suffix] : self.testHomeDirectory;
50 [[NSFileManager defaultManager] createDirectoryAtPath:dir
51 withIntermediateDirectories:YES
52 attributes:nil
53 error:&error];
54 XCTAssertNil(error, "Unable to create directory: %@", error);
55 return dir;
56 }
57
58 - (void)createKeychainDirectory
59 {
60 [self createKeychainDirectoryWithSubPath:nil];
61 }
62
63 - (void)setUp {
64 [super setUp];
65
66 NSString* testName = [self.name componentsSeparatedByString:@" "][1];
67 testName = [testName stringByReplacingOccurrencesOfString:@"]" withString:@""];
68 secnotice("ckkstest", "Beginning test %@", testName);
69
70 self.testHomeDirectory = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@/%@/", homeDirUUID, testName]];
71 [self createKeychainDirectory];
72
73 SetCustomHomeURLString((__bridge CFStringRef) self.testHomeDirectory);
74 static dispatch_once_t onceToken;
75 dispatch_once(&onceToken, ^{
76 securityd_init(NULL);
77 });
78 SecKeychainDbReset(NULL);
79
80 // Actually load the database.
81 kc_with_dbt(true, NULL, ^bool (SecDbConnectionRef dbt) { return false; });
82 }
83
84 + (void)tearDown
85 {
86 SetCustomHomeURLString(NULL);
87 SecKeychainDbReset(NULL);
88 }
89
90 @end