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 <Security/SecureObjectSync/SOSAccount.h>
24 #define kAccountPasswordString ((uint8_t*) "FooFooFoo")
25 #define kAccountPasswordStringLen 10
27 static void tests(void) {
28 CFErrorRef error = NULL;
30 // Unretained aliases.
31 CFDataRef cfpassword = CFDataCreate(NULL, kAccountPasswordString, kAccountPasswordStringLen);
32 CFStringRef cfaccount = CFSTR("test@test.org");
33 CFMutableDictionaryRef cfchanges = CFDictionaryCreateMutableForCFTypes(kCFAllocatorDefault);
35 SOSAccount* alice_account = CreateAccountForLocalChanges(CFSTR("Alice"), CFSTR("TestSource"));
36 SOSAccount* bob_account = CreateAccountForLocalChanges(CFSTR("Bob"), CFSTR("TestSource"));
37 SOSAccount* carole_account = CreateAccountForLocalChanges(CFSTR("Carole"), CFSTR("TestSource"));
38 SOSAccount* david_account = CreateAccountForLocalChanges(CFSTR("David"), CFSTR("TestSource"));
40 CFArrayRef aView = CFArrayCreateForCFTypes(kCFAllocatorDefault,
44 CFArrayRef wifiView = CFArrayCreateForCFTypes(kCFAllocatorDefault,
48 CFArrayRef otherView = CFArrayCreateForCFTypes(kCFAllocatorDefault,
49 kSOSViewOtherSyncable,
52 CFArrayRef otherAndWifiViews = CFArrayCreateForCFTypes(kCFAllocatorDefault,
54 kSOSViewOtherSyncable,
57 is(SOSAccountPeersHaveViewsEnabled(carole_account, aView, &error), NULL, "Peer views empty (%@)", error);
60 ok(SOSAccountAssertUserCredentialsAndUpdate(bob_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
62 // Bob wins writing at this point, feed the changes back to alice.
63 is(ProcessChangesUntilNoChange(cfchanges, alice_account, bob_account, carole_account, david_account, NULL), 1, "updates");
65 ok(SOSAccountAssertUserCredentialsAndUpdate(alice_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
68 ok(SOSAccountAssertUserCredentialsAndUpdate(carole_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
71 ok(SOSAccountAssertUserCredentialsAndUpdate(david_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
72 CFReleaseNull(cfpassword);
75 ok(SOSAccountResetToOffering_wTxn(alice_account, &error), "Reset to offering (%@)", error);
78 is(ProcessChangesUntilNoChange(cfchanges, alice_account, bob_account, carole_account, david_account, NULL), 2, "updates");
80 is(SOSAccountPeersHaveViewsEnabled(alice_account, aView, &error), kCFBooleanFalse, "Peer views empty (%@)", error);
83 ok(SOSAccountJoinCircles_wTxn(bob_account, &error), "Bob Applies (%@)", error);
86 ok(SOSAccountJoinCircles_wTxn(carole_account, &error), "Carole Applies too (%@)", error);
89 ok(SOSAccountJoinCircles_wTxn(david_account, &error), "David Applies too (%@)", error);
92 is(ProcessChangesUntilNoChange(cfchanges, alice_account, bob_account, carole_account, david_account, NULL), 4, "updates");
94 is(SOSAccountPeersHaveViewsEnabled(carole_account, aView, &error), NULL, "Peer views empty (%@)", error);
98 CFArrayRef applicants = SOSAccountCopyApplicants(alice_account, &error);
100 ok(applicants && CFArrayGetCount(applicants) == 3, "See three applicants %@ (%@)", applicants, error);
101 CFReleaseNull(error);
102 ok(SOSAccountAcceptApplicants(alice_account, applicants, &error), "Accept bob into the fold");
103 CFReleaseNull(error);
104 CFReleaseSafe(applicants);
107 is(ProcessChangesUntilNoChange(cfchanges, alice_account, bob_account, carole_account, david_account, NULL), 5, "updates");
109 // Make all views work buy finishing initial sync.
110 SOSAccountPeerGotInSync_wTxn(bob_account, alice_account.peerInfo);
111 SOSAccountPeerGotInSync_wTxn(carole_account, alice_account.peerInfo);
112 SOSAccountPeerGotInSync_wTxn(david_account, alice_account.peerInfo);
114 is(ProcessChangesUntilNoChange(cfchanges, alice_account, bob_account, carole_account, david_account, NULL), 4, "updates");
116 is(SOSAccountPeersHaveViewsEnabled(alice_account, aView, &error), kCFBooleanTrue, "Peer views empty (%@)", error);
117 CFReleaseNull(error);
119 is(SOSAccountPeersHaveViewsEnabled(alice_account, wifiView, &error), kCFBooleanFalse, "Peer views empty (%@)", error);
120 CFReleaseNull(error);
122 ok(SOSAccountUpdateView_wTxn(alice_account, kSOSViewWiFi, kSOSCCViewEnable, &error), "Enable view (%@)", error);
123 CFReleaseNull(error);
125 ok(SOSAccountUpdateView_wTxn(bob_account, kSOSViewOtherSyncable, kSOSCCViewEnable, &error), "Enable view (%@)", error);
126 CFReleaseNull(error);
128 is(ProcessChangesUntilNoChange(cfchanges, alice_account, bob_account, carole_account, david_account, NULL), 3, "updates");
130 is(SOSAccountPeersHaveViewsEnabled(alice_account, wifiView, &error), kCFBooleanFalse, "Wifi view for Alice (%@)", error);
131 CFReleaseNull(error);
133 is(SOSAccountPeersHaveViewsEnabled(alice_account, otherView, &error), kCFBooleanTrue, "other view for Alice (%@)", error);
134 CFReleaseNull(error);
136 is(SOSAccountPeersHaveViewsEnabled(alice_account, otherAndWifiViews, &error), kCFBooleanFalse, "both for Alice (%@)", error);
137 CFReleaseNull(error);
139 is(SOSAccountPeersHaveViewsEnabled(bob_account, wifiView, &error), kCFBooleanTrue, "Wifi view for Bob (%@)", error);
140 CFReleaseNull(error);
142 is(SOSAccountPeersHaveViewsEnabled(bob_account, otherView, &error), kCFBooleanFalse, "other view for Bob (%@)", error);
143 CFReleaseNull(error);
145 is(SOSAccountPeersHaveViewsEnabled(bob_account, otherAndWifiViews, &error), kCFBooleanFalse, "both for Bob (%@)", error);
146 CFReleaseNull(error);
148 is(SOSAccountPeersHaveViewsEnabled(carole_account, wifiView, &error), kCFBooleanTrue, "Wifi view for Carole (%@)", error);
149 CFReleaseNull(error);
151 is(SOSAccountPeersHaveViewsEnabled(carole_account, otherView, &error), kCFBooleanTrue, "other view for Carole (%@)", error);
152 CFReleaseNull(error);
154 is(SOSAccountPeersHaveViewsEnabled(carole_account, otherAndWifiViews, &error), kCFBooleanTrue, "both for Carole (%@)", error);
155 CFReleaseNull(error);
157 CFReleaseNull(aView);
158 CFReleaseNull(wifiView);
159 CFReleaseNull(otherView);
160 CFReleaseNull(otherAndWifiViews);
165 int secd_130_other_peer_views(int argc, char *const *argv)
169 secd_test_setup_temp_keychain(__FUNCTION__, NULL);