]> git.saurik.com Git - apple/security.git/blob - SecurityTests/regressions/kc/kc-25-bulk-notify.c
Security-57031.1.35.tar.gz
[apple/security.git] / SecurityTests / regressions / kc / kc-25-bulk-notify.c
1 #include <Security/SecKeychain.h>
2 #include <Security/SecKeychainSearch.h>
3 #include <stdlib.h>
4 #include <unistd.h>
5
6 #include "testenv.h"
7 #include "testleaks.h"
8 #include "testmore.h"
9 #include "testsecevent.h"
10
11 void tests(void)
12 {
13 SecKeychainRef keychain = NULL;
14 ok_status(SecKeychainCreate("test", 4, "test", FALSE, NULL, &keychain),
15 "create keychain");
16 ok_status(test_sec_event_register(kSecEveryEventMask),
17 "register for all events");
18 int item_num;
19 int item_count = 9;
20 for (item_num = 0; item_num < item_count; ++item_num)
21 {
22 char account[64];
23 sprintf(account, "account-%d", item_num);
24 ok_status(SecKeychainAddGenericPassword(keychain, 7, "service",
25 strlen(account), account, 4, "test", NULL),
26 "add generic password");
27 }
28 SecKeychainAttribute attrs[] =
29 { { kSecAccountItemAttr } };
30 SecKeychainAttributeList attrList =
31 { sizeof(attrs) / sizeof(*attrs), attrs };
32
33 for (item_num = 0; item_num < item_count - 2; ++item_num)
34 {
35 char account[64];
36 sprintf(account, "account-%d", item_num);
37 SecKeychainItemRef item = NULL;
38 is_sec_event(kSecAddEvent, NULL, &item, NULL, "got add event");
39
40 SKIP: {
41 skip("no item", 3, item != NULL);
42
43 ok_status(SecKeychainItemCopyContent(item, NULL, &attrList, NULL,
44 NULL), "get content");
45
46 eq_stringn(account, strlen(account), attrs[0].data, attrs[0].length,
47 "account name in notification matches");
48 ok_status(SecKeychainItemFreeContent(&attrList, NULL),
49 "free content");
50 }
51 }
52
53 for (; item_num < item_count; ++item_num)
54 {
55 char account[64];
56 sprintf(account, "account-%d", item_num);
57 SecKeychainItemRef item = NULL;
58 is_sec_event(kSecAddEvent, NULL, &item, NULL, "got add event");
59
60 SKIP: {
61 skip("no item", 3, item != NULL);
62
63 ok_status(SecKeychainItemCopyContent(item, NULL, &attrList, NULL,
64 NULL), "get content");
65 eq_stringn(account, strlen(account), attrs[0].data, attrs[0].length,
66 "account name in notification matches");
67 ok_status(SecKeychainItemFreeContent(&attrList, NULL),
68 "free content");
69 }
70 }
71
72 ok(tests_end(1), "cleanup");
73 }
74
75 int main(int argc, char *const *argv)
76 {
77 #ifdef DEBUG
78 plan_tests(49);
79
80 if (!tests_begin(argc, argv))
81 BAIL_OUT("tests_begin failed");
82
83 tests();
84 ok_leaks("no leaks");
85 #endif
86 plan_tests(1);
87 ok_leaks("no leaks");
88
89 return 0;
90 }