]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_keychain/regressions/kc-04-is-valid.c
Security-59306.11.20.tar.gz
[apple/security.git] / OSX / libsecurity_keychain / regressions / kc-04-is-valid.c
1 #include <Security/SecKeychain.h>
2 #include <Security/SecKeychainPriv.h>
3 #include <fcntl.h>
4 #include <stdlib.h>
5 #include <sys/stat.h>
6 #include <sys/types.h>
7 #include <unistd.h>
8
9 #include "keychain_regressions.h"
10 #include "kc-helpers.h"
11
12 static void tests(void)
13 {
14 char *home = getenv("HOME");
15 char kcname1[256], kcname2[256];
16
17 if (!home || strlen(home) > 200)
18 plan_skip_all("home too big");
19
20 sprintf(kcname1, "%s/kctests/kc1-16-is-valid", home);
21 SecKeychainRef kc1 = NULL, kc2 = NULL;
22 Boolean kc1valid, kc2valid;
23 kc1 = createNewKeychainAt(kcname1, "test");
24 ok_status(SecKeychainIsValid(kc1, &kc1valid), "SecKeychainIsValid kc1");
25 is(kc1valid, TRUE, "is kc1 valid");
26
27 ok_status(SecKeychainDelete(kc1), "%s: SecKeychainDelete", testName);
28 CFRelease(kc1);
29
30 int fd;
31 sprintf(kcname2, "%s/kctests/kc2-16-is-valid", home);
32 ok_unix(fd = open(kcname2, O_CREAT|O_WRONLY|O_TRUNC, 0600),
33 "create invalid kc2 file");
34 ok_unix(close(fd), "close the kc2 file");
35 ok_status(SecKeychainOpen(kcname2, &kc2), "SecKeychainOpen kc2");
36
37 ok_status(SecKeychainIsValid(kc2, &kc2valid), "SecKeychainIsValid kc2");
38 TODO: {
39 todo("<rdar://problem/3795566> SecKeychainIsValid always returns "
40 "TRUE");
41 is(kc2valid, FALSE, "is kc2 not valid");
42 }
43
44 ok_status(SecKeychainDelete(kc2), "%s: SecKeychainDelete", testName);
45 CFRelease(kc2);
46 }
47
48 int kc_04_is_valid(int argc, char *const *argv)
49 {
50 plan_tests(11);
51
52 tests();
53
54 deleteTestFiles();
55 return 0;
56 }