]> git.saurik.com Git - apple/security.git/blob - OSX/sec/securityd/Regressions/secd-100-initialsync.c
Security-57740.1.18.tar.gz
[apple/security.git] / OSX / sec / securityd / Regressions / secd-100-initialsync.c
1 //
2 // secd-100-initialsync.c
3 // sec
4 //
5
6
7 /*
8 * Copyright (c) 2014 Apple Inc. All Rights Reserved.
9 *
10 * @APPLE_LICENSE_HEADER_START@
11 *
12 * This file contains Original Code and/or Modifications of Original Code
13 * as defined in and that are subject to the Apple Public Source License
14 * Version 2.0 (the 'License'). You may not use this file except in
15 * compliance with the License. Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this
17 * file.
18 *
19 * The Original Code and all software distributed under the License are
20 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
21 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
22 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
24 * Please see the License for the specific language governing rights and
25 * limitations under the License.
26 *
27 * @APPLE_LICENSE_HEADER_END@
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 <utilities/SecCFWrappers.h>
47 #include <Security/SecKeyPriv.h>
48
49 #include <securityd/SOSCloudCircleServer.h>
50
51 #include "SOSAccountTesting.h"
52
53 #include "SecdTestKeychainUtilities.h"
54
55 static int kTestTestCount = 43;
56
57 static void tests(void)
58 {
59
60 CFErrorRef error = NULL;
61 CFDataRef cfpassword = CFDataCreate(NULL, (uint8_t *) "FooFooFoo", 10);
62 CFStringRef cfaccount = CFSTR("test@test.org");
63
64 CFMutableDictionaryRef changes = CFDictionaryCreateMutableForCFTypes(kCFAllocatorDefault);
65
66 SOSDataSourceFactoryRef test_factory = SOSTestDataSourceFactoryCreate();
67 SOSDataSourceRef test_source = SOSTestDataSourceCreate();
68 SOSTestDataSourceFactorySetDataSource(test_factory, CFSTR("TestType"), test_source);
69
70 SOSAccountRef alice_account = CreateAccountForLocalChanges(CFSTR("AliceAccount"),CFSTR("TestType") );
71 SOSAccountRef bob_account = CreateAccountForLocalChanges(CFSTR("BobAccount"),CFSTR("TestType") );
72
73 ok(SOSAccountAssertUserCredentialsAndUpdate(alice_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
74
75 ok(SOSAccountJoinCircles_wTxn(alice_account, &error), "Join circle: %@", error);
76 ok(SOSAccountCheckHasBeenInSync_wTxn(alice_account), "Alice account initial sync done");
77
78 ok(SOSAccountAssertUserCredentialsAndUpdate(bob_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
79 CFReleaseNull(error);
80 CFReleaseNull(cfpassword);
81
82 is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, NULL), 1, "updates");
83
84 ok(SOSAccountJoinCircles_wTxn(bob_account, &error), "Bob Applies (%@)", error);
85 CFReleaseNull(error);
86
87 is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, NULL), 4, "updates");
88
89 {
90 CFArrayRef applicants = SOSAccountCopyApplicants(alice_account, &error);
91
92 ok(applicants && CFArrayGetCount(applicants) == 1, "See one applicant %@ (%@)", applicants, error);
93 ok(SOSAccountAcceptApplicants(alice_account, applicants, &error), "Alice accepts (%@)", error);
94 CFReleaseNull(error);
95 CFReleaseNull(applicants);
96 }
97
98
99 is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, NULL), 3, "updates");
100
101 accounts_agree("bob&alice pair", bob_account, alice_account);
102
103 ok(!SOSAccountCheckHasBeenInSync_wTxn(bob_account), "Bob should not be initially synced");
104 CFSetRef bob_viewSet = SOSPeerInfoCopyEnabledViews(SOSAccountGetMyPeerInfo(bob_account));
105 is(CFSetGetCount(bob_viewSet), 5, "bob's initial view set should be just the 14 views");
106 CFReleaseNull(bob_viewSet);
107
108 ok(!SOSAccountCheckHasBeenInSync_wTxn(bob_account), "Bob should not be initially synced");
109 SOSAccountPeerGotInSync_wTxn(bob_account, SOSAccountGetMyPeerInfo(alice_account));
110
111 bob_viewSet = SOSPeerInfoCopyEnabledViews(SOSAccountGetMyPeerInfo(bob_account));
112 is(CFSetGetCount(bob_viewSet), 18, "bob's initial view set should be just the back up");
113 CFReleaseNull(bob_viewSet);
114
115 }
116
117 int secd_100_initialsync(int argc, char *const *argv)
118 {
119 plan_tests(kTestTestCount);
120
121 secd_test_setup_temp_keychain(__FUNCTION__, NULL);
122
123 tests();
124
125 return 0;
126 }