2 // secd-130-other-peer-views.m
5 // Created by Mitch Adler on 7/9/16.
12 #include "secd_regressions.h"
14 #include "SOSRegressionUtilities.h"
15 #include <utilities/SecCFWrappers.h>
16 #include <Security/SecKeyPriv.h>
18 #include "SecdTestKeychainUtilities.h"
20 #include "SOSAccountTesting.h"
22 #include "keychain/SecureObjectSync/SOSAccount.h"
25 #define kAccountPasswordString ((uint8_t*) "FooFooFoo")
26 #define kAccountPasswordStringLen 10
28 static void tests(void) {
29 CFErrorRef error = NULL;
31 // Unretained aliases.
32 CFDataRef cfpassword = CFDataCreate(NULL, kAccountPasswordString, kAccountPasswordStringLen);
33 CFStringRef cfaccount = CFSTR("test@test.org");
34 CFMutableDictionaryRef cfchanges = CFDictionaryCreateMutableForCFTypes(kCFAllocatorDefault);
35 CFSetRef initialSyncViews = SOSViewCopyViewSet(kViewSetInitial);
36 int initialSyncViewCount = (int) CFSetGetCount(initialSyncViews);
37 CFReleaseNull(initialSyncViews);
39 SOSAccount* alice_account = CreateAccountForLocalChanges(CFSTR("Alice"), CFSTR("TestSource"));
40 SOSAccount* bob_account = CreateAccountForLocalChanges(CFSTR("Bob"), CFSTR("TestSource"));
41 SOSAccount* carole_account = CreateAccountForLocalChanges(CFSTR("Carole"), CFSTR("TestSource"));
42 SOSAccount* david_account = CreateAccountForLocalChanges(CFSTR("David"), CFSTR("TestSource"));
44 CFArrayRef aView = CFArrayCreateForCFTypes(kCFAllocatorDefault,
48 CFArrayRef wifiView = CFArrayCreateForCFTypes(kCFAllocatorDefault,
52 CFArrayRef otherView = CFArrayCreateForCFTypes(kCFAllocatorDefault,
53 kSOSViewOtherSyncable,
56 CFArrayRef otherAndWifiViews = CFArrayCreateForCFTypes(kCFAllocatorDefault,
58 kSOSViewOtherSyncable,
61 is(SOSAccountPeersHaveViewsEnabled(carole_account, aView, &error), NULL, "Peer views empty (%@)", error);
64 ok(SOSAccountAssertUserCredentialsAndUpdate(bob_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
66 // Bob wins writing at this point, feed the changes back to alice.
67 is(ProcessChangesUntilNoChange(cfchanges, alice_account, bob_account, carole_account, david_account, NULL), 1, "updates");
69 ok(SOSAccountAssertUserCredentialsAndUpdate(alice_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
72 ok(SOSAccountAssertUserCredentialsAndUpdate(carole_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
75 ok(SOSAccountAssertUserCredentialsAndUpdate(david_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
76 CFReleaseNull(cfpassword);
79 ok(SOSAccountResetToOffering_wTxn(alice_account, &error), "Reset to offering (%@)", error);
82 is(ProcessChangesUntilNoChange(cfchanges, alice_account, bob_account, carole_account, david_account, NULL), 2, "updates");
84 is(SOSAccountPeersHaveViewsEnabled(alice_account, aView, &error), kCFBooleanFalse, "Peer views empty (%@)", error);
87 ok(SOSAccountJoinCircles_wTxn(bob_account, &error), "Bob Applies (%@)", error);
90 ok(SOSAccountJoinCircles_wTxn(carole_account, &error), "Carole Applies too (%@)", error);
93 ok(SOSAccountJoinCircles_wTxn(david_account, &error), "David Applies too (%@)", error);
96 is(ProcessChangesUntilNoChange(cfchanges, alice_account, bob_account, carole_account, david_account, NULL), 4, "updates");
98 is(SOSAccountPeersHaveViewsEnabled(carole_account, aView, &error), NULL, "Peer views empty (%@)", error);
102 CFArrayRef applicants = SOSAccountCopyApplicants(alice_account, &error);
104 ok(applicants && CFArrayGetCount(applicants) == 3, "See three applicants %@ (%@)", applicants, error);
105 CFReleaseNull(error);
106 ok(SOSAccountAcceptApplicants(alice_account, applicants, &error), "Accept bob into the fold");
107 CFReleaseNull(error);
108 CFReleaseSafe(applicants);
111 is(ProcessChangesUntilNoChange(cfchanges, alice_account, bob_account, carole_account, david_account, NULL), 5, "updates");
113 // Make all views work buy finishing initial sync.
114 SOSAccountPeerGotInSync_wTxn(bob_account, alice_account.peerInfo);
115 SOSAccountPeerGotInSync_wTxn(carole_account, alice_account.peerInfo);
116 SOSAccountPeerGotInSync_wTxn(david_account, alice_account.peerInfo);
118 int changeCount = (initialSyncViewCount) ? 4 : 1;
119 is(ProcessChangesUntilNoChange(cfchanges, alice_account, bob_account, carole_account, david_account, NULL), changeCount, "updates");
121 is(SOSAccountPeersHaveViewsEnabled(alice_account, aView, &error), kCFBooleanTrue, "Peer views empty (%@)", error);
122 CFReleaseNull(error);
124 is(SOSAccountPeersHaveViewsEnabled(alice_account, wifiView, &error), kCFBooleanFalse, "Peer views empty (%@)", error);
125 CFReleaseNull(error);
127 ok(SOSAccountUpdateView_wTxn(alice_account, kSOSViewWiFi, kSOSCCViewEnable, &error), "Enable view (%@)", error);
128 CFReleaseNull(error);
130 ok(SOSAccountUpdateView_wTxn(bob_account, kSOSViewOtherSyncable, kSOSCCViewEnable, &error), "Enable view (%@)", error);
131 CFReleaseNull(error);
133 is(ProcessChangesUntilNoChange(cfchanges, alice_account, bob_account, carole_account, david_account, NULL), 3, "updates");
135 is(SOSAccountPeersHaveViewsEnabled(alice_account, wifiView, &error), kCFBooleanFalse, "Wifi view for Alice (%@)", error);
136 CFReleaseNull(error);
138 is(SOSAccountPeersHaveViewsEnabled(alice_account, otherView, &error), kCFBooleanTrue, "other view for Alice (%@)", error);
139 CFReleaseNull(error);
141 is(SOSAccountPeersHaveViewsEnabled(alice_account, otherAndWifiViews, &error), kCFBooleanFalse, "both for Alice (%@)", error);
142 CFReleaseNull(error);
144 is(SOSAccountPeersHaveViewsEnabled(bob_account, wifiView, &error), kCFBooleanTrue, "Wifi view for Bob (%@)", error);
145 CFReleaseNull(error);
147 is(SOSAccountPeersHaveViewsEnabled(bob_account, otherView, &error), kCFBooleanFalse, "other view for Bob (%@)", error);
148 CFReleaseNull(error);
150 is(SOSAccountPeersHaveViewsEnabled(bob_account, otherAndWifiViews, &error), kCFBooleanFalse, "both for Bob (%@)", error);
151 CFReleaseNull(error);
153 is(SOSAccountPeersHaveViewsEnabled(carole_account, wifiView, &error), kCFBooleanTrue, "Wifi view for Carole (%@)", error);
154 CFReleaseNull(error);
156 is(SOSAccountPeersHaveViewsEnabled(carole_account, otherView, &error), kCFBooleanTrue, "other view for Carole (%@)", error);
157 CFReleaseNull(error);
159 is(SOSAccountPeersHaveViewsEnabled(carole_account, otherAndWifiViews, &error), kCFBooleanTrue, "both for Carole (%@)", error);
160 CFReleaseNull(error);
162 CFReleaseNull(aView);
163 CFReleaseNull(wifiView);
164 CFReleaseNull(otherView);
165 CFReleaseNull(otherAndWifiViews);
171 int secd_130_other_peer_views(int argc, char *const *argv)
175 secd_test_setup_temp_keychain(__FUNCTION__, NULL);
176 secd_test_clear_testviews();