]>
Commit | Line | Data |
---|---|---|
fa7225c8 A |
1 | // |
2 | // si-15-delete-access-group.m | |
3 | // sec | |
4 | // | |
5 | // Created by Love Hörnquist Åstrand on 2016-06-28. | |
6 | // | |
7 | // | |
8 | ||
9 | #import <Foundation/Foundation.h> | |
10 | #include <Security/Security.h> | |
11 | #include <Security/SecItemPriv.h> | |
12 | #include <unistd.h> | |
13 | ||
14 | #include "Security_regressions.h" | |
15 | ||
16 | ||
17 | int si_15_delete_access_group(int argc, char *const *argv) | |
18 | { | |
866f8763 | 19 | plan_tests(11); |
fa7225c8 A |
20 | |
21 | @autoreleasepool { | |
22 | NSDictionary *query = NULL, *item = NULL; | |
23 | NSDictionary *query2 = NULL, *item2 = NULL; | |
24 | NSString *agrp = @"123456.test.group"; | |
25 | NSString *agrp2 = @"123456.test.group2"; | |
26 | CFErrorRef error = NULL; | |
27 | ||
28 | /* | |
29 | * Clean first | |
30 | */ | |
31 | query = @{ | |
32 | (id)kSecClass : (id)kSecClassGenericPassword, | |
33 | (id)kSecAttrLabel : @"keychain label", | |
34 | }; | |
35 | query2 = @{ | |
36 | (id)kSecClass : (id)kSecClassGenericPassword, | |
37 | (id)kSecAttrLabel : @"keychain label2", | |
38 | }; | |
39 | SecItemDelete((CFDictionaryRef)query); | |
40 | SecItemDelete((CFDictionaryRef)query2); | |
41 | ||
42 | /* | |
43 | * Add entry | |
44 | */ | |
45 | ||
46 | item = @{ | |
47 | (id)kSecClass : (id)kSecClassGenericPassword, | |
48 | (id)kSecAttrLabel : @"keychain label", | |
49 | (id)kSecAttrAccessGroup : agrp | |
50 | }; | |
51 | ||
52 | ok_status(SecItemAdd((CFDictionaryRef)item, NULL), "SecItemAdd2"); | |
53 | ||
54 | ok_status(SecItemCopyMatching((CFDictionaryRef)query, NULL)); | |
55 | ||
56 | item2 = @{ | |
57 | (id)kSecClass : (id)kSecClassGenericPassword, | |
58 | (id)kSecAttrLabel : @"keychain label2", | |
59 | (id)kSecAttrAccessGroup : agrp2 | |
60 | }; | |
61 | ||
62 | ok_status(SecItemAdd((CFDictionaryRef)item2, NULL), "SecItemAdd2"); | |
63 | ||
64 | is_status(SecItemCopyMatching((CFDictionaryRef)query, NULL), errSecSuccess); | |
65 | is_status(SecItemCopyMatching((CFDictionaryRef)query2, NULL), errSecSuccess); | |
66 | ||
67 | ||
68 | ok(SecItemDeleteAllWithAccessGroups((__bridge CFArrayRef)@[ agrp ], &error), | |
69 | "SecItemDeleteAllWithAccessGroups: %@", error); | |
70 | ||
71 | if (error) | |
72 | CFRelease(error); | |
73 | ||
74 | is_status(SecItemCopyMatching((CFDictionaryRef)query, NULL), errSecItemNotFound); | |
75 | is_status(SecItemCopyMatching((CFDictionaryRef)query2, NULL), errSecSuccess); | |
76 | ||
77 | ok(SecItemDeleteAllWithAccessGroups((__bridge CFArrayRef)@[ agrp2 ], &error), | |
78 | "SecItemDeleteAllWithAccessGroups: %@", error); | |
79 | ||
80 | if (error) | |
81 | CFRelease(error); | |
82 | ||
83 | is_status(SecItemCopyMatching((CFDictionaryRef)query, NULL), errSecItemNotFound); | |
84 | is_status(SecItemCopyMatching((CFDictionaryRef)query2, NULL), errSecItemNotFound); | |
85 | } | |
86 | ||
87 | return 0; | |
88 | } |