2 // secd-55-account-circle.c
5 // Created by Mitch Adler on 1/25/12.
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
= 9;
38 static void tests(void)
40 CFErrorRef error
= NULL
;
41 CFDataRef cfpassword
= CFDataCreate(NULL
, (uint8_t *) "FooFooFoo", 10);
42 CFDataRef cfwrong_password
= CFDataCreate(NULL
, (uint8_t *) "NotFooFooFoo", 10);
43 CFStringRef cfaccount
= CFSTR("test@test.org");
44 CFStringRef data_name
= CFSTR("TestSource");
45 CFStringRef circle_key_name
= SOSCircleKeyCreateWithName(data_name
, NULL
);
47 CFMutableDictionaryRef changes
= CFDictionaryCreateMutableForCFTypes(kCFAllocatorDefault
);
49 SOSAccountRef alice_account
= CreateAccountForLocalChanges(changes
, CFSTR("Alice"), data_name
);
50 SOSAccountRef bob_account
= CreateAccountForLocalChanges(changes
, CFSTR("Bob"), data_name
);
51 SOSAccountRef carol_account
= CreateAccountForLocalChanges(changes
, CFSTR("Carol"), data_name
);
53 ok(SOSAccountAssertUserCredentials(bob_account
, cfaccount
, cfpassword
, &error
), "Credential setting (%@)", error
);
55 // Bob wins writing at this point, feed the changes back to alice.
57 FeedChangesToMulti(changes
, alice_account
, carol_account
, NULL
);
59 ok(SOSAccountAssertUserCredentials(alice_account
, cfaccount
, cfpassword
, &error
), "Credential setting (%@)", error
);
61 ok(SOSAccountTryUserCredentials(alice_account
, cfaccount
, cfpassword
, &error
), "Credential trying (%@)", error
);
63 CFReleaseNull(cfpassword
);
65 ok(!SOSAccountTryUserCredentials(alice_account
, cfaccount
, cfwrong_password
, &error
), "Credential failing (%@)", error
);
66 CFReleaseNull(cfwrong_password
);
67 is(error
? CFErrorGetCode(error
) : 0, kSOSErrorWrongPassword
, "Expected SOSErrorWrongPassword");
70 CFDataRef incompatibleDER
= SOSCircleCreateIncompatibleCircleDER(&error
);
72 CFDictionarySetValue(changes
, circle_key_name
, incompatibleDER
);
74 FeedChangesTo(changes
, alice_account
);
75 CFReleaseNull(incompatibleDER
);
76 CFReleaseNull(circle_key_name
);
77 is(SOSAccountIsInCircles(alice_account
, &error
), kSOSCCError
, "Is in circle");
81 ok(SOSAccountResetToOffering(alice_account
, &error
), "Reset to offering (%@)", error
);
84 FeedChangesTo(changes
, bob_account
);
86 ok(SOSAccountJoinCircles(bob_account
, &error
), "Bob Applies (%@)", error
);
89 FeedChangesTo(changes
, alice_account
);
92 CFArrayRef applicants
= SOSAccountCopyApplicants(alice_account
, &error
);
94 ok(applicants
&& CFArrayGetCount(applicants
) == 1, "See one applicant %@ (%@)", applicants
, error
);
95 ok(SOSAccountAcceptApplicants(alice_account
, applicants
, &error
), "Alice accepts (%@)", error
);
97 CFReleaseNull(applicants
);
101 FeedChangesTo(changes
, bob_account
); // Bob sees he's accepted
103 FeedChangesTo(changes
, alice_account
); // Alice sees bob-concurring
105 ok(CFDictionaryGetCount(changes
) == 0, "We converged. (%@)", changes
);
107 accounts_agree("bob&alice pair", bob_account
, alice_account
);
109 CFArrayRef peers
= SOSAccountCopyPeers(alice_account
, &error
);
110 ok(peers
&& CFArrayGetCount(peers
) == 2, "See two peers %@ (%@)", peers
, error
);
111 CFReleaseNull(peers
);
113 CFDictionaryRef alice_new_gestalt
= SOSCreatePeerGestaltFromName(CFSTR("Alice, but different"));
115 ok(SOSAccountUpdateGestalt(alice_account
, alice_new_gestalt
), "Update gestalt %@ (%@)", alice_account
, error
);
116 CFReleaseNull(alice_new_gestalt
);
118 FeedChangesTo(changes
, bob_account
); // Bob sees alice change her name.
120 FeedChangesTo(changes
, alice_account
); // Alice sees the fallout.
122 accounts_agree("Alice's name changed", bob_account
, alice_account
);
124 ok(SOSAccountLeaveCircles(alice_account
, &error
), "Alice Leaves (%@)", error
);
125 CFReleaseNull(error
);
127 FeedChangesTo(changes
, bob_account
); // Bob sees alice bail.
129 FeedChangesTo(changes
, alice_account
); // Alice sees the fallout.
131 accounts_agree("Alice bails", bob_account
, alice_account
);
133 peers
= SOSAccountCopyPeers(alice_account
, &error
);
134 ok(peers
&& CFArrayGetCount(peers
) == 1, "See one peer %@ (%@)", peers
, error
);
135 CFReleaseNull(peers
);
137 ok(SOSAccountJoinCircles(alice_account
, &error
), "Alice re-applies (%@)", error
);
138 CFReleaseNull(error
);
140 FeedChangesTo(changes
, bob_account
);
144 CFArrayRef applicants
= SOSAccountCopyApplicants(alice_account
, &error
);
146 ok(applicants
&& CFArrayGetCount(applicants
) == 1, "See one applicant %@ (%@)", applicants
, error
);
147 ok(SOSAccountAcceptApplicants(bob_account
, applicants
, &error
), "Bob accepts (%@)", error
);
148 CFReleaseNull(error
);
149 CFReleaseNull(applicants
);
152 FeedChangesTo(changes
, alice_account
); // Alice sees bob accepting
154 FeedChangesTo(changes
, bob_account
); // Bob sees Alice concurring
156 accounts_agree("Alice accepts' Bob", bob_account
, alice_account
);
158 ok(SOSAccountLeaveCircles(alice_account
, &error
), "Alice Leaves (%@)", error
);
159 CFReleaseNull(error
);
160 ok(SOSAccountJoinCircles(alice_account
, &error
), "Alice re-applies (%@)", error
);
161 CFReleaseNull(error
);
163 FeedChangesTo(changes
, bob_account
); // Bob sees Alice leaving and rejoining
164 FeedChangesTo(changes
, alice_account
); // Alice sees bob concurring
167 CFArrayRef applicants
= SOSAccountCopyApplicants(alice_account
, &error
);
169 ok(applicants
&& CFArrayGetCount(applicants
) == 1, "See one applicant %@ (%@)", applicants
, error
);
170 ok(SOSAccountAcceptApplicants(bob_account
, applicants
, &error
), "Bob accepts (%@)", error
);
171 CFReleaseNull(error
);
172 CFReleaseNull(applicants
);
175 FeedChangesTo(changes
, alice_account
); // Alice sees bob accepting
177 FeedChangesTo(changes
, bob_account
); // Bob sees Alice concurring
179 accounts_agree("Bob accepts Alice", bob_account
, alice_account
);
182 CFReleaseNull(alice_new_gestalt
);
185 CFReleaseNull(bob_account
);
186 CFReleaseNull(alice_account
);
187 CFReleaseNull(carol_account
);
190 int secd_55_account_incompatibility(int argc
, char *const *argv
)
192 plan_tests(kTestTestCount
);