2 * Copyright (c) 2013-2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
27 #include <Security/SecBase.h>
28 #include <Security/SecItem.h>
30 #include <CoreFoundation/CFDictionary.h>
32 #include <SecureObjectSync/SOSAccount.h>
33 #include <SecureObjectSync/SOSCloudCircle.h>
34 #include <SecureObjectSync/SOSInternal.h>
35 #include <SecureObjectSync/SOSUserKeygen.h>
36 #include <SecureObjectSync/SOSKVSKeys.h>
37 #include <SecureObjectSync/SOSTransport.h>
42 #include "secd_regressions.h"
43 #include "SOSTestDataSource.h"
45 #include "SOSRegressionUtilities.h"
46 #include <utilities/SecCFWrappers.h>
47 #include <Security/SecKeyPriv.h>
49 #include <securityd/SOSCloudCircleServer.h>
51 #include "SOSAccountTesting.h"
53 static int kTestTestCount
= 136;
55 static void tests(void)
57 CFErrorRef error
= NULL
;
58 CFDataRef cfpassword
= CFDataCreate(NULL
, (uint8_t *) "FooFooFoo", 10);
59 CFStringRef cfaccount
= CFSTR("test@test.org");
60 CFStringRef circle_name
= CFSTR("TestSource");
62 CFMutableDictionaryRef changes
= CFDictionaryCreateMutableForCFTypes(kCFAllocatorDefault
);
64 SOSAccountRef alice_account
= CreateAccountForLocalChanges(CFSTR("Alice"), circle_name
);
65 SOSAccountRef bob_account
= CreateAccountForLocalChanges(CFSTR("Bob"), circle_name
);
66 SOSAccountRef carole_account
= CreateAccountForLocalChanges(CFSTR("Carole"), circle_name
);
68 ok(SOSAccountAssertUserCredentials(bob_account
, cfaccount
, cfpassword
, &error
), "Credential setting (%@)", error
);
70 // Bob wins writing at this point, feed the changes back to alice.
71 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carole_account
, NULL
), 1, "updates");
73 ok(SOSAccountAssertUserCredentials(alice_account
, cfaccount
, cfpassword
, &error
), "Credential setting (%@)", error
);
76 ok(SOSAccountAssertUserCredentials(carole_account
, cfaccount
, cfpassword
, &error
), "Credential setting (%@)", error
);
78 ok(SOSAccountResetToOffering(alice_account
, &error
), "Reset to offering (%@)", error
);
81 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carole_account
, NULL
), 2, "updates");
83 ok(SOSAccountJoinCircles(bob_account
, &error
), "Bob Applies (%@)", error
);
86 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carole_account
, NULL
), 2, "updates");
89 CFArrayRef applicants
= SOSAccountCopyApplicants(alice_account
, &error
);
91 ok(applicants
&& CFArrayGetCount(applicants
) == 1, "See one applicant %@ (%@)", applicants
, error
);
92 ok(SOSAccountAcceptApplicants(alice_account
, applicants
, &error
), "Alice accepts (%@)", error
);
94 CFReleaseNull(applicants
);
97 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carole_account
, NULL
), 3, "updates");
99 accounts_agree("bob&alice pair", bob_account
, alice_account
);
101 CFArrayRef peers
= SOSAccountCopyPeers(alice_account
, &error
);
102 ok(peers
&& CFArrayGetCount(peers
) == 2, "See two peers %@ (%@)", peers
, error
);
103 CFReleaseNull(peers
);
105 SOSFullPeerInfoRef fpiAlice
= SOSAccountGetMyFullPeerInCircleNamedIfPresent(alice_account
, circle_name
, NULL
);
106 CFStringRef alice_id
= CFStringCreateCopy(NULL
, SOSPeerInfoGetPeerID(SOSFullPeerInfoGetPeerInfo(fpiAlice
)));
108 ok(SOSAccountLeaveCircles(alice_account
, &error
), "Alice Leaves (%@)", error
);
109 CFReleaseNull(error
);
110 CFReleaseNull(cfpassword
);
112 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carole_account
, NULL
), 3, "updates");
114 accounts_agree("Alice bails", bob_account
, alice_account
);
115 accounts_agree("Alice bails", bob_account
, carole_account
);
117 SOSAccountCleanupRetirementTickets(bob_account
, 0, &error
);
119 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carole_account
, NULL
), 1, "updates");
121 //is(CFDictionaryGetCountOfValue(BobChanges, kCFNull),0, "0 Keys Nulled Out");
123 ok(SOSAccountJoinCircles(carole_account
, &error
), "Carole Applies (%@)", error
);
124 CFReleaseNull(error
);
126 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carole_account
, NULL
), 2, "updates");
130 CFArrayRef applicants
= SOSAccountCopyApplicants(bob_account
, &error
);
132 ok(applicants
&& CFArrayGetCount(applicants
) == 1, "See one applicant %@ (%@)", applicants
, error
);
133 ok(SOSAccountAcceptApplicants(bob_account
, applicants
, &error
), "Bob accepts Carole (%@)", error
);
134 CFReleaseNull(error
);
135 CFReleaseNull(applicants
);
138 // Bob should not yet cleanup Alice's retirment here on his own since it hasn't been long enough
140 //is(CFDictionaryGetCountOfValue(BobChanges, kCFNull),0, "0 Keys Nulled Out");
142 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carole_account
, NULL
), 3, "updates");
144 accounts_agree("Carole joins", bob_account
, carole_account
);
146 SOSAccountCleanupRetirementTickets(bob_account
, 0, &error
);
148 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carole_account
, NULL
), 2, "updates");
150 is(countPeers(bob_account
), 2, "Active peers after forced cleanup");
151 is(countActivePeers(bob_account
), 3, "Inactive peers after forced cleanup");
153 //is(CFDictionaryGetCountOfValue(BobChanges, kCFNull), 1, "1 Keys Nulled Out");
155 // CFDictionaryForEach(BobChanges, ^(const void *key, const void *value) {
156 // if(isNull(value)) {
157 // CFStringRef circle_name = NULL, retiree = NULL;
158 // SOSKVSKeyType keytype = SOSKVSKeyGetKeyTypeAndParse(key, &circle_name, &retiree, NULL);
159 // is(keytype, kRetirementKey, "Expect only a retirement key");
160 // ok(CFEqualSafe(alice_id, retiree), "Alice (%@) is retiree (%@)", alice_id, retiree);
161 // CFReleaseNull(circle_name);
162 // CFReleaseNull(retiree);
166 CFReleaseNull(alice_id
);
167 CFReleaseNull(carole_account
);
168 CFReleaseNull(bob_account
);
169 CFReleaseNull(alice_account
);
171 SOSUnregisterAllTransportMessages();
172 SOSUnregisterAllTransportCircles();
173 SOSUnregisterAllTransportKeyParameters();
174 CFArrayRemoveAllValues(key_transports
);
175 CFArrayRemoveAllValues(circle_transports
);
176 CFArrayRemoveAllValues(message_transports
);
180 int secd_59_account_cleanup(int argc
, char *const *argv
)
182 plan_tests(kTestTestCount
);