2 * secd_52_account_changed.c
4 * Created by Richard Murphy on 09152013.
5 * Copyright 2013 Apple Inc. All rights reserved.
10 #include <Security/SecBase.h>
11 #include <Security/SecItem.h>
13 #include <SecureObjectSync/SOSAccount.h>
14 #include <SecureObjectSync/SOSCloudCircle.h>
15 #include <SecureObjectSync/SOSInternal.h>
16 #include <SecureObjectSync/SOSUserKeygen.h>
21 #include "secd_regressions.h"
22 #include "SOSTestDataSource.h"
24 #include "SOSRegressionUtilities.h"
25 #include <utilities/SecCFWrappers.h>
27 #include <securityd/SOSCloudCircleServer.h>
29 #include "SecdTestKeychainUtilities.h"
30 #include "SOSAccountTesting.h"
33 static int kTestTestCount
= 133;
36 static void tests(void)
38 CFErrorRef error
= NULL
;
39 CFDataRef cfpassword
= CFDataCreate(NULL
, (uint8_t *) "FooFooFoo", 10);
40 CFStringRef cfaccount
= CFSTR("test@test.org");
42 CFMutableDictionaryRef changes
= CFDictionaryCreateMutableForCFTypes(kCFAllocatorDefault
);
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"));
48 ok(SOSAccountAssertUserCredentials(bob_account
, cfaccount
, cfpassword
, &error
), "Credential setting (%@)", error
);
50 // Bob wins writing at this point, feed the changes back to alice.
52 FeedChangesToMulti(changes
, alice_account
, carol_account
, NULL
);
54 ok(SOSAccountAssertUserCredentials(alice_account
, cfaccount
, cfpassword
, &error
), "Credential setting (%@)", error
);
56 ok(SOSAccountAssertUserCredentials(carol_account
, cfaccount
, cfpassword
, &error
), "Credential setting (%@)", error
);
58 CFReleaseNull(cfpassword
);
60 /* ==================== Three Accounts setup =============================================*/
62 ok(SOSAccountResetToOffering(alice_account
, &error
), "Reset to offering (%@)", error
);
65 FeedChangesToMulti(changes
, bob_account
, carol_account
, NULL
);
67 ok(SOSAccountJoinCircles(bob_account
, &error
), "Bob Applies (%@)", error
);
70 FeedChangesToMulti(changes
, alice_account
, carol_account
, bob_account
, NULL
);
72 ok(SOSAccountJoinCircles(carol_account
, &error
), "Carol Applies (%@)", error
);
75 FeedChangesToMulti(changes
, alice_account
, carol_account
, bob_account
, NULL
);
78 CFArrayRef applicants
= SOSAccountCopyApplicants(alice_account
, &error
);
80 ok(applicants
&& CFArrayGetCount(applicants
) == 2, "See two applicants %@ (%@)", applicants
, error
);
81 ok(SOSAccountAcceptApplicants(alice_account
, applicants
, &error
), "Alice accepts (%@)", error
);
83 CFReleaseNull(applicants
);
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
92 ok(CFDictionaryGetCount(changes
) == 0, "We converged. (%@)", changes
);
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
);
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");
103 CFDataRef cfpassword2
= CFDataCreate(NULL
, (uint8_t *) "ooFooFooF", 10);
104 CFStringRef cfaccount2
= CFSTR("test2@test.org");
106 ok(SOSAccountAssertUserCredentials(alice_account
, cfaccount2
, cfpassword2
, &error
), "Credential setting (%@)", error
);
107 CFReleaseNull(error
);
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
);
113 ok(SOSAccountAssertUserCredentials(bob_account
, cfaccount2
, cfpassword2
, &error
), "Credential setting (%@)", error
);
114 CFReleaseNull(error
);
116 ok(SOSAccountAssertUserCredentials(carol_account
, cfaccount2
, cfpassword2
, &error
), "Credential setting (%@)", error
);
117 CFReleaseNull(error
);
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.
123 /* ==================== Three Accounts setup =============================================*/
125 ok(SOSAccountResetToOffering(alice_account
, &error
), "Reset to offering (%@)", error
);
126 CFReleaseNull(error
);
127 is(countActivePeers(alice_account
), 2, "2 peers - alice and icloud");
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");
134 ok(SOSAccountJoinCircles(bob_account
, &error
), "Bob Applies (%@)", error
);
135 CFReleaseNull(error
);
137 FeedChangesToMulti(changes
, alice_account
, carol_account
, bob_account
, NULL
);
138 is(SOSAccountIsInCircles(bob_account
, &error
), kSOSCCRequestPending
, "Bob has a pending request");
140 ok(SOSAccountJoinCircles(carol_account
, &error
), "Carol Applies (%@)", error
);
141 CFReleaseNull(error
);
143 FeedChangesToMulti(changes
, alice_account
, carol_account
, bob_account
, NULL
);
144 is(SOSAccountIsInCircles(carol_account
, &error
), kSOSCCRequestPending
, "Carol has a pending request");
147 CFArrayRef applicants
= SOSAccountCopyApplicants(alice_account
, &error
);
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");
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
164 ok(CFDictionaryGetCount(changes
) == 0, "We converged. (%@)", changes
);
166 accounts_agree_internal("bob&alice pair", bob_account
, alice_account
, false);
167 accounts_agree_internal("bob&carol pair", bob_account
, carol_account
, false);
172 int secd_52_account_changed(int argc
, char *const *argv
)
174 plan_tests(kTestTestCount
);