]>
Commit | Line | Data |
---|---|---|
427c49bc A |
1 | /* |
2 | * secd_52_account_changed.c | |
3 | * | |
4 | * Created by Richard Murphy on 09152013. | |
5 | * Copyright 2013 Apple Inc. All rights reserved. | |
6 | * | |
7 | */ | |
8 | ||
9 | ||
10 | #include <Security/SecBase.h> | |
11 | #include <Security/SecItem.h> | |
12 | ||
13 | #include <SecureObjectSync/SOSAccount.h> | |
14 | #include <SecureObjectSync/SOSCloudCircle.h> | |
15 | #include <SecureObjectSync/SOSInternal.h> | |
16 | #include <SecureObjectSync/SOSUserKeygen.h> | |
17 | ||
18 | #include <stdlib.h> | |
19 | #include <unistd.h> | |
20 | ||
21 | #include "secd_regressions.h" | |
22 | #include "SOSTestDataSource.h" | |
23 | ||
24 | #include "SOSRegressionUtilities.h" | |
25 | #include <utilities/SecCFWrappers.h> | |
26 | ||
27 | #include <securityd/SOSCloudCircleServer.h> | |
28 | ||
29 | #include "SecdTestKeychainUtilities.h" | |
30 | #include "SOSAccountTesting.h" | |
31 | ||
32 | ||
33 | static int kTestTestCount = 133; | |
34 | ||
35 | ||
36 | static void tests(void) | |
37 | { | |
38 | CFErrorRef error = NULL; | |
39 | CFDataRef cfpassword = CFDataCreate(NULL, (uint8_t *) "FooFooFoo", 10); | |
40 | CFStringRef cfaccount = CFSTR("test@test.org"); | |
41 | ||
42 | CFMutableDictionaryRef changes = CFDictionaryCreateMutableForCFTypes(kCFAllocatorDefault); | |
43 | ||
44 | SOSAccountRef alice_account = CreateAccountForLocalChanges(changes, CFSTR("Alice"), CFSTR("TestSource")); | |
45 | SOSAccountRef bob_account = CreateAccountForLocalChanges(changes, CFSTR("Bob"), CFSTR("TestSource")); | |
46 | SOSAccountRef carol_account = CreateAccountForLocalChanges(changes, CFSTR("Carol"), CFSTR("TestSource")); | |
47 | ||
48 | ok(SOSAccountAssertUserCredentials(bob_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error); | |
49 | ||
50 | // Bob wins writing at this point, feed the changes back to alice. | |
51 | ||
52 | FeedChangesToMulti(changes, alice_account, carol_account, NULL); | |
53 | ||
54 | ok(SOSAccountAssertUserCredentials(alice_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error); | |
55 | CFReleaseNull(error); | |
56 | ok(SOSAccountAssertUserCredentials(carol_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error); | |
57 | CFReleaseNull(error); | |
58 | CFReleaseNull(cfpassword); | |
59 | ||
60 | /* ==================== Three Accounts setup =============================================*/ | |
61 | ||
62 | ok(SOSAccountResetToOffering(alice_account, &error), "Reset to offering (%@)", error); | |
63 | CFReleaseNull(error); | |
64 | ||
65 | FeedChangesToMulti(changes, bob_account, carol_account, NULL); | |
66 | ||
67 | ok(SOSAccountJoinCircles(bob_account, &error), "Bob Applies (%@)", error); | |
68 | CFReleaseNull(error); | |
69 | ||
70 | FeedChangesToMulti(changes, alice_account, carol_account, bob_account, NULL); | |
71 | ||
72 | ok(SOSAccountJoinCircles(carol_account, &error), "Carol Applies (%@)", error); | |
73 | CFReleaseNull(error); | |
74 | ||
75 | FeedChangesToMulti(changes, alice_account, carol_account, bob_account, NULL); | |
76 | ||
77 | { | |
78 | CFArrayRef applicants = SOSAccountCopyApplicants(alice_account, &error); | |
79 | ||
80 | ok(applicants && CFArrayGetCount(applicants) == 2, "See two applicants %@ (%@)", applicants, error); | |
81 | ok(SOSAccountAcceptApplicants(alice_account, applicants, &error), "Alice accepts (%@)", error); | |
82 | CFReleaseNull(error); | |
83 | CFReleaseNull(applicants); | |
84 | } | |
85 | ||
86 | FeedChangesToMulti(changes, bob_account, NULL); // let bob concurr | |
87 | FeedChangesToMulti(changes, alice_account, carol_account, NULL); // let carol concurr | |
88 | FeedChangesToMulti(changes, alice_account, bob_account, carol_account, NULL); // all synced | |
89 | FeedChangesToMulti(changes, alice_account, bob_account, carol_account, NULL); // all synced | |
90 | FeedChangesToMulti(changes, alice_account, bob_account, carol_account, NULL); // all synced | |
91 | ||
92 | ok(CFDictionaryGetCount(changes) == 0, "We converged. (%@)", changes); | |
93 | ||
94 | accounts_agree_internal("bob&alice pair", bob_account, alice_account, false); | |
95 | accounts_agree_internal("bob&carol pair", bob_account, carol_account, false); | |
96 | /* ==================== Three Accounts in circle =============================================*/ | |
97 | InjectChangeToMulti(CFSTR("^AccountChanged"), CFSTR("none"), alice_account, bob_account, carol_account, NULL); | |
98 | ||
99 | is(SOSAccountIsInCircles(alice_account, &error), kSOSCCError, "Account reset - no user keys - error"); | |
100 | is(SOSAccountIsInCircles(bob_account, &error), kSOSCCError, "Account reset - no user keys - error"); | |
101 | is(SOSAccountIsInCircles(carol_account, &error), kSOSCCError, "Account reset - no user keys - error"); | |
102 | ||
103 | CFDataRef cfpassword2 = CFDataCreate(NULL, (uint8_t *) "ooFooFooF", 10); | |
104 | CFStringRef cfaccount2 = CFSTR("test2@test.org"); | |
105 | ||
106 | ok(SOSAccountAssertUserCredentials(alice_account, cfaccount2, cfpassword2, &error), "Credential setting (%@)", error); | |
107 | CFReleaseNull(error); | |
108 | ||
109 | is(SOSAccountIsInCircles(alice_account, &error), kSOSCCCircleAbsent, "Account reset - circle is absent"); | |
110 | is(SOSAccountIsInCircles(bob_account, &error), kSOSCCError, "Account reset - no user keys - error"); | |
111 | FeedChangesToMulti(changes, bob_account, carol_account, NULL); | |
112 | ||
113 | ok(SOSAccountAssertUserCredentials(bob_account, cfaccount2, cfpassword2, &error), "Credential setting (%@)", error); | |
114 | CFReleaseNull(error); | |
115 | ||
116 | ok(SOSAccountAssertUserCredentials(carol_account, cfaccount2, cfpassword2, &error), "Credential setting (%@)", error); | |
117 | CFReleaseNull(error); | |
118 | ||
119 | is(SOSAccountIsInCircles(bob_account, &error), kSOSCCCircleAbsent, "Account reset - circle is absent"); | |
120 | is(SOSAccountIsInCircles(carol_account, &error), kSOSCCCircleAbsent, "Account reset - circle is absent"); | |
121 | // Now everyone is playing the same account. | |
122 | ||
123 | /* ==================== Three Accounts setup =============================================*/ | |
124 | ||
125 | ok(SOSAccountResetToOffering(alice_account, &error), "Reset to offering (%@)", error); | |
126 | CFReleaseNull(error); | |
127 | is(countActivePeers(alice_account), 2, "2 peers - alice and icloud"); | |
128 | ||
129 | FeedChangesToMulti(changes, bob_account, carol_account, NULL); | |
130 | is(SOSAccountIsInCircles(alice_account, &error), kSOSCCInCircle, "Alice is in circle"); | |
131 | is(SOSAccountIsInCircles(bob_account, &error), kSOSCCNotInCircle, "Bob is not in circle"); | |
132 | is(SOSAccountIsInCircles(carol_account, &error), kSOSCCNotInCircle, "Carol is not in circle"); | |
133 | ||
134 | ok(SOSAccountJoinCircles(bob_account, &error), "Bob Applies (%@)", error); | |
135 | CFReleaseNull(error); | |
136 | ||
137 | FeedChangesToMulti(changes, alice_account, carol_account, bob_account, NULL); | |
138 | is(SOSAccountIsInCircles(bob_account, &error), kSOSCCRequestPending, "Bob has a pending request"); | |
139 | ||
140 | ok(SOSAccountJoinCircles(carol_account, &error), "Carol Applies (%@)", error); | |
141 | CFReleaseNull(error); | |
142 | ||
143 | FeedChangesToMulti(changes, alice_account, carol_account, bob_account, NULL); | |
144 | is(SOSAccountIsInCircles(carol_account, &error), kSOSCCRequestPending, "Carol has a pending request"); | |
145 | ||
146 | { | |
147 | CFArrayRef applicants = SOSAccountCopyApplicants(alice_account, &error); | |
148 | ||
149 | ok(applicants && CFArrayGetCount(applicants) == 2, "See two applicants %@ (%@)", applicants, error); | |
150 | ok(SOSAccountAcceptApplicants(alice_account, applicants, &error), "Alice accepts (%@)", error); | |
151 | CFReleaseNull(error); | |
152 | CFReleaseNull(applicants); | |
153 | is(countActivePeers(alice_account), 4, "4 peers - alice, bob, carol, and icloud"); | |
154 | } | |
155 | ||
156 | FeedChangesToMulti(changes, bob_account, NULL); // let bob concurr | |
157 | is(SOSAccountIsInCircles(bob_account, &error), kSOSCCInCircle, "Bob is in circle"); | |
158 | FeedChangesToMulti(changes, alice_account, carol_account, NULL); // let carol concurr | |
159 | is(SOSAccountIsInCircles(carol_account, &error), kSOSCCInCircle, "Carol is in circle"); | |
160 | FeedChangesToMulti(changes, alice_account, bob_account, carol_account, NULL); // all synced | |
161 | FeedChangesToMulti(changes, alice_account, bob_account, carol_account, NULL); // all synced | |
162 | FeedChangesToMulti(changes, alice_account, bob_account, carol_account, NULL); // all synced | |
163 | ||
164 | ok(CFDictionaryGetCount(changes) == 0, "We converged. (%@)", changes); | |
165 | ||
166 | accounts_agree_internal("bob&alice pair", bob_account, alice_account, false); | |
167 | accounts_agree_internal("bob&carol pair", bob_account, carol_account, false); | |
168 | ||
169 | } | |
170 | ||
171 | ||
172 | int secd_52_account_changed(int argc, char *const *argv) | |
173 | { | |
174 | plan_tests(kTestTestCount); | |
175 | ||
176 | tests(); | |
177 | ||
178 | return 0; | |
179 | } |