]> git.saurik.com Git - apple/security.git/blob - SecurityTests/regressions/kc/kc-26-is-valid.c
Security-57031.1.35.tar.gz
[apple/security.git] / SecurityTests / regressions / kc / kc-26-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 "testmore.h"
10 #include "testenv.h"
11 #include "testleaks.h"
12
13 static void tests(void)
14 {
15 char *home = getenv("HOME");
16 char kcname1[256], kcname2[256];
17
18 if (!home || strlen(home) > 200)
19 plan_skip_all("home too big");
20
21 sprintf(kcname1, "%s/kc1", home);
22 SecKeychainRef kc1 = NULL, kc2 = NULL;
23 Boolean kc1valid, kc2valid;
24 ok_status(SecKeychainCreate(kcname1, 4, "test", FALSE, NULL, &kc1),
25 "SecKeychainCreate kc1");
26 ok_status(SecKeychainIsValid(kc1, &kc1valid), "SecKeychainIsValid kc1");
27 is(kc1valid, TRUE, "is kc1 valid");
28 CFRelease(kc1);
29
30 int fd;
31 sprintf(kcname2, "%s/kc2", 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 CFRelease(kc2);
44
45 tests_end(1);
46 }
47
48 int main(int argc, char *const *argv)
49 {
50 plan_tests(9);
51 if (!tests_begin(argc, argv))
52 BAIL_OUT("tests_begin failed");
53
54 tests();
55
56 ok_leaks("leaks");
57
58 return 0;
59 }