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/SOSTransport.h>
41 #include "secd_regressions.h"
42 #include "SOSTestDataSource.h"
44 #include "SOSRegressionUtilities.h"
45 #include <utilities/SecCFWrappers.h>
46 #include <Security/SecKeyPriv.h>
48 #include <securityd/SOSCloudCircleServer.h>
50 #include "SOSAccountTesting.h"
52 static int kTestTestCount
= 145;
56 static void tests(void)
58 CFErrorRef error
= NULL
;
59 CFDataRef cfpassword
= CFDataCreate(NULL
, (uint8_t *) "FooFooFoo", 10);
60 CFStringRef cfaccount
= CFSTR("test@test.org");
62 CFMutableDictionaryRef changes
= CFDictionaryCreateMutableForCFTypes(kCFAllocatorDefault
);
64 SOSAccountRef alice_account
= CreateAccountForLocalChanges( CFSTR("Alice"), CFSTR("TestSource"));
65 SOSAccountRef bob_account
= CreateAccountForLocalChanges(CFSTR("Bob"), CFSTR("TestSource"));
66 SOSAccountRef carole_account
= CreateAccountForLocalChanges(CFSTR("Carole"), CFSTR("TestSource"));
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 CFReleaseNull(cfpassword
);
79 ok(SOSAccountResetToOffering(alice_account
, &error
), "Reset to offering (%@)", error
);
82 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carole_account
, NULL
), 2, "updates");
84 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 /*----- normal join after restore -----*/
103 ok(SOSAccountJoinCirclesAfterRestore(carole_account
, &error
), "Carole cloud identity joins (%@)", error
);
104 CFReleaseNull(error
);
105 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carole_account
, NULL
), 4, "updates");
107 is(countApplicants(alice_account
), 0, "See no applicants");
109 is(countPeers(carole_account
), 3, "Carole sees 3 valid peers after sliding in");
111 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carole_account
, NULL
), 1, "updates");
113 accounts_agree_internal("Carole's in", bob_account
, alice_account
, false);
114 accounts_agree_internal("Carole's in - 2", bob_account
, carole_account
, false);
116 ok(SOSAccountLeaveCircles(carole_account
, &error
), "Carol Leaves again");
117 CFReleaseNull(error
);
119 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carole_account
, NULL
), 3, "updates");
121 /*----- join - join after restore -----*/
123 ok(SOSAccountJoinCircles(carole_account
, &error
), "Carole normally joins (%@)", error
);
124 CFReleaseNull(error
);
126 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carole_account
, NULL
), 2, "updates");
128 is(countApplicants(alice_account
), 1, "See one applicant");
130 ok(SOSAccountJoinCirclesAfterRestore(carole_account
, &error
), "Carole cloud identity joins (%@)", error
);
131 CFReleaseNull(error
);
133 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carole_account
, NULL
), 4, "updates");
136 is(countApplicants(alice_account
), 0, "See no applicants");
138 is(countPeers(carole_account
), 3, "Carole sees 3 valid peers after sliding in");
140 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, carole_account
, NULL
), 1, "updates");
142 accounts_agree_internal("Carole's in", bob_account
, alice_account
, false);
143 accounts_agree_internal("Carole's in - 2", bob_account
, carole_account
, false);
145 CFReleaseNull(bob_account
);
146 CFReleaseNull(alice_account
);
147 CFReleaseNull(carole_account
);
149 SOSUnregisterAllTransportMessages();
150 SOSUnregisterAllTransportCircles();
151 SOSUnregisterAllTransportKeyParameters();
152 CFArrayRemoveAllValues(key_transports
);
153 CFArrayRemoveAllValues(circle_transports
);
154 CFArrayRemoveAllValues(message_transports
);
158 int secd_60_account_cloud_identity(int argc
, char *const *argv
)
160 plan_tests(kTestTestCount
);