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"
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);
34 CFSetRef initialSyncViews = SOSViewCopyViewSet(kViewSetInitial);
35 int initialSyncViewCount = (int) CFSetGetCount(initialSyncViews);
36 CFReleaseNull(initialSyncViews);
38 SOSAccount* alice_account = CreateAccountForLocalChanges(CFSTR("Alice"), CFSTR("TestSource"));
39 SOSAccount* bob_account = CreateAccountForLocalChanges(CFSTR("Bob"), CFSTR("TestSource"));
40 SOSAccount* carole_account = CreateAccountForLocalChanges(CFSTR("Carole"), CFSTR("TestSource"));
41 SOSAccount* david_account = CreateAccountForLocalChanges(CFSTR("David"), CFSTR("TestSource"));
43 CFArrayRef aView = CFArrayCreateForCFTypes(kCFAllocatorDefault,
47 CFArrayRef wifiView = CFArrayCreateForCFTypes(kCFAllocatorDefault,
51 CFArrayRef otherView = CFArrayCreateForCFTypes(kCFAllocatorDefault,
52 kSOSViewOtherSyncable,
55 CFArrayRef otherAndWifiViews = CFArrayCreateForCFTypes(kCFAllocatorDefault,
57 kSOSViewOtherSyncable,
60 is(SOSAccountPeersHaveViewsEnabled(carole_account, aView, &error), NULL, "Peer views empty (%@)", error);
63 ok(SOSAccountAssertUserCredentialsAndUpdate(bob_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
65 // Bob wins writing at this point, feed the changes back to alice.
66 is(ProcessChangesUntilNoChange(cfchanges, alice_account, bob_account, carole_account, david_account, NULL), 1, "updates");
68 ok(SOSAccountAssertUserCredentialsAndUpdate(alice_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
71 ok(SOSAccountAssertUserCredentialsAndUpdate(carole_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
74 ok(SOSAccountAssertUserCredentialsAndUpdate(david_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
75 CFReleaseNull(cfpassword);
78 ok(SOSAccountResetToOffering_wTxn(alice_account, &error), "Reset to offering (%@)", error);
81 is(ProcessChangesUntilNoChange(cfchanges, alice_account, bob_account, carole_account, david_account, NULL), 2, "updates");
83 is(SOSAccountPeersHaveViewsEnabled(alice_account, aView, &error), kCFBooleanFalse, "Peer views empty (%@)", error);
86 ok(SOSAccountJoinCircles_wTxn(bob_account, &error), "Bob Applies (%@)", error);
89 ok(SOSAccountJoinCircles_wTxn(carole_account, &error), "Carole Applies too (%@)", error);
92 ok(SOSAccountJoinCircles_wTxn(david_account, &error), "David Applies too (%@)", error);
95 is(ProcessChangesUntilNoChange(cfchanges, alice_account, bob_account, carole_account, david_account, NULL), 4, "updates");
97 is(SOSAccountPeersHaveViewsEnabled(carole_account, aView, &error), NULL, "Peer views empty (%@)", error);
101 CFArrayRef applicants = SOSAccountCopyApplicants(alice_account, &error);
103 ok(applicants && CFArrayGetCount(applicants) == 3, "See three applicants %@ (%@)", applicants, error);
104 CFReleaseNull(error);
105 ok(SOSAccountAcceptApplicants(alice_account, applicants, &error), "Accept bob into the fold");
106 CFReleaseNull(error);
107 CFReleaseSafe(applicants);
110 is(ProcessChangesUntilNoChange(cfchanges, alice_account, bob_account, carole_account, david_account, NULL), 5, "updates");
112 // Make all views work buy finishing initial sync.
113 SOSAccountPeerGotInSync_wTxn(bob_account, alice_account.peerInfo);
114 SOSAccountPeerGotInSync_wTxn(carole_account, alice_account.peerInfo);
115 SOSAccountPeerGotInSync_wTxn(david_account, alice_account.peerInfo);
117 int changeCount = (initialSyncViewCount) ? 4 : 1;
118 is(ProcessChangesUntilNoChange(cfchanges, alice_account, bob_account, carole_account, david_account, NULL), changeCount, "updates");
120 is(SOSAccountPeersHaveViewsEnabled(alice_account, aView, &error), kCFBooleanTrue, "Peer views empty (%@)", error);
121 CFReleaseNull(error);
123 is(SOSAccountPeersHaveViewsEnabled(alice_account, wifiView, &error), kCFBooleanFalse, "Peer views empty (%@)", error);
124 CFReleaseNull(error);
126 ok(SOSAccountUpdateView_wTxn(alice_account, kSOSViewWiFi, kSOSCCViewEnable, &error), "Enable view (%@)", error);
127 CFReleaseNull(error);
129 ok(SOSAccountUpdateView_wTxn(bob_account, kSOSViewOtherSyncable, kSOSCCViewEnable, &error), "Enable view (%@)", error);
130 CFReleaseNull(error);
132 is(ProcessChangesUntilNoChange(cfchanges, alice_account, bob_account, carole_account, david_account, NULL), 3, "updates");
134 is(SOSAccountPeersHaveViewsEnabled(alice_account, wifiView, &error), kCFBooleanFalse, "Wifi view for Alice (%@)", error);
135 CFReleaseNull(error);
137 is(SOSAccountPeersHaveViewsEnabled(alice_account, otherView, &error), kCFBooleanTrue, "other view for Alice (%@)", error);
138 CFReleaseNull(error);
140 is(SOSAccountPeersHaveViewsEnabled(alice_account, otherAndWifiViews, &error), kCFBooleanFalse, "both for Alice (%@)", error);
141 CFReleaseNull(error);
143 is(SOSAccountPeersHaveViewsEnabled(bob_account, wifiView, &error), kCFBooleanTrue, "Wifi view for Bob (%@)", error);
144 CFReleaseNull(error);
146 is(SOSAccountPeersHaveViewsEnabled(bob_account, otherView, &error), kCFBooleanFalse, "other view for Bob (%@)", error);
147 CFReleaseNull(error);
149 is(SOSAccountPeersHaveViewsEnabled(bob_account, otherAndWifiViews, &error), kCFBooleanFalse, "both for Bob (%@)", error);
150 CFReleaseNull(error);
152 is(SOSAccountPeersHaveViewsEnabled(carole_account, wifiView, &error), kCFBooleanTrue, "Wifi view for Carole (%@)", error);
153 CFReleaseNull(error);
155 is(SOSAccountPeersHaveViewsEnabled(carole_account, otherView, &error), kCFBooleanTrue, "other view for Carole (%@)", error);
156 CFReleaseNull(error);
158 is(SOSAccountPeersHaveViewsEnabled(carole_account, otherAndWifiViews, &error), kCFBooleanTrue, "both for Carole (%@)", error);
159 CFReleaseNull(error);
161 CFReleaseNull(aView);
162 CFReleaseNull(wifiView);
163 CFReleaseNull(otherView);
164 CFReleaseNull(otherAndWifiViews);
169 int secd_130_other_peer_views(int argc, char *const *argv)
173 secd_test_setup_temp_keychain(__FUNCTION__, NULL);
174 secd_test_clear_testviews();