]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_keychain/regressions/kc-10-item-add-internet.c
Security-57740.31.2.tar.gz
[apple/security.git] / OSX / libsecurity_keychain / regressions / kc-10-item-add-internet.c
1 #include <Security/SecKeychain.h>
2 #include <Security/SecKeychainItem.h>
3 #include <stdlib.h>
4 #include <unistd.h>
5
6 #include "keychain_regressions.h"
7 #include "kc-helpers.h"
8
9 static void tests()
10 {
11 SecKeychainRef keychain = createNewKeychain("test", "test");
12 SecKeychainItemRef item = NULL;
13 ok_status(SecKeychainAddInternetPassword(keychain,
14 19, "members.spamcop.net",
15 0, NULL,
16 5, "smith",
17 0, NULL,
18 80, kSecProtocolTypeHTTP,
19 kSecAuthenticationTypeDefault,
20 4, "test", &item), "add internet password");
21 ok(item, "is item non NULL");
22 SecKeychainItemRef oldItem = item;
23 is_status(SecKeychainAddInternetPassword(keychain,
24 19, "members.spamcop.net",
25 0, NULL,
26 5, "smith",
27 0, NULL,
28 80, kSecProtocolTypeHTTP,
29 kSecAuthenticationTypeDefault,
30 4, "test", &item), errSecDuplicateItem, "add internet password again");
31 is((intptr_t)item, (intptr_t)oldItem, "item is unchanged");
32
33 CFRelease(item);
34 item = NULL;
35 ok_status(SecKeychainFindInternetPassword(keychain,
36 19, "members.spamcop.net",
37 0, NULL,
38 0, NULL,
39 0, NULL,
40 80,
41 kSecProtocolTypeHTTP,
42 kSecAuthenticationTypeDefault,
43 NULL, NULL,
44 &item), "find internet password");
45
46 SecItemClass itemClass = 0;
47 SecKeychainAttribute attrs[] =
48 {
49 { kSecAccountItemAttr },
50 { kSecSecurityDomainItemAttr },
51 { kSecServerItemAttr }
52 };
53 SecKeychainAttributeList attrList =
54 {
55 sizeof(attrs) / sizeof(*attrs),
56 attrs
57 };
58 ok_status(SecKeychainItemCopyContent(item, &itemClass, &attrList,
59 NULL, NULL), "SecKeychainItemCopyContent");
60 is(itemClass, kSecInternetPasswordItemClass, "is internet password?");
61 is(attrs[0].length, 5, "account len");
62 ok(!strncmp(attrs[0].data, "smith", 5), "account eq smith");
63 is(attrs[1].length, 0, "security domain len");
64 is(attrs[2].length, 19, "server len");
65 ok(!strncmp(attrs[2].data, "members.spamcop.net", 19),
66 "servername eq members.spamcop.net");
67 ok_status(SecKeychainItemFreeContent(&attrList, NULL),
68 "SecKeychainItemCopyContent");
69
70 SecKeychainAttribute attrs2[] =
71 {
72 { kSecAccountItemAttr },
73 { kSecServiceItemAttr },
74 { kSecSecurityDomainItemAttr },
75 { kSecServerItemAttr }
76 };
77 SecKeychainAttributeList attrList2 =
78 {
79 (sizeof(attrs2) / sizeof(*attrs2)),
80 attrs2
81 };
82 SKIP: {
83 skip("<rdar://problem/3298182> 6L60 Malloc/free misuse in "
84 "SecKeychainItemCopyContent()", 1, 1);
85 is_status(SecKeychainItemCopyContent(item, &itemClass, &attrList2,
86 NULL, NULL), errSecNoSuchAttr, "SecKeychainItemCopyContent fails");
87 }
88
89 is(CFGetRetainCount(item), 1, "item retaincount is 1");
90 cmp_ok(CFGetRetainCount(keychain), >=, 2, "keychain retaincount is at least 2");
91 CFRelease(item);
92 cmp_ok(CFGetRetainCount(keychain), >=, 1, "keychain retaincount is at least 1");
93 ok_status(SecKeychainDelete(keychain), "delete keychain");
94 CFRelease(keychain);
95 }
96
97 int kc_10_item_add_internet(int argc, char *const *argv)
98 {
99 plan_tests(19);
100
101 tests();
102
103 deleteTestFiles();
104 return 0;
105 }