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 kTestTestCount 109
26 #define kAccountPasswordString ((uint8_t*) "FooFooFoo")
27 #define kAccountPasswordStringLen 10
29 static void tests(void) {
30 CFErrorRef error
= NULL
;
32 // Unretained aliases.
33 CFDataRef cfpassword
= CFDataCreate(NULL
, kAccountPasswordString
, kAccountPasswordStringLen
);
34 CFStringRef cfaccount
= CFSTR("test@test.org");
35 CFMutableDictionaryRef cfchanges
= CFDictionaryCreateMutableForCFTypes(kCFAllocatorDefault
);
37 SOSAccountRef alice_account
= CreateAccountForLocalChanges(CFSTR("Alice"), CFSTR("TestSource"));
38 SOSAccountRef bob_account
= CreateAccountForLocalChanges(CFSTR("Bob"), CFSTR("TestSource"));
39 SOSAccountRef carole_account
= CreateAccountForLocalChanges(CFSTR("Carole"), CFSTR("TestSource"));
40 SOSAccountRef david_account
= CreateAccountForLocalChanges(CFSTR("David"), CFSTR("TestSource"));
42 CFArrayRef aView
= CFArrayCreateForCFTypes(kCFAllocatorDefault
,
46 CFArrayRef wifiView
= CFArrayCreateForCFTypes(kCFAllocatorDefault
,
50 CFArrayRef otherView
= CFArrayCreateForCFTypes(kCFAllocatorDefault
,
51 kSOSViewOtherSyncable
,
54 CFArrayRef otherAndWifiViews
= CFArrayCreateForCFTypes(kCFAllocatorDefault
,
56 kSOSViewOtherSyncable
,
59 is(SOSAccountPeersHaveViewsEnabled(carole_account
, aView
, &error
), NULL
, "Peer views empty (%@)", error
);
62 ok(SOSAccountAssertUserCredentialsAndUpdate(bob_account
, cfaccount
, cfpassword
, &error
), "Credential setting (%@)", error
);
64 // Bob wins writing at this point, feed the changes back to alice.
65 is(ProcessChangesUntilNoChange(cfchanges
, alice_account
, bob_account
, carole_account
, david_account
, NULL
), 1, "updates");
67 ok(SOSAccountAssertUserCredentialsAndUpdate(alice_account
, cfaccount
, cfpassword
, &error
), "Credential setting (%@)", error
);
70 ok(SOSAccountAssertUserCredentialsAndUpdate(carole_account
, cfaccount
, cfpassword
, &error
), "Credential setting (%@)", error
);
73 ok(SOSAccountAssertUserCredentialsAndUpdate(david_account
, cfaccount
, cfpassword
, &error
), "Credential setting (%@)", error
);
74 CFReleaseNull(cfpassword
);
77 ok(SOSAccountResetToOffering_wTxn(alice_account
, &error
), "Reset to offering (%@)", error
);
80 is(ProcessChangesUntilNoChange(cfchanges
, alice_account
, bob_account
, carole_account
, david_account
, NULL
), 2, "updates");
82 is(SOSAccountPeersHaveViewsEnabled(alice_account
, aView
, &error
), kCFBooleanFalse
, "Peer views empty (%@)", error
);
85 ok(SOSAccountJoinCircles_wTxn(bob_account
, &error
), "Bob Applies (%@)", error
);
88 ok(SOSAccountJoinCircles_wTxn(carole_account
, &error
), "Carole Applies too (%@)", error
);
91 ok(SOSAccountJoinCircles_wTxn(david_account
, &error
), "David Applies too (%@)", error
);
94 is(ProcessChangesUntilNoChange(cfchanges
, alice_account
, bob_account
, carole_account
, david_account
, NULL
), 4, "updates");
96 is(SOSAccountPeersHaveViewsEnabled(carole_account
, aView
, &error
), NULL
, "Peer views empty (%@)", error
);
100 CFArrayRef applicants
= SOSAccountCopyApplicants(alice_account
, &error
);
102 ok(applicants
&& CFArrayGetCount(applicants
) == 3, "See three applicants %@ (%@)", applicants
, error
);
103 CFReleaseNull(error
);
104 ok(SOSAccountAcceptApplicants(alice_account
, applicants
, &error
), "Accept bob into the fold");
105 CFReleaseNull(error
);
106 CFReleaseSafe(applicants
);
109 is(ProcessChangesUntilNoChange(cfchanges
, alice_account
, bob_account
, carole_account
, david_account
, NULL
), 5, "updates");
111 // Make all views work buy finishing initial sync.
112 SOSAccountPeerGotInSync_wTxn(bob_account
, SOSAccountGetMyPeerInfo(alice_account
));
113 SOSAccountPeerGotInSync_wTxn(carole_account
, SOSAccountGetMyPeerInfo(alice_account
));
114 SOSAccountPeerGotInSync_wTxn(david_account
, SOSAccountGetMyPeerInfo(alice_account
));
116 is(ProcessChangesUntilNoChange(cfchanges
, alice_account
, bob_account
, carole_account
, david_account
, NULL
), 4, "updates");
118 is(SOSAccountPeersHaveViewsEnabled(alice_account
, aView
, &error
), kCFBooleanTrue
, "Peer views empty (%@)", error
);
119 CFReleaseNull(error
);
121 is(SOSAccountPeersHaveViewsEnabled(alice_account
, wifiView
, &error
), kCFBooleanFalse
, "Peer views empty (%@)", error
);
122 CFReleaseNull(error
);
124 ok(SOSAccountUpdateView_wTxn(alice_account
, kSOSViewWiFi
, kSOSCCViewEnable
, &error
), "Enable view (%@)", error
);
125 CFReleaseNull(error
);
127 ok(SOSAccountUpdateView_wTxn(bob_account
, kSOSViewOtherSyncable
, kSOSCCViewEnable
, &error
), "Enable view (%@)", error
);
128 CFReleaseNull(error
);
130 is(ProcessChangesUntilNoChange(cfchanges
, alice_account
, bob_account
, carole_account
, david_account
, NULL
), 3, "updates");
132 is(SOSAccountPeersHaveViewsEnabled(alice_account
, wifiView
, &error
), kCFBooleanFalse
, "Wifi view for Alice (%@)", error
);
133 CFReleaseNull(error
);
135 is(SOSAccountPeersHaveViewsEnabled(alice_account
, otherView
, &error
), kCFBooleanTrue
, "other view for Alice (%@)", error
);
136 CFReleaseNull(error
);
138 is(SOSAccountPeersHaveViewsEnabled(alice_account
, otherAndWifiViews
, &error
), kCFBooleanFalse
, "both for Alice (%@)", error
);
139 CFReleaseNull(error
);
141 is(SOSAccountPeersHaveViewsEnabled(bob_account
, wifiView
, &error
), kCFBooleanTrue
, "Wifi view for Bob (%@)", error
);
142 CFReleaseNull(error
);
144 is(SOSAccountPeersHaveViewsEnabled(bob_account
, otherView
, &error
), kCFBooleanFalse
, "other view for Bob (%@)", error
);
145 CFReleaseNull(error
);
147 is(SOSAccountPeersHaveViewsEnabled(bob_account
, otherAndWifiViews
, &error
), kCFBooleanFalse
, "both for Bob (%@)", error
);
148 CFReleaseNull(error
);
150 is(SOSAccountPeersHaveViewsEnabled(carole_account
, wifiView
, &error
), kCFBooleanTrue
, "Wifi view for Carole (%@)", error
);
151 CFReleaseNull(error
);
153 is(SOSAccountPeersHaveViewsEnabled(carole_account
, otherView
, &error
), kCFBooleanTrue
, "other view for Carole (%@)", error
);
154 CFReleaseNull(error
);
156 is(SOSAccountPeersHaveViewsEnabled(carole_account
, otherAndWifiViews
, &error
), kCFBooleanTrue
, "both for Carole (%@)", error
);
157 CFReleaseNull(error
);
159 CFReleaseNull(aView
);
160 CFReleaseNull(wifiView
);
161 CFReleaseNull(otherView
);
162 CFReleaseNull(otherAndWifiViews
);
164 CFReleaseNull(bob_account
);
165 CFReleaseNull(alice_account
);
166 CFReleaseNull(carole_account
);
167 CFReleaseNull(david_account
);
172 int secd_130_other_peer_views(int argc
, char *const *argv
)
174 plan_tests(kTestTestCount
);
176 secd_test_setup_temp_keychain(__FUNCTION__
, NULL
);