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