]> git.saurik.com Git - apple/security.git/blob - SecurityTests/regressions/kc/kc-23-item-notify.c
Security-57031.1.35.tar.gz
[apple/security.git] / SecurityTests / regressions / kc / kc-23-item-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 static char account[] = "account";
12 static char service[] = "service";
13 static char password[] = "password";
14
15 void tests(int dont_skip)
16 {
17 SecKeychainRef keychain = NULL;
18 ok_status(SecKeychainCreate("test", 4, "test", FALSE, NULL, &keychain),
19 "create keychain");
20 ok_status(test_sec_event_register(kSecEveryEventMask),
21 "register for all events");
22 SecKeychainItemRef itemRef;
23 ok_status(SecKeychainAddGenericPassword(keychain,
24 sizeof(account), account,
25 sizeof(service), service,
26 sizeof(password), password,
27 &itemRef),
28 "add generic password, wait for callback");
29 SecKeychainRef eventKeychain = NULL;
30 SecKeychainItemRef eventItem = NULL;
31 is_sec_event(kSecAddEvent, &eventKeychain, &eventItem, NULL,
32 "add event");
33 is(eventItem, itemRef, "add event item matches");
34 is(eventKeychain, keychain, "add event keychain matches");
35 CFRelease(eventKeychain);
36 eventKeychain = NULL;
37 CFRelease(eventItem);
38 eventItem = NULL;
39
40 ok_status(SecKeychainItemDelete(itemRef), "delete item");
41 is_sec_event(kSecDeleteEvent, &eventKeychain, &eventItem, NULL,
42 "delete event");
43 is(eventItem, itemRef, "delete event item matches");
44 is(eventKeychain, keychain, "delete event keychain matches");
45 if (eventKeychain != NULL) // eventKeychain can be null if the test times out
46 {
47 CFRelease(eventKeychain);
48 eventKeychain = NULL;
49 }
50
51 if (eventItem != NULL)
52 {
53 CFRelease(eventItem);
54 eventItem = NULL;
55 }
56
57 no_sec_event("no event");
58 ok_status(test_sec_event_deregister(), "deregister events.");
59
60 CFRelease(itemRef);
61 CFRelease(keychain);
62
63
64 ok(tests_end(1), "cleanup");
65 }
66
67 int main(int argc, char *const *argv)
68 {
69 #ifdef DEBUG
70 int dont_skip = argc > 1 && !strcmp(argv[1], "-s");
71 plan_tests(14);
72
73 if (!tests_begin(argc, argv))
74 BAIL_OUT("tests_begin failed");
75
76 tests(dont_skip);
77 ok_leaks("no leaks");
78 #endif
79 plan_tests(1);
80 ok_leaks("no leaks");
81
82 return 0;
83 }