]> git.saurik.com Git - apple/security.git/blob - OSX/sec/securityd/Regressions/secd-130-other-peer-views.m
Security-58286.41.2.tar.gz
[apple/security.git] / OSX / sec / securityd / Regressions / secd-130-other-peer-views.m
1 //
2 // secd-130-other-peer-views.m
3 // sec
4 //
5 // Created by Mitch Adler on 7/9/16.
6 //
7 //
8
9 #include <stdlib.h>
10 #include <unistd.h>
11
12 #include "secd_regressions.h"
13
14 #include "SOSRegressionUtilities.h"
15 #include <utilities/SecCFWrappers.h>
16 #include <Security/SecKeyPriv.h>
17
18 #include "SecdTestKeychainUtilities.h"
19
20 #include "SOSAccountTesting.h"
21
22 #include <Security/SecureObjectSync/SOSAccount.h>
23
24 #define kAccountPasswordString ((uint8_t*) "FooFooFoo")
25 #define kAccountPasswordStringLen 10
26
27 static void tests(void) {
28 CFErrorRef error = NULL;
29
30 // Unretained aliases.
31 CFDataRef cfpassword = CFDataCreate(NULL, kAccountPasswordString, kAccountPasswordStringLen);
32 CFStringRef cfaccount = CFSTR("test@test.org");
33 CFMutableDictionaryRef cfchanges = CFDictionaryCreateMutableForCFTypes(kCFAllocatorDefault);
34
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"));
39
40 CFArrayRef aView = CFArrayCreateForCFTypes(kCFAllocatorDefault,
41 kSOSViewPCSMasterKey,
42 NULL);
43
44 CFArrayRef wifiView = CFArrayCreateForCFTypes(kCFAllocatorDefault,
45 kSOSViewWiFi,
46 NULL);
47
48 CFArrayRef otherView = CFArrayCreateForCFTypes(kCFAllocatorDefault,
49 kSOSViewOtherSyncable,
50 NULL);
51
52 CFArrayRef otherAndWifiViews = CFArrayCreateForCFTypes(kCFAllocatorDefault,
53 kSOSViewWiFi,
54 kSOSViewOtherSyncable,
55 NULL);
56
57 is(SOSAccountPeersHaveViewsEnabled(carole_account, aView, &error), NULL, "Peer views empty (%@)", error);
58 CFReleaseNull(error);
59
60 ok(SOSAccountAssertUserCredentialsAndUpdate(bob_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
61
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");
64
65 ok(SOSAccountAssertUserCredentialsAndUpdate(alice_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
66 CFReleaseNull(error);
67
68 ok(SOSAccountAssertUserCredentialsAndUpdate(carole_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
69 CFReleaseNull(error);
70
71 ok(SOSAccountAssertUserCredentialsAndUpdate(david_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
72 CFReleaseNull(cfpassword);
73 CFReleaseNull(error);
74
75 ok(SOSAccountResetToOffering_wTxn(alice_account, &error), "Reset to offering (%@)", error);
76 CFReleaseNull(error);
77
78 is(ProcessChangesUntilNoChange(cfchanges, alice_account, bob_account, carole_account, david_account, NULL), 2, "updates");
79
80 is(SOSAccountPeersHaveViewsEnabled(alice_account, aView, &error), kCFBooleanFalse, "Peer views empty (%@)", error);
81 CFReleaseNull(error);
82
83 ok(SOSAccountJoinCircles_wTxn(bob_account, &error), "Bob Applies (%@)", error);
84 CFReleaseNull(error);
85
86 ok(SOSAccountJoinCircles_wTxn(carole_account, &error), "Carole Applies too (%@)", error);
87 CFReleaseNull(error);
88
89 ok(SOSAccountJoinCircles_wTxn(david_account, &error), "David Applies too (%@)", error);
90 CFReleaseNull(error);
91
92 is(ProcessChangesUntilNoChange(cfchanges, alice_account, bob_account, carole_account, david_account, NULL), 4, "updates");
93
94 is(SOSAccountPeersHaveViewsEnabled(carole_account, aView, &error), NULL, "Peer views empty (%@)", error);
95 CFReleaseNull(error);
96
97 {
98 CFArrayRef applicants = SOSAccountCopyApplicants(alice_account, &error);
99
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);
105 }
106
107 is(ProcessChangesUntilNoChange(cfchanges, alice_account, bob_account, carole_account, david_account, NULL), 5, "updates");
108
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);
113
114 is(ProcessChangesUntilNoChange(cfchanges, alice_account, bob_account, carole_account, david_account, NULL), 4, "updates");
115
116 is(SOSAccountPeersHaveViewsEnabled(alice_account, aView, &error), kCFBooleanTrue, "Peer views empty (%@)", error);
117 CFReleaseNull(error);
118
119 is(SOSAccountPeersHaveViewsEnabled(alice_account, wifiView, &error), kCFBooleanFalse, "Peer views empty (%@)", error);
120 CFReleaseNull(error);
121
122 ok(SOSAccountUpdateView_wTxn(alice_account, kSOSViewWiFi, kSOSCCViewEnable, &error), "Enable view (%@)", error);
123 CFReleaseNull(error);
124
125 ok(SOSAccountUpdateView_wTxn(bob_account, kSOSViewOtherSyncable, kSOSCCViewEnable, &error), "Enable view (%@)", error);
126 CFReleaseNull(error);
127
128 is(ProcessChangesUntilNoChange(cfchanges, alice_account, bob_account, carole_account, david_account, NULL), 3, "updates");
129
130 is(SOSAccountPeersHaveViewsEnabled(alice_account, wifiView, &error), kCFBooleanFalse, "Wifi view for Alice (%@)", error);
131 CFReleaseNull(error);
132
133 is(SOSAccountPeersHaveViewsEnabled(alice_account, otherView, &error), kCFBooleanTrue, "other view for Alice (%@)", error);
134 CFReleaseNull(error);
135
136 is(SOSAccountPeersHaveViewsEnabled(alice_account, otherAndWifiViews, &error), kCFBooleanFalse, "both for Alice (%@)", error);
137 CFReleaseNull(error);
138
139 is(SOSAccountPeersHaveViewsEnabled(bob_account, wifiView, &error), kCFBooleanTrue, "Wifi view for Bob (%@)", error);
140 CFReleaseNull(error);
141
142 is(SOSAccountPeersHaveViewsEnabled(bob_account, otherView, &error), kCFBooleanFalse, "other view for Bob (%@)", error);
143 CFReleaseNull(error);
144
145 is(SOSAccountPeersHaveViewsEnabled(bob_account, otherAndWifiViews, &error), kCFBooleanFalse, "both for Bob (%@)", error);
146 CFReleaseNull(error);
147
148 is(SOSAccountPeersHaveViewsEnabled(carole_account, wifiView, &error), kCFBooleanTrue, "Wifi view for Carole (%@)", error);
149 CFReleaseNull(error);
150
151 is(SOSAccountPeersHaveViewsEnabled(carole_account, otherView, &error), kCFBooleanTrue, "other view for Carole (%@)", error);
152 CFReleaseNull(error);
153
154 is(SOSAccountPeersHaveViewsEnabled(carole_account, otherAndWifiViews, &error), kCFBooleanTrue, "both for Carole (%@)", error);
155 CFReleaseNull(error);
156
157 CFReleaseNull(aView);
158 CFReleaseNull(wifiView);
159 CFReleaseNull(otherView);
160 CFReleaseNull(otherAndWifiViews);
161
162 SOSTestCleanup();
163 }
164
165 int secd_130_other_peer_views(int argc, char *const *argv)
166 {
167 plan_tests(107);
168
169 secd_test_setup_temp_keychain(__FUNCTION__, NULL);
170
171 tests();
172
173 return 0;
174 }