]>
Commit | Line | Data |
---|---|---|
d8f41ccd A |
1 | /* |
2 | * Copyright (c) 2013-2014 Apple Inc. All Rights Reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * This file contains Original Code and/or Modifications of Original Code | |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. Please obtain a copy of the License at | |
10 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
11 | * file. | |
12 | * | |
13 | * The Original Code and all software distributed under the License are | |
14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
18 | * Please see the License for the specific language governing rights and | |
19 | * limitations under the License. | |
20 | * | |
21 | * @APPLE_LICENSE_HEADER_END@ | |
22 | */ | |
23 | ||
427c49bc A |
24 | |
25 | ||
26 | ||
27 | #include <Security/SecBase.h> | |
28 | #include <Security/SecItem.h> | |
29 | ||
30 | #include <CoreFoundation/CFDictionary.h> | |
31 | ||
32 | #include <SecureObjectSync/SOSAccount.h> | |
33 | #include <SecureObjectSync/SOSCloudCircle.h> | |
34 | #include <SecureObjectSync/SOSInternal.h> | |
35 | #include <SecureObjectSync/SOSUserKeygen.h> | |
d8f41ccd A |
36 | #include <SecureObjectSync/SOSKVSKeys.h> |
37 | #include <SecureObjectSync/SOSTransport.h> | |
427c49bc A |
38 | |
39 | #include <stdlib.h> | |
40 | #include <unistd.h> | |
41 | ||
42 | #include "secd_regressions.h" | |
43 | #include "SOSTestDataSource.h" | |
44 | ||
45 | #include "SOSRegressionUtilities.h" | |
46 | #include <utilities/SecCFWrappers.h> | |
47 | #include <Security/SecKeyPriv.h> | |
48 | ||
49 | #include <securityd/SOSCloudCircleServer.h> | |
50 | ||
51 | #include "SOSAccountTesting.h" | |
52 | ||
d8f41ccd | 53 | static int kTestTestCount = 136; |
427c49bc A |
54 | |
55 | static void tests(void) | |
56 | { | |
57 | CFErrorRef error = NULL; | |
58 | CFDataRef cfpassword = CFDataCreate(NULL, (uint8_t *) "FooFooFoo", 10); | |
59 | CFStringRef cfaccount = CFSTR("test@test.org"); | |
60 | CFStringRef circle_name = CFSTR("TestSource"); | |
61 | ||
62 | CFMutableDictionaryRef changes = CFDictionaryCreateMutableForCFTypes(kCFAllocatorDefault); | |
427c49bc | 63 | |
d8f41ccd A |
64 | SOSAccountRef alice_account = CreateAccountForLocalChanges(CFSTR("Alice"), circle_name); |
65 | SOSAccountRef bob_account = CreateAccountForLocalChanges(CFSTR("Bob"), circle_name); | |
66 | SOSAccountRef carole_account = CreateAccountForLocalChanges(CFSTR("Carole"), circle_name); | |
67 | ||
427c49bc A |
68 | ok(SOSAccountAssertUserCredentials(bob_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error); |
69 | ||
70 | // Bob wins writing at this point, feed the changes back to alice. | |
d8f41ccd A |
71 | is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, NULL), 1, "updates"); |
72 | ||
427c49bc A |
73 | ok(SOSAccountAssertUserCredentials(alice_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error); |
74 | CFReleaseNull(error); | |
75 | ||
76 | ok(SOSAccountAssertUserCredentials(carole_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error); | |
77 | CFReleaseNull(error); | |
78 | ok(SOSAccountResetToOffering(alice_account, &error), "Reset to offering (%@)", error); | |
79 | CFReleaseNull(error); | |
d8f41ccd A |
80 | |
81 | is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, NULL), 2, "updates"); | |
427c49bc A |
82 | |
83 | ok(SOSAccountJoinCircles(bob_account, &error), "Bob Applies (%@)", error); | |
84 | CFReleaseNull(error); | |
d8f41ccd A |
85 | |
86 | is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, NULL), 2, "updates"); | |
87 | ||
427c49bc A |
88 | { |
89 | CFArrayRef applicants = SOSAccountCopyApplicants(alice_account, &error); | |
90 | ||
91 | ok(applicants && CFArrayGetCount(applicants) == 1, "See one applicant %@ (%@)", applicants, error); | |
92 | ok(SOSAccountAcceptApplicants(alice_account, applicants, &error), "Alice accepts (%@)", error); | |
93 | CFReleaseNull(error); | |
94 | CFReleaseNull(applicants); | |
95 | } | |
96 | ||
d8f41ccd A |
97 | is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, NULL), 3, "updates"); |
98 | ||
427c49bc A |
99 | accounts_agree("bob&alice pair", bob_account, alice_account); |
100 | ||
101 | CFArrayRef peers = SOSAccountCopyPeers(alice_account, &error); | |
102 | ok(peers && CFArrayGetCount(peers) == 2, "See two peers %@ (%@)", peers, error); | |
103 | CFReleaseNull(peers); | |
d8f41ccd | 104 | |
427c49bc A |
105 | SOSFullPeerInfoRef fpiAlice = SOSAccountGetMyFullPeerInCircleNamed(alice_account, circle_name, NULL); |
106 | CFStringRef alice_id = CFStringCreateCopy(NULL, SOSPeerInfoGetPeerID(SOSFullPeerInfoGetPeerInfo(fpiAlice))); | |
107 | ||
108 | ok(SOSAccountLeaveCircles(alice_account, &error), "Alice Leaves (%@)", error); | |
109 | CFReleaseNull(error); | |
110 | CFReleaseNull(cfpassword); | |
111 | ||
d8f41ccd | 112 | is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, NULL), 3, "updates"); |
427c49bc A |
113 | |
114 | accounts_agree("Alice bails", bob_account, alice_account); | |
115 | accounts_agree("Alice bails", bob_account, carole_account); | |
116 | ||
117 | SOSAccountCleanupRetirementTickets(bob_account, 0, &error); | |
d8f41ccd A |
118 | |
119 | is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, NULL), 1, "updates"); | |
120 | ||
121 | //is(CFDictionaryGetCountOfValue(BobChanges, kCFNull),0, "0 Keys Nulled Out"); | |
427c49bc A |
122 | |
123 | ok(SOSAccountJoinCircles(carole_account, &error), "Carole Applies (%@)", error); | |
124 | CFReleaseNull(error); | |
d8f41ccd A |
125 | |
126 | is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, NULL), 2, "updates"); | |
127 | ||
427c49bc A |
128 | |
129 | { | |
130 | CFArrayRef applicants = SOSAccountCopyApplicants(bob_account, &error); | |
131 | ||
132 | ok(applicants && CFArrayGetCount(applicants) == 1, "See one applicant %@ (%@)", applicants, error); | |
133 | ok(SOSAccountAcceptApplicants(bob_account, applicants, &error), "Bob accepts Carole (%@)", error); | |
134 | CFReleaseNull(error); | |
135 | CFReleaseNull(applicants); | |
136 | } | |
d8f41ccd | 137 | |
427c49bc A |
138 | // Bob should not yet cleanup Alice's retirment here on his own since it hasn't been long enough |
139 | // by default. | |
d8f41ccd | 140 | //is(CFDictionaryGetCountOfValue(BobChanges, kCFNull),0, "0 Keys Nulled Out"); |
427c49bc | 141 | |
d8f41ccd | 142 | is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, NULL), 3, "updates"); |
427c49bc A |
143 | |
144 | accounts_agree("Carole joins", bob_account, carole_account); | |
d8f41ccd | 145 | |
427c49bc A |
146 | SOSAccountCleanupRetirementTickets(bob_account, 0, &error); |
147 | ||
d8f41ccd A |
148 | is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, NULL), 2, "updates"); |
149 | ||
427c49bc A |
150 | is(countPeers(bob_account), 2, "Active peers after forced cleanup"); |
151 | is(countActivePeers(bob_account), 3, "Inactive peers after forced cleanup"); | |
427c49bc | 152 | |
d8f41ccd | 153 | //is(CFDictionaryGetCountOfValue(BobChanges, kCFNull), 1, "1 Keys Nulled Out"); |
427c49bc | 154 | |
d8f41ccd A |
155 | // CFDictionaryForEach(BobChanges, ^(const void *key, const void *value) { |
156 | // if(isNull(value)) { | |
157 | // CFStringRef circle_name = NULL, retiree = NULL; | |
158 | // SOSKVSKeyType keytype = SOSKVSKeyGetKeyTypeAndParse(key, &circle_name, &retiree, NULL); | |
159 | // is(keytype, kRetirementKey, "Expect only a retirement key"); | |
160 | // ok(CFEqualSafe(alice_id, retiree), "Alice (%@) is retiree (%@)", alice_id, retiree); | |
161 | // CFReleaseNull(circle_name); | |
162 | // CFReleaseNull(retiree); | |
163 | // } | |
164 | // }); | |
165 | ||
427c49bc A |
166 | CFReleaseNull(alice_id); |
167 | CFReleaseNull(carole_account); | |
168 | CFReleaseNull(bob_account); | |
169 | CFReleaseNull(alice_account); | |
d8f41ccd A |
170 | |
171 | SOSUnregisterAllTransportMessages(); | |
172 | SOSUnregisterAllTransportCircles(); | |
173 | SOSUnregisterAllTransportKeyParameters(); | |
174 | CFArrayRemoveAllValues(key_transports); | |
175 | CFArrayRemoveAllValues(circle_transports); | |
176 | CFArrayRemoveAllValues(message_transports); | |
177 | ||
427c49bc A |
178 | } |
179 | ||
180 | int secd_59_account_cleanup(int argc, char *const *argv) | |
181 | { | |
182 | plan_tests(kTestTestCount); | |
183 | ||
184 | tests(); | |
185 | ||
d8f41ccd | 186 | return 0; |
427c49bc | 187 | } |