]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_keychain/regressions/kc-19-item-copy-internet.c
Security-59754.80.3.tar.gz
[apple/security.git] / OSX / libsecurity_keychain / regressions / kc-19-item-copy-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 source, dest;
12 source = createNewKeychain("source", "test");
13 dest = createNewKeychain("dest", "test");
14 SecKeychainItemRef original = NULL;
15 ok_status(SecKeychainAddInternetPassword(source,
16 19, "members.spamcop.net",
17 0, NULL,
18 5, "smith",
19 0, NULL,
20 80, kSecProtocolTypeHTTP,
21 kSecAuthenticationTypeDefault,
22 4, "test", &original), "add internet password");
23 SecKeychainAttribute origAttrs[] =
24 {
25 { kSecCreationDateItemAttr },
26 { kSecModDateItemAttr }
27 };
28 SecKeychainAttributeList origAttrList =
29 {
30 sizeof(origAttrs) / sizeof(*origAttrs),
31 origAttrs
32 };
33 ok_status(SecKeychainItemCopyContent(original, NULL, &origAttrList,
34 NULL, NULL), "SecKeychainItemCopyContent");
35
36 /* Must sleep 1 second to trigger mod date bug. */
37 sleep(1);
38 SecKeychainItemRef copy;
39 ok_status(SecKeychainItemCreateCopy(original, dest, NULL, &copy),
40 "copy item");
41
42 SecKeychainAttribute copyAttrs[] =
43 {
44 { kSecCreationDateItemAttr },
45 { kSecModDateItemAttr }
46 };
47 SecKeychainAttributeList copyAttrList =
48 {
49 sizeof(copyAttrs) / sizeof(*copyAttrs),
50 copyAttrs
51 };
52 ok_status(SecKeychainItemCopyContent(copy, NULL, &copyAttrList,
53 NULL, NULL), "SecKeychainItemCopyContent");
54
55 is(origAttrs[0].length, 16, "creation date length 16");
56 is(origAttrs[1].length, 16, "mod date length 16");
57 is(origAttrs[0].length, copyAttrs[0].length, "creation date length same");
58 is(origAttrs[1].length, copyAttrs[1].length, "mod date length same");
59
60 diag("original creation: %.*s copy creation: %.*s",
61 (int)origAttrs[0].length, (const char *)origAttrs[0].data,
62 (int)copyAttrs[0].length, (const char *)copyAttrs[0].data);
63 ok(!memcmp(origAttrs[0].data, copyAttrs[0].data, origAttrs[0].length),
64 "creation date same");
65
66 diag("original mod: %.*s copy mod: %.*s",
67 (int)origAttrs[1].length, (const char *)origAttrs[1].data,
68 (int)copyAttrs[1].length, (const char *)copyAttrs[1].data);
69 ok(!memcmp(origAttrs[1].data, copyAttrs[1].data, origAttrs[1].length),
70 "mod date same");
71
72 ok_status(SecKeychainItemFreeContent(&origAttrList, NULL),
73 "SecKeychainItemCopyContent");
74 ok_status(SecKeychainItemFreeContent(&copyAttrList, NULL),
75 "SecKeychainItemCopyContent");
76
77 is(CFGetRetainCount(original), 1, "original retaincount is 1");
78 CFRelease(original);
79 is(CFGetRetainCount(copy), 1, "copy retaincount is 1");
80 CFRelease(copy);
81 cmp_ok(CFGetRetainCount(source), >=, 1, "source keychain retaincount is 1");
82 ok_status(SecKeychainDelete(source), "delete keychain source");
83 CFRelease(source);
84 ok_status(SecKeychainDelete(dest), "delete keychain dest");
85 cmp_ok(CFGetRetainCount(dest), >=, 1, "dest retaincount is 1");
86 CFRelease(dest);
87 }
88
89 int kc_19_item_copy_internet(int argc, char *const *argv)
90 {
91 plan_tests(20);
92
93 tests();
94
95 deleteTestFiles();
96 return 0;
97 }