]>
Commit | Line | Data |
---|---|---|
427c49bc A |
1 | // |
2 | // secd-61-account-leave-not-in-kansas-anymore.c | |
3 | // sec | |
4 | // | |
5 | // Created by Richard Murphy on 7/16/13. | |
6 | // | |
7 | ||
8 | ||
9 | #include <Security/SecBase.h> | |
10 | #include <Security/SecItem.h> | |
11 | ||
12 | #include <CoreFoundation/CFDictionary.h> | |
13 | ||
14 | #include <SecureObjectSync/SOSAccount.h> | |
15 | #include <SecureObjectSync/SOSCloudCircle.h> | |
16 | #include <SecureObjectSync/SOSInternal.h> | |
17 | #include <SecureObjectSync/SOSUserKeygen.h> | |
18 | ||
19 | #include <stdlib.h> | |
20 | #include <unistd.h> | |
21 | ||
22 | #include "secd_regressions.h" | |
23 | #include "SOSTestDataSource.h" | |
24 | ||
25 | #include "SOSRegressionUtilities.h" | |
26 | #include <utilities/SecCFWrappers.h> | |
27 | #include <Security/SecKeyPriv.h> | |
28 | ||
29 | #include <securityd/SOSCloudCircleServer.h> | |
30 | ||
31 | #include "SOSAccountTesting.h" | |
32 | ||
33 | ||
34 | static int kTestTestCount = 102; | |
35 | #if 0 | |
36 | static int countPeers(SOSAccountRef account, bool active) { | |
37 | CFErrorRef error = NULL; | |
38 | CFArrayRef peers; | |
39 | ||
40 | if(active) peers = SOSAccountCopyActivePeers(account, &error); | |
41 | else peers = SOSAccountCopyPeers(account, &error); | |
42 | int retval = (int) CFArrayGetCount(peers); | |
43 | CFReleaseNull(error); | |
44 | CFReleaseNull(peers); | |
45 | return retval; | |
46 | } | |
47 | #endif | |
48 | /* | |
49 | static void trim_retirements_from_circle(SOSAccountRef account) { | |
50 | SOSAccountForEachCircle(account, ^(SOSCircleRef circle) { | |
51 | SOSCircleRemoveRetired(circle, NULL); | |
52 | }); | |
53 | } | |
54 | */ | |
55 | static bool accept_applicants(SOSAccountRef account, int count) { | |
56 | CFErrorRef error = NULL; | |
57 | CFArrayRef applicants = SOSAccountCopyApplicants(account, &error); | |
58 | bool retval = false; | |
59 | ok(applicants, "Have Applicants"); | |
60 | if(!applicants) goto errout; | |
61 | is(CFArrayGetCount(applicants), count, "See applicants %@ (%@)", applicants, error); | |
62 | if(CFArrayGetCount(applicants) != count) goto errout; | |
63 | ok(retval = SOSAccountAcceptApplicants(account, applicants, &error), "Account accepts (%@)", error); | |
64 | errout: | |
65 | CFReleaseNull(error); | |
66 | CFReleaseNull(applicants); | |
67 | return retval; | |
68 | } | |
69 | ||
70 | ||
71 | static void tests(void) | |
72 | { | |
73 | CFErrorRef error = NULL; | |
74 | CFDataRef cfpassword = CFDataCreate(NULL, (uint8_t *) "FooFooFoo", 10); | |
75 | CFStringRef cfaccount = CFSTR("test@test.org"); | |
76 | ||
77 | CFMutableDictionaryRef changes = CFDictionaryCreateMutableForCFTypes(kCFAllocatorDefault); | |
78 | ||
79 | SOSAccountRef alice_account = CreateAccountForLocalChanges(changes, CFSTR("Alice"), CFSTR("TestSource")); | |
80 | SOSAccountRef bob_account = CreateAccountForLocalChanges(changes, CFSTR("Bob"), CFSTR("TestSource")); | |
81 | SOSAccountRef carole_account = CreateAccountForLocalChanges(changes, CFSTR("Carole"), CFSTR("TestSource")); | |
82 | SOSAccountRef david_account = CreateAccountForLocalChanges(changes, CFSTR("David"), CFSTR("TestSource")); | |
83 | ||
84 | ok(SOSAccountAssertUserCredentials(bob_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error); | |
85 | ||
86 | // Bob wins writing at this point, feed the changes back to alice. | |
87 | ||
88 | FeedChangesToMulti(changes, alice_account, carole_account, david_account, NULL); | |
89 | ||
90 | ok(SOSAccountAssertUserCredentials(alice_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error); | |
91 | CFReleaseNull(error); | |
92 | ||
93 | ok(SOSAccountAssertUserCredentials(carole_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error); | |
94 | CFReleaseNull(error); | |
95 | ||
96 | ok(SOSAccountAssertUserCredentials(david_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error); | |
97 | CFReleaseNull(error); | |
98 | ||
99 | ok(SOSAccountResetToOffering(alice_account, &error), "Reset to offering (%@)", error); | |
100 | CFReleaseNull(error); | |
101 | ||
102 | FeedChangesTo(changes, bob_account); | |
103 | ||
104 | ok(SOSAccountJoinCircles(bob_account, &error), "Bob Applies (%@)", error); | |
105 | CFReleaseNull(error); | |
106 | ||
107 | FeedChangesTo(changes, alice_account); | |
108 | ||
109 | ok(accept_applicants(alice_account, 1), "Alice Accepts Application"); | |
110 | ||
111 | FeedChangesToMulti(changes, alice_account, bob_account, carole_account, david_account, NULL); | |
112 | ||
113 | FeedChangesToMulti(changes, alice_account, bob_account, carole_account, david_account, NULL); | |
114 | ||
115 | ok(CFDictionaryGetCount(changes) == 0, "We converged. (%@)", changes); | |
116 | ||
117 | accounts_agree("bob&alice pair", bob_account, alice_account); | |
118 | is(SOSAccountGetLastDepartureReason(bob_account, &error), kSOSNeverLeftCircle, "Bob affirms he hasn't left."); | |
119 | ||
120 | // ============================== Alice and Bob are in the Account. ============================================ | |
121 | ||
122 | ok(SOSAccountJoinCircles(carole_account, &error), "Carole Applies (%@)", error); | |
123 | CFReleaseNull(error); | |
124 | ||
125 | FeedChangesToMulti(changes, alice_account, carole_account, david_account, NULL); | |
126 | ||
127 | ok(accept_applicants(alice_account, 1), "Alice Accepts Application"); | |
128 | ||
129 | // Let everyone concur. | |
130 | FeedChangesToMulti(changes, alice_account, carole_account, david_account, NULL); | |
131 | ||
132 | CFArrayRef peers = SOSAccountCopyPeers(alice_account, &error); | |
133 | ok(peers && CFArrayGetCount(peers) == 3, "See three peers %@ (%@)", peers, error); | |
134 | CFReleaseNull(peers); | |
135 | ||
136 | ||
137 | // SOSAccountPurgePrivateCredential(alice_account); | |
138 | ||
139 | ok(SOSAccountLeaveCircles(alice_account, &error), "Alice Leaves (%@)", error); | |
140 | CFReleaseNull(error); | |
141 | ||
142 | FeedChangesToMulti(changes, alice_account, carole_account, david_account, NULL); | |
143 | FeedChangesToMulti(changes, alice_account, carole_account, david_account, NULL); | |
144 | FeedChangesToMulti(changes, alice_account, carole_account, david_account, NULL); | |
145 | ||
146 | ok(SOSAccountJoinCircles(david_account, &error), "David Applies (%@)", error); | |
147 | CFReleaseNull(error); | |
148 | ||
149 | FeedChangesToMulti(changes, alice_account, carole_account, david_account, NULL); | |
150 | ||
151 | CFReleaseNull(error); | |
152 | ok(accept_applicants(carole_account, 1), "Carole Accepts Application"); | |
153 | ||
154 | // ============================== We added Carole and David while Bob was in a drawer. Alice has left ============================================ | |
155 | ||
156 | // ============================== Bob comes out of the drawer seeing alice left and doesn't recognize the remainder. ============================================ | |
157 | ||
158 | FeedChangesToMulti(changes, alice_account, carole_account, david_account, NULL); | |
159 | FeedChangesToMulti(changes, bob_account, alice_account, carole_account, david_account, NULL); | |
160 | FeedChangesToMulti(changes, alice_account, carole_account, david_account, bob_account, NULL); | |
161 | FeedChangesToMulti(changes, alice_account, carole_account, david_account, bob_account, NULL); | |
162 | FeedChangesToMulti(changes, alice_account, carole_account, david_account, bob_account, NULL); | |
163 | FeedChangesToMulti(changes, alice_account, carole_account, david_account, bob_account, NULL); | |
164 | FeedChangesToMulti(changes, alice_account, carole_account, david_account, bob_account, NULL); | |
165 | ||
166 | CFReleaseNull(error); | |
167 | is(SOSAccountIsInCircles(carole_account, &error), kSOSCCInCircle, "Carole still in Circle (%@)", error); | |
168 | CFReleaseNull(error); | |
169 | is(SOSAccountIsInCircles(david_account, &error), kSOSCCInCircle, "David still in Circle (%@)", error); | |
170 | CFReleaseNull(error); | |
171 | is(SOSAccountIsInCircles(bob_account, &error), kSOSCCNotInCircle, "Bob is not in Circle (%@)", error); | |
172 | CFReleaseNull(error); | |
173 | is(SOSAccountGetLastDepartureReason(bob_account, &error), kSOSLeftUntrustedCircle, "Bob affirms he left because he doesn't know anyone."); | |
174 | CFReleaseNull(error); | |
175 | is(SOSAccountIsInCircles(alice_account, &error), kSOSCCNotInCircle, "Alice is not in Circle (%@)", error); | |
176 | CFReleaseNull(error); | |
177 | is(SOSAccountGetLastDepartureReason(alice_account, &error), kSOSWithdrewMembership, "Alice affirms she left by request."); | |
178 | CFReleaseNull(error); | |
179 | ||
180 | ||
181 | CFReleaseNull(carole_account); | |
182 | CFReleaseNull(david_account); | |
183 | CFReleaseNull(bob_account); | |
184 | CFReleaseNull(alice_account); | |
185 | } | |
186 | ||
187 | int secd_61_account_leave_not_in_kansas_anymore(int argc, char *const *argv) | |
188 | { | |
189 | plan_tests(kTestTestCount); | |
190 | ||
191 | tests(); | |
192 | ||
193 | return 0; | |
194 | } |