2 // secd-80-views-basic.c
5 // Created by Richard Murphy on 1/26/15.
11 * Copyright (c) 2012-2014 Apple Inc. All Rights Reserved.
13 * @APPLE_LICENSE_HEADER_START@
15 * This file contains Original Code and/or Modifications of Original Code
16 * as defined in and that are subject to the Apple Public Source License
17 * Version 2.0 (the 'License'). You may not use this file except in
18 * compliance with the License. Please obtain a copy of the License at
19 * http://www.opensource.apple.com/apsl/ and read it before using this
22 * The Original Code and all software distributed under the License are
23 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
24 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
25 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
26 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
27 * Please see the License for the specific language governing rights and
28 * limitations under the License.
30 * @APPLE_LICENSE_HEADER_END@
35 #include <Security/SecBase.h>
36 #include <Security/SecItem.h>
38 #include "keychain/SecureObjectSync/SOSAccount.h"
39 #include <Security/SecureObjectSync/SOSCloudCircle.h>
40 #include "keychain/SecureObjectSync/SOSInternal.h"
41 #include "keychain/SecureObjectSync/SOSFullPeerInfo.h"
42 #include "keychain/SecureObjectSync/SOSUserKeygen.h"
43 #include <Security/SecureObjectSync/SOSViews.h>
48 #include "secd_regressions.h"
49 #include "SOSTestDataSource.h"
51 #include "SOSRegressionUtilities.h"
52 #include <utilities/SecCFWrappers.h>
54 #include "keychain/securityd/SOSCloudCircleServer.h"
55 #include "SecdTestKeychainUtilities.h"
56 #include "SOSAccountTesting.h"
60 static void testView(SOSAccount* account, SOSViewResultCode expected, CFStringRef view, SOSViewActionCode action, char *label) {
61 CFErrorRef error = NULL;
62 SOSViewResultCode vcode = 9999;
65 vcode = [account.trust viewStatus:account name:view err:&error];
67 case kSOSCCViewEnable:
68 case kSOSCCViewDisable: // fallthrough
69 vcode = [account.trust updateView:account name:view code:action err:&error];
74 is(vcode, expected, "%s (%@)", label, error);
78 static void testViewLists(void) {
79 CFSetRef allViews = SOSViewCopyViewSet(kViewSetAll);
80 CFSetRef defaultViews = SOSViewCopyViewSet(kViewSetDefault);
81 CFSetRef initialViews = SOSViewCopyViewSet(kViewSetInitial);
82 CFSetRef alwaysOnViews = SOSViewCopyViewSet(kViewSetAlwaysOn);
83 CFSetRef backupRequiredViews = SOSViewCopyViewSet(kViewSetRequiredForBackup);
84 CFSetRef V0Views = SOSViewCopyViewSet(kViewSetV0);
86 is(CFSetGetCount(allViews), 24, "make sure count of allViews is correct");
87 is(CFSetGetCount(defaultViews), 20, "make sure count of defaultViews is correct");
88 is(CFSetGetCount(initialViews), 0, "make sure count of initialViews is correct");
89 is(CFSetGetCount(alwaysOnViews), 20, "make sure count of alwaysOnViews is correct");
90 is(CFSetGetCount(backupRequiredViews), 3, "make sure count of backupRequiredViews is correct");
91 is(CFSetGetCount(V0Views), 6, "make sure count of V0Views is correct");
93 CFReleaseNull(allViews);
94 CFReleaseNull(defaultViews);
95 CFReleaseNull(initialViews);
96 CFReleaseNull(alwaysOnViews);
97 CFReleaseNull(backupRequiredViews);
98 CFReleaseNull(V0Views);
101 static int kTestTestCount = 38;
102 static void tests(void)
104 CFErrorRef error = NULL;
105 CFDataRef cfpassword = CFDataCreate(NULL, (uint8_t *) "FooFooFoo", 10);
106 CFStringRef cfaccount = CFSTR("test@test.org");
107 CFSetRef nullSet = CFSetCreateMutableForCFTypes(kCFAllocatorDefault);
109 SOSDataSourceFactoryRef test_factory = SOSTestDataSourceFactoryCreate();
110 SOSDataSourceRef test_source = SOSTestDataSourceCreate();
111 SOSTestDataSourceFactorySetDataSource(test_factory, CFSTR("TestType"), test_source);
113 SOSAccount* account = CreateAccountForLocalChanges(CFSTR("Test Device"),CFSTR("TestType") );
115 ok(SOSAccountAssertUserCredentialsAndUpdate(account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
116 CFReleaseNull(error);
117 CFReleaseNull(cfpassword);
119 ok(SOSAccountJoinCircles_wTxn(account, &error), "Join circle: %@", error);
121 ok(NULL != account, "Created");
123 ok(SOSAccountCheckHasBeenInSync_wTxn(account), "In sync already");
125 testView(account, kSOSCCViewNotMember, kSOSViewKeychainV0, kSOSCCViewQuery, "Expected view capability for kSOSViewKeychain");
126 // Default views no longer includes kSOSViewAppleTV
127 testView(account, kSOSCCViewMember, kSOSViewAppleTV, kSOSCCViewQuery, "Expected view capability for kSOSViewAppleTV");
128 testView(account, kSOSCCViewMember, kSOSViewPCSPhotos, kSOSCCViewQuery, "Expected no view capability for kSOSViewPCSPhotos");
129 testView(account, kSOSCCViewMember, kSOSViewPCSiCloudDrive, kSOSCCViewQuery, "Expected no view capability for kSOSViewPCSiCloudDrive");
130 testView(account, kSOSCCNoSuchView, CFSTR("FOO"), kSOSCCViewQuery, "Expected no such view for FOO");
132 testView(account, kSOSCCViewMember, kSOSViewPCSiCloudDrive, kSOSCCViewEnable, "Expected to enable kSOSViewPCSiCloudDrive");
133 testView(account, kSOSCCViewMember, kSOSViewPCSiCloudDrive, kSOSCCViewQuery, "Expected view capability for kSOSViewPCSiCloudDrive");
134 testView(account, kSOSCCViewMember, kSOSViewPCSiCloudDrive, kSOSCCViewDisable, "Expected cannot disable kSOSViewPCSiCloudDrive");
135 testView(account, kSOSCCViewMember, kSOSViewPCSiCloudDrive, kSOSCCViewQuery, "Expected view capability for kSOSViewPCSiCloudDrive");
137 testView(account, kSOSCCViewMember, kSOSViewPCSiCloudDrive, kSOSCCViewEnable, "Expected to enable kSOSViewPCSiCloudDrive");
138 testView(account, kSOSCCViewMember, kSOSViewPCSiCloudDrive, kSOSCCViewQuery, "Expected view capability for kSOSViewPCSiCloudDrive");
139 testView(account, kSOSCCViewNotMember, kSOSViewKeychainV0, kSOSCCViewEnable, "Expected to enable kSOSViewKeychainV0");
140 testView(account, kSOSCCViewMember, kSOSViewPCSiCloudDrive, kSOSCCViewQuery, "Expected view capability for kSOSViewPCSiCloudDrive");
141 testView(account, kSOSCCViewMember, kSOSViewAppleTV, kSOSCCViewEnable, "Expected to enable kSOSViewAppleTV");
143 testView(account, kSOSCCViewMember, kSOSViewPCSiCloudDrive, kSOSCCViewQuery, "Expected view capability for kSOSViewPCSiCloudDrive");
144 testView(account, kSOSCCViewNotMember, kSOSViewKeychainV0, kSOSCCViewQuery, "Expected view capability for kSOSViewKeychainV0");
145 testView(account, kSOSCCViewMember, kSOSViewAppleTV, kSOSCCViewQuery, "Expected view capability for kSOSViewAppleTV");
147 ok([account.trust updateViewSets:account enabled:SOSViewsGetV0ViewSet() disabled:nullSet], "Expect not accepting kSOSKeychainV0");
148 testView(account, kSOSCCViewNotMember, kSOSViewKeychainV0, kSOSCCViewQuery, "Expected no addition of kSOSKeychainV0");
150 ok([account.trust updateViewSets:account enabled:SOSViewsGetV0ViewSet() disabled:nullSet], "Expect not accepting kSOSKeychainV0");
151 testView(account, kSOSCCViewNotMember, kSOSViewKeychainV0, kSOSCCViewQuery, "Expected no addition of kSOSKeychainV0");
153 SOSPeerInfoRef pi = account.peerInfo;
154 ok(pi, "should have the peerInfo");
155 SOSViewResultCode vr = SOSViewsEnable(pi, kSOSViewKeychainV0, NULL);
157 ok(vr == kSOSCCViewMember, "Set Virtual View manually");
159 ok(![account.trust updateViewSets:account enabled:nullSet disabled:SOSViewsGetV0ViewSet()], "Expect not removing kSOSKeychainV0");
160 testView(account, kSOSCCViewMember, kSOSViewKeychainV0, kSOSCCViewQuery, "Expected kSOSKeychainV0 is still there");
162 ok(![account.trust updateViewSets:account enabled:nullSet disabled:SOSViewsGetV0ViewSet()], "Expect not removing kSOSKeychainV0");
163 testView(account, kSOSCCViewMember, kSOSViewKeychainV0, kSOSCCViewQuery, "Expected kSOSKeychainV0 is still there");
165 SOSDataSourceRelease(test_source, NULL);
166 SOSDataSourceFactoryRelease(test_factory);
172 int secd_80_views_basic(int argc, char *const *argv)
175 plan_tests(kTestTestCount);
176 secd_test_setup_temp_keychain(__FUNCTION__, NULL);
177 secd_test_clear_testviews();