]> git.saurik.com Git - apple/security.git/blob - SecurityTests/regressions/kc/kc-11-unlock-referral.c
Security-57031.1.35.tar.gz
[apple/security.git] / SecurityTests / regressions / kc / kc-11-unlock-referral.c
1 #include <stdlib.h>
2 #include <Security/SecKeychain.h>
3
4 #include "testmore.h"
5 #include "testenv.h"
6
7 int main(int argc, char *const *argv)
8 {
9 int dont_skip = argc > 1 && !strcmp(argv[1], "-s");
10
11 plan_tests(10);
12
13 ok_status(SecKeychainSetUserInteractionAllowed(FALSE), "disable ui");
14 if (!tests_begin(argc, argv))
15 BAIL_OUT("tests_begin failed");
16
17 char *home = getenv("HOME");
18 char source[256], dest[256];
19 if (!home || strlen(home) > 200)
20 plan_skip_all("home too big");
21
22 sprintf(source, "%s/source", home);
23 sprintf(dest, "%s/dest", home);
24 SecKeychainRef sourcekc = NULL, destkc = NULL;
25 ok_status(SecKeychainCreate(source, 4, "test", FALSE, NULL, &sourcekc),
26 "SecKeychainCreate source");
27 ok_status(SecKeychainCreate(dest, 4, "test", FALSE, NULL, &destkc),
28 "SecKeychainCreate dest");
29 char cmdbuf[1024];
30 ok_unix(sprintf(cmdbuf, "systemkeychain -k '%s' -s '%s'", dest, source),
31 "sprintf");
32 SKIP: {
33 skip("systemkeychain brings up UI", 1, dont_skip);
34
35 ok_unix(system(cmdbuf), "systemkeychain");
36 }
37 ok_status(SecKeychainLock(sourcekc), "SecKeychainLock source");
38 SKIP: {
39 skip("unlocking a source keychain w/ referal before reopen brings "
40 "up ui", 1, dont_skip);
41 TODO: {
42 todo("<rdar://problem/4066169> Unlocking a source "
43 "keychain w/ referal before reopen fails");
44
45 ok_status(SecKeychainUnlock(sourcekc, 0, NULL, FALSE),
46 "SecKeychainUnlock source");
47 }
48 }
49 CFRelease(sourcekc);
50 sourcekc = NULL;
51 char source2[256];
52 sprintf(source2, "%s/source2", home);
53 ok_unix(rename(source, source2), "rename source -> source2");
54 ok_status(SecKeychainOpen(source2, &sourcekc), "SecKeychainOpen source2");
55 SKIP: {
56 skip("systemkeychain brings up UI", 1, dont_skip);
57
58 ok_status(SecKeychainUnlock(sourcekc, 0, NULL, FALSE),
59 "SecKeychainUnlock source2");
60 }
61 CFRelease(sourcekc);
62
63 return !tests_end(1);
64 }