]> git.saurik.com Git - apple/security.git/blob - OSX/sec/securityd/Regressions/secd-57-1-account-last-standing.c
Security-57740.60.18.tar.gz
[apple/security.git] / OSX / sec / securityd / Regressions / secd-57-1-account-last-standing.c
1 //
2 // secd-57-1-account-last-standing.c
3 // sec
4 //
5 /*
6 * Copyright (c) 2013-2014 Apple Inc. All Rights Reserved.
7 *
8 * @APPLE_LICENSE_HEADER_START@
9 *
10 * This file contains Original Code and/or Modifications of Original Code
11 * as defined in and that are subject to the Apple Public Source License
12 * Version 2.0 (the 'License'). You may not use this file except in
13 * compliance with the License. Please obtain a copy of the License at
14 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * file.
16 *
17 * The Original Code and all software distributed under the License are
18 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
19 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
20 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
22 * Please see the License for the specific language governing rights and
23 * limitations under the License.
24 *
25 * @APPLE_LICENSE_HEADER_END@
26 */
27
28
29
30
31 #include <Security/SecBase.h>
32 #include <Security/SecItem.h>
33
34 #include <CoreFoundation/CFDictionary.h>
35
36 #include <Security/SecureObjectSync/SOSAccount.h>
37 #include <Security/SecureObjectSync/SOSCloudCircle.h>
38 #include <Security/SecureObjectSync/SOSInternal.h>
39 #include <Security/SecureObjectSync/SOSUserKeygen.h>
40 #include <Security/SecureObjectSync/SOSTransport.h>
41
42 #include <stdlib.h>
43 #include <unistd.h>
44
45 #include "secd_regressions.h"
46 #include "SOSTestDataSource.h"
47
48 #include "SOSRegressionUtilities.h"
49 #include <utilities/SecCFWrappers.h>
50 #include <Security/SecKeyPriv.h>
51
52 #include <securityd/SOSCloudCircleServer.h>
53
54 #include "SOSAccountTesting.h"
55
56 #include "SecdTestKeychainUtilities.h"
57
58
59 static int kTestTestCount = 66;
60
61
62 static bool acceptApplicants(SOSAccountRef account, CFIndex count) {
63 bool retval = false;
64 CFErrorRef error = NULL;
65 CFArrayRef applicants = SOSAccountCopyApplicants(account, &error);
66 ok(applicants && CFArrayGetCount(applicants) == count, "See %ld applicants %@ (%@)", count, applicants, error);
67 CFReleaseNull(error);
68 require_quiet(CFArrayGetCount(applicants) == count, xit);
69 ok((retval=SOSAccountAcceptApplicants(account, applicants, &error)), "Accept applicants into the fold");
70 CFReleaseNull(error);
71 CFReleaseSafe(applicants);
72 xit:
73 return retval;
74 }
75
76
77 static void tests(void)
78 {
79 CFErrorRef error = NULL;
80 CFDataRef cfpassword = CFDataCreate(NULL, (uint8_t *) "FooFooFoo", 10);
81 CFStringRef cfaccount = CFSTR("test@test.org");
82
83 CFMutableDictionaryRef changes = CFDictionaryCreateMutableForCFTypes(kCFAllocatorDefault);
84
85 SOSAccountRef alice_account = CreateAccountForLocalChanges(CFSTR("Alice"), CFSTR("TestSource"));
86
87 ok(SOSAccountAssertUserCredentialsAndUpdate(alice_account , cfaccount, cfpassword, &error), "Credential setting (%@)", error);
88
89 is(ProcessChangesUntilNoChange(changes, alice_account, NULL), 1, "updates");
90
91 ok(SOSAccountResetToOffering_wTxn(alice_account , &error), "Reset to offering (%@)", error);
92 CFReleaseNull(error);
93
94 is(ProcessChangesUntilNoChange(changes, alice_account, NULL), 1, "updates");
95
96 ok(SOSAccountLeaveCircle(alice_account , &error), "Alice Leaves (%@)", error);
97 CFReleaseNull(error);
98
99 is(ProcessChangesUntilNoChange(changes, alice_account, NULL), 1, "updates");
100
101 ok(SOSAccountTryUserCredentials(alice_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
102 CFReleaseNull(error);
103
104 ok(SOSAccountJoinCircles_wTxn(alice_account , &error), "Alice re-applies (%@)", error);
105 CFReleaseNull(error);
106
107 is(ProcessChangesUntilNoChange(changes, alice_account, NULL), 1, "updates");
108
109 ok(SOSAccountIsInCircle(alice_account, &error), "Alice is back in the circle (%@)", error);
110 CFReleaseNull(error);
111
112 is(countActivePeers(alice_account), 2, "Alice sees 2 active peers");
113 is(countPeers(alice_account), 1, "Alice sees 1 valid peer");
114
115 // Have Alice leave the circle just as Bob tries to join.
116 SOSAccountRef bob_account = CreateAccountForLocalChanges(CFSTR("Bob"), CFSTR("TestSource"));
117 SOSAccountRef carole_account = CreateAccountForLocalChanges(CFSTR("Carole"), CFSTR("TestSource"));
118
119 is(ProcessChangesUntilNoChange(changes, bob_account, alice_account, carole_account, NULL), 1, "updates");
120 ok(SOSAccountTryUserCredentials(bob_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
121 CFReleaseNull(error);
122 ok(SOSAccountTryUserCredentials(carole_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
123 CFReleaseNull(error);
124 is(ProcessChangesUntilNoChange(changes, bob_account, alice_account, carole_account, NULL), 1, "updates");
125
126 ok(SOSAccountJoinCircles_wTxn(carole_account , &error), "Carole applies (%@)", error);
127 CFReleaseNull(error);
128 is(ProcessChangesUntilNoChange(changes, bob_account, alice_account, carole_account, NULL), 2, "updates");
129 ok(acceptApplicants(alice_account, 1), "Alice accepts Carole");
130 is(ProcessChangesUntilNoChange(changes, bob_account, alice_account, carole_account, NULL), 3, "updates");
131
132 ok(SOSAccountLeaveCircle(alice_account , &error), "Alice Leaves (%@)", error);
133 CFReleaseNull(error);
134 is(ProcessChangesUntilNoChange(changes, alice_account, carole_account, NULL), 2, "updates");
135
136 ok(SOSAccountLeaveCircle(carole_account , &error), "Carole Leaves (%@)", error);
137 CFReleaseNull(error);
138
139 is(ProcessChangesUntilNoChange(changes, alice_account, carole_account, NULL), 2, "updates");
140 ok(SOSAccountJoinCircles_wTxn(bob_account , &error), "Bob applies (%@)", error);
141 is(ProcessChangesUntilNoChange(changes, bob_account, NULL), 2, "updates");
142 CFReleaseNull(error);
143
144 is(countActivePeers(bob_account), 2, "Bob sees 2 active peers");
145 is(countPeers(bob_account), 1, "Bob sees 1 valid peer");
146
147
148 CFReleaseNull(cfpassword);
149 CFReleaseNull(alice_account);
150 CFReleaseNull(bob_account);
151
152 SOSTestCleanup();
153 }
154
155 int secd_57_1_account_last_standing(int argc, char *const *argv)
156 {
157 plan_tests(kTestTestCount);
158
159 secd_test_setup_temp_keychain(__FUNCTION__, NULL);
160
161 tests();
162
163 return 0;
164 }