2 // sc-60-account-cloud-identity.c
5 // Created by Mitch Adler on 6/25/13.
11 #include <Security/SecBase.h>
12 #include <Security/SecItem.h>
14 #include <CoreFoundation/CFDictionary.h>
16 #include <SecureObjectSync/SOSAccount.h>
17 #include <SecureObjectSync/SOSCloudCircle.h>
18 #include <SecureObjectSync/SOSInternal.h>
19 #include <SecureObjectSync/SOSUserKeygen.h>
24 #include "secd_regressions.h"
25 #include "SOSTestDataSource.h"
27 #include "SOSRegressionUtilities.h"
28 #include <utilities/SecCFWrappers.h>
29 #include <Security/SecKeyPriv.h>
31 #include <securityd/SOSCloudCircleServer.h>
33 #include "SOSAccountTesting.h"
36 static int kTestTestCount
= 95;
40 static void tests(void)
42 CFErrorRef error
= NULL
;
43 CFDataRef cfpassword
= CFDataCreate(NULL
, (uint8_t *) "FooFooFoo", 10);
44 CFStringRef cfaccount
= CFSTR("test@test.org");
46 CFMutableDictionaryRef changes
= CFDictionaryCreateMutableForCFTypes(kCFAllocatorDefault
);
48 SOSAccountRef alice_account
= CreateAccountForLocalChanges(changes
, CFSTR("Alice"), CFSTR("TestSource"));
49 SOSAccountRef bob_account
= CreateAccountForLocalChanges(changes
, CFSTR("Bob"), CFSTR("TestSource"));
50 SOSAccountRef carole_account
= CreateAccountForLocalChanges(changes
, CFSTR("Carole"), CFSTR("TestSource"));
52 ok(SOSAccountAssertUserCredentials(bob_account
, cfaccount
, cfpassword
, &error
), "Credential setting (%@)", error
);
54 // Bob wins writing at this point, feed the changes back to alice.
56 FeedChangesToMulti(changes
, alice_account
, carole_account
, NULL
);
58 ok(SOSAccountAssertUserCredentials(alice_account
, cfaccount
, cfpassword
, &error
), "Credential setting (%@)", error
);
61 ok(SOSAccountAssertUserCredentials(carole_account
, cfaccount
, cfpassword
, &error
), "Credential setting (%@)", error
);
63 CFReleaseNull(cfpassword
);
64 ok(SOSAccountResetToOffering(alice_account
, &error
), "Reset to offering (%@)", error
);
67 FeedChangesToMulti(changes
, bob_account
, carole_account
, NULL
);
69 ok(SOSAccountJoinCircles(bob_account
, &error
), "Bob Applies (%@)", error
);
72 FeedChangesTo(changes
, alice_account
);
75 CFArrayRef applicants
= SOSAccountCopyApplicants(alice_account
, &error
);
77 ok(applicants
&& CFArrayGetCount(applicants
) == 1, "See one applicant %@ (%@)", applicants
, error
);
78 ok(SOSAccountAcceptApplicants(alice_account
, applicants
, &error
), "Alice accepts (%@)", error
);
80 CFReleaseNull(applicants
);
84 FeedChangesTo(changes
, bob_account
); // Bob sees he's accepted
86 FeedChangesToMulti(changes
, alice_account
, carole_account
, NULL
); // Everyone sees conurring circle
88 ok(CFDictionaryGetCount(changes
) == 0, "We converged. (%@)", changes
);
90 accounts_agree("bob&alice pair", bob_account
, alice_account
);
92 /*----- normal join after restore -----*/
94 ok(SOSAccountJoinCirclesAfterRestore(carole_account
, &error
), "Carole cloud identity joins (%@)", error
);
97 FeedChangesToMulti(changes
, bob_account
, carole_account
, NULL
); // Bob and carole see the final result.
98 FeedChangesToMulti(changes
, alice_account
, bob_account
, carole_account
, NULL
); // Bob and carole see the final result.
100 is(countApplicants(alice_account
), 0, "See no applicants");
102 is(countPeers(carole_account
), 3, "Carole sees 3 valid peers after sliding in");
104 FeedChangesToMulti(changes
, bob_account
, carole_account
, NULL
); // Bob and carole see the final result.
106 accounts_agree_internal("Carole's in", bob_account
, alice_account
, false);
107 accounts_agree_internal("Carole's in - 2", bob_account
, carole_account
, false);
109 ok(SOSAccountLeaveCircles(carole_account
, &error
), "Carol Leaves again");
110 CFReleaseNull(error
);
111 FeedChangesToMulti(changes
, bob_account
, alice_account
, NULL
);
112 FeedChangesToMulti(changes
, alice_account
, bob_account
, carole_account
, NULL
);
114 /*----- join - join after restore -----*/
116 ok(SOSAccountJoinCircles(carole_account
, &error
), "Carole normally joins (%@)", error
);
117 CFReleaseNull(error
);
118 FeedChangesTo(changes
, alice_account
);
120 is(countApplicants(alice_account
), 1, "See one applicant");
122 ok(SOSAccountJoinCirclesAfterRestore(carole_account
, &error
), "Carole cloud identity joins (%@)", error
);
123 CFReleaseNull(error
);
125 FeedChangesToMulti(changes
, bob_account
, carole_account
, NULL
); // Bob and carole see the final result.
126 FeedChangesToMulti(changes
, alice_account
, bob_account
, carole_account
, NULL
); // Bob and carole see the final result.
128 is(countApplicants(alice_account
), 0, "See no applicants");
130 is(countPeers(carole_account
), 3, "Carole sees 3 valid peers after sliding in");
132 FeedChangesToMulti(changes
, bob_account
, carole_account
, NULL
); // Bob and carole see the final result.
134 accounts_agree_internal("Carole's in", bob_account
, alice_account
, false);
135 accounts_agree_internal("Carole's in - 2", bob_account
, carole_account
, false);
139 CFReleaseNull(bob_account
);
140 CFReleaseNull(alice_account
);
141 CFReleaseNull(carole_account
);
144 int secd_60_account_cloud_identity(int argc
, char *const *argv
)
146 plan_tests(kTestTestCount
);