/ tests / SecDbBackupTests / SecDbBackupTestsBase.m
SecDbBackupTestsBase.m
 1  #import "SecDbBackupTestsBase.h"
 2  
 3  static int checkV12DevEnabledOn(void) {
 4      return 1;
 5  }
 6  
 7  static int checkV12DevEnabledOff(void) {
 8  	return 0;
 9  }
10  
11  NSString* _uuidstring;
12  
13  @implementation SecDbBackupTestsBase {
14  	NSString* _testHomeDirectory;
15  }
16  
17  + (void)setV12Development:(BOOL)newState {
18  	if (newState) {
19  		checkV12DevEnabled = checkV12DevEnabledOn;
20  	} else {
21  		checkV12DevEnabled = checkV12DevEnabledOff;
22  	}
23  }
24  
25  + (void)setUp {
26      [super setUp];
27      checkV12DevEnabled = checkV12DevEnabledOn;
28      SecCKKSDisable();
29  #if OCTAGON
30      SecCKKSTestSetDisableSOS(true);
31  #endif
32  	_uuidstring = [[NSUUID UUID] UUIDString];
33  }
34  
35  - (void)setUp {
36      NSString* testName = [self.name componentsSeparatedByString:@" "][1];
37      testName = [testName stringByReplacingOccurrencesOfString:@"]" withString:@""];
38      secnotice("secdbbackuptest", "Beginning test %@", testName);
39  
40      // Make a new fake keychain
41      NSError* error;
42      _testHomeDirectory = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@/%@/", _uuidstring, testName]];
43  
44      NSLog(@"%@", _testHomeDirectory);
45  
46      [[NSFileManager defaultManager] createDirectoryAtPath:_testHomeDirectory
47                                withIntermediateDirectories:YES
48                                                 attributes:nil
49                                                      error:&error];
50  
51  	XCTAssertNil(error, "Could not make directory at %@", _testHomeDirectory);
52  
53      SecSetCustomHomeURLString((__bridge CFStringRef)_testHomeDirectory);
54      static dispatch_once_t onceToken;
55      dispatch_once(&onceToken, ^{
56          securityd_init(NULL);
57      });
58      SecKeychainDbReset(NULL);
59  
60      // Actually load the database.
61      kc_with_dbt(true, NULL, ^bool (SecDbConnectionRef dbt) { return false; });
62  }
63  
64  - (void)tearDown {
65      // Put teardown code here. This method is called after the invocation of each test method in the class.
66  }
67  
68  + (void)tearDown {
69      SecSetCustomHomeURL(NULL);
70      SecKeychainDbReset(NULL);
71      resetCheckV12DevEnabled();
72  }
73  
74  @end