]> git.saurik.com Git - apple/security.git/blob - keychain/securityd/Regressions/secd-130-other-peer-views.m
Security-59306.41.2.tar.gz
[apple/security.git] / keychain / 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 "keychain/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 CFSetRef initialSyncViews = SOSViewCopyViewSet(kViewSetInitial);
35 int initialSyncViewCount = (int) CFSetGetCount(initialSyncViews);
36 CFReleaseNull(initialSyncViews);
37
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"));
42
43 CFArrayRef aView = CFArrayCreateForCFTypes(kCFAllocatorDefault,
44 kSOSViewPCSMasterKey,
45 NULL);
46
47 CFArrayRef wifiView = CFArrayCreateForCFTypes(kCFAllocatorDefault,
48 kSOSViewWiFi,
49 NULL);
50
51 CFArrayRef otherView = CFArrayCreateForCFTypes(kCFAllocatorDefault,
52 kSOSViewOtherSyncable,
53 NULL);
54
55 CFArrayRef otherAndWifiViews = CFArrayCreateForCFTypes(kCFAllocatorDefault,
56 kSOSViewWiFi,
57 kSOSViewOtherSyncable,
58 NULL);
59
60 is(SOSAccountPeersHaveViewsEnabled(carole_account, aView, &error), NULL, "Peer views empty (%@)", error);
61 CFReleaseNull(error);
62
63 ok(SOSAccountAssertUserCredentialsAndUpdate(bob_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
64
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");
67
68 ok(SOSAccountAssertUserCredentialsAndUpdate(alice_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
69 CFReleaseNull(error);
70
71 ok(SOSAccountAssertUserCredentialsAndUpdate(carole_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
72 CFReleaseNull(error);
73
74 ok(SOSAccountAssertUserCredentialsAndUpdate(david_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
75 CFReleaseNull(cfpassword);
76 CFReleaseNull(error);
77
78 ok(SOSAccountResetToOffering_wTxn(alice_account, &error), "Reset to offering (%@)", error);
79 CFReleaseNull(error);
80
81 is(ProcessChangesUntilNoChange(cfchanges, alice_account, bob_account, carole_account, david_account, NULL), 2, "updates");
82
83 is(SOSAccountPeersHaveViewsEnabled(alice_account, aView, &error), kCFBooleanFalse, "Peer views empty (%@)", error);
84 CFReleaseNull(error);
85
86 ok(SOSAccountJoinCircles_wTxn(bob_account, &error), "Bob Applies (%@)", error);
87 CFReleaseNull(error);
88
89 ok(SOSAccountJoinCircles_wTxn(carole_account, &error), "Carole Applies too (%@)", error);
90 CFReleaseNull(error);
91
92 ok(SOSAccountJoinCircles_wTxn(david_account, &error), "David Applies too (%@)", error);
93 CFReleaseNull(error);
94
95 is(ProcessChangesUntilNoChange(cfchanges, alice_account, bob_account, carole_account, david_account, NULL), 4, "updates");
96
97 is(SOSAccountPeersHaveViewsEnabled(carole_account, aView, &error), NULL, "Peer views empty (%@)", error);
98 CFReleaseNull(error);
99
100 {
101 CFArrayRef applicants = SOSAccountCopyApplicants(alice_account, &error);
102
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);
108 }
109
110 is(ProcessChangesUntilNoChange(cfchanges, alice_account, bob_account, carole_account, david_account, NULL), 5, "updates");
111
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);
116
117 int changeCount = (initialSyncViewCount) ? 4 : 1;
118 is(ProcessChangesUntilNoChange(cfchanges, alice_account, bob_account, carole_account, david_account, NULL), changeCount, "updates");
119
120 is(SOSAccountPeersHaveViewsEnabled(alice_account, aView, &error), kCFBooleanTrue, "Peer views empty (%@)", error);
121 CFReleaseNull(error);
122
123 is(SOSAccountPeersHaveViewsEnabled(alice_account, wifiView, &error), kCFBooleanFalse, "Peer views empty (%@)", error);
124 CFReleaseNull(error);
125
126 ok(SOSAccountUpdateView_wTxn(alice_account, kSOSViewWiFi, kSOSCCViewEnable, &error), "Enable view (%@)", error);
127 CFReleaseNull(error);
128
129 ok(SOSAccountUpdateView_wTxn(bob_account, kSOSViewOtherSyncable, kSOSCCViewEnable, &error), "Enable view (%@)", error);
130 CFReleaseNull(error);
131
132 is(ProcessChangesUntilNoChange(cfchanges, alice_account, bob_account, carole_account, david_account, NULL), 3, "updates");
133
134 is(SOSAccountPeersHaveViewsEnabled(alice_account, wifiView, &error), kCFBooleanFalse, "Wifi view for Alice (%@)", error);
135 CFReleaseNull(error);
136
137 is(SOSAccountPeersHaveViewsEnabled(alice_account, otherView, &error), kCFBooleanTrue, "other view for Alice (%@)", error);
138 CFReleaseNull(error);
139
140 is(SOSAccountPeersHaveViewsEnabled(alice_account, otherAndWifiViews, &error), kCFBooleanFalse, "both for Alice (%@)", error);
141 CFReleaseNull(error);
142
143 is(SOSAccountPeersHaveViewsEnabled(bob_account, wifiView, &error), kCFBooleanTrue, "Wifi view for Bob (%@)", error);
144 CFReleaseNull(error);
145
146 is(SOSAccountPeersHaveViewsEnabled(bob_account, otherView, &error), kCFBooleanFalse, "other view for Bob (%@)", error);
147 CFReleaseNull(error);
148
149 is(SOSAccountPeersHaveViewsEnabled(bob_account, otherAndWifiViews, &error), kCFBooleanFalse, "both for Bob (%@)", error);
150 CFReleaseNull(error);
151
152 is(SOSAccountPeersHaveViewsEnabled(carole_account, wifiView, &error), kCFBooleanTrue, "Wifi view for Carole (%@)", error);
153 CFReleaseNull(error);
154
155 is(SOSAccountPeersHaveViewsEnabled(carole_account, otherView, &error), kCFBooleanTrue, "other view for Carole (%@)", error);
156 CFReleaseNull(error);
157
158 is(SOSAccountPeersHaveViewsEnabled(carole_account, otherAndWifiViews, &error), kCFBooleanTrue, "both for Carole (%@)", error);
159 CFReleaseNull(error);
160
161 CFReleaseNull(aView);
162 CFReleaseNull(wifiView);
163 CFReleaseNull(otherView);
164 CFReleaseNull(otherAndWifiViews);
165
166 SOSTestCleanup();
167 }
168
169 int secd_130_other_peer_views(int argc, char *const *argv)
170 {
171 plan_tests(72);
172
173 secd_test_setup_temp_keychain(__FUNCTION__, NULL);
174 secd_test_clear_testviews();
175 tests();
176
177 return 0;
178 }