1 #include <Security/SecKeychain.h>
2 #include <Security/SecKeychainItem.h>
10 void tests(int dont_skip
)
12 SecKeychainRef keychain
;
13 ok_status(SecKeychainCreate("test", 4, "test", FALSE
, NULL
, &keychain
),
15 SecKeychainItemRef item
= NULL
;
16 ok_status(SecKeychainAddInternetPassword(keychain
,
17 19, "members.spamcop.net",
21 80, kSecProtocolTypeHTTP
,
22 kSecAuthenticationTypeDefault
,
23 4, "test", &item
), "add internet password");
24 ok(item
, "is item non NULL");
25 SecKeychainItemRef oldItem
= item
;
26 is_status(SecKeychainAddInternetPassword(keychain
,
27 19, "members.spamcop.net",
31 80, kSecProtocolTypeHTTP
,
32 kSecAuthenticationTypeDefault
,
33 4, "test", &item
), errSecDuplicateItem
, "add internet password again");
34 is((intptr_t)item
, (intptr_t)oldItem
, "item is unchanged");
38 ok_status(SecKeychainFindInternetPassword(NULL
,
39 19, "members.spamcop.net",
45 kSecAuthenticationTypeDefault
,
47 &item
), "find internet password");
49 SecItemClass itemClass
= 0;
50 SecKeychainAttribute attrs
[] =
52 { kSecAccountItemAttr
},
53 { kSecSecurityDomainItemAttr
},
54 { kSecServerItemAttr
}
56 SecKeychainAttributeList attrList
=
58 sizeof(attrs
) / sizeof(*attrs
),
61 ok_status(SecKeychainItemCopyContent(item
, &itemClass
, &attrList
,
62 NULL
, NULL
), "SecKeychainItemCopyContent");
63 is(itemClass
, kSecInternetPasswordItemClass
, "is internet password?");
64 is(attrs
[0].length
, 5, "account len");
65 ok(!strncmp(attrs
[0].data
, "smith", 5), "account eq smith");
66 is(attrs
[1].length
, 0, "security domain len");
67 is(attrs
[2].length
, 19, "server len");
68 ok(!strncmp(attrs
[2].data
, "members.spamcop.net", 19),
69 "servername eq members.spamcop.net");
70 ok_status(SecKeychainItemFreeContent(&attrList
, NULL
),
71 "SecKeychainItemCopyContent");
73 SecKeychainAttribute attrs2
[] =
75 { kSecAccountItemAttr
},
76 { kSecServiceItemAttr
},
77 { kSecSecurityDomainItemAttr
},
78 { kSecServerItemAttr
}
80 SecKeychainAttributeList attrList2
=
82 (sizeof(attrs2
) / sizeof(*attrs2
)),
86 skip("<rdar://problem/3298182> 6L60 Malloc/free misuse in "
87 "SecKeychainItemCopyContent()", 1, dont_skip
);
88 is_status(SecKeychainItemCopyContent(item
, &itemClass
, &attrList2
,
89 NULL
, NULL
), errSecNoSuchAttr
, "SecKeychainItemCopyContent fails");
92 is(CFGetRetainCount(item
), 1, "item retaincount is 1");
93 is(CFGetRetainCount(keychain
), 2, "keychain retaincount is 2");
95 is(CFGetRetainCount(keychain
), 1, "keychain retaincount is 1");
96 ok_status(SecKeychainDelete(keychain
), "delete keychain");
100 int main(int argc
, char *const *argv
)
102 int dont_skip
= argc
> 1 && !strcmp(argv
[1], "-s");
106 if (!tests_begin(argc
, argv
))
107 BAIL_OUT("tests_begin failed");
110 ok(tests_end(1), "cleanup");
111 ok_leaks("no leaks");