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 <Security/SecureObjectSync/SOSAccount.h>
39 #include <Security/SecureObjectSync/SOSCloudCircle.h>
40 #include <Security/SecureObjectSync/SOSInternal.h>
41 #include <Security/SecureObjectSync/SOSFullPeerInfo.h>
42 #include <Security/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 <securityd/SOSCloudCircleServer.h>
55 #include "SecdTestKeychainUtilities.h"
56 #include "SOSAccountTesting.h"
59 static void testView(SOSAccountRef account
, SOSViewResultCode expected
, CFStringRef view
, SOSViewActionCode action
, char *label
) {
60 CFErrorRef error
= NULL
;
61 SOSViewResultCode vcode
= 9999;
64 vcode
= SOSAccountViewStatus(account
, view
, &error
);
66 case kSOSCCViewEnable
:
67 case kSOSCCViewDisable
: // fallthrough
68 vcode
= SOSAccountUpdateView(account
, view
, action
, &error
);
73 is(vcode
, expected
, "%s (%@)", label
, error
);
77 static void testViewLists(void) {
78 CFSetRef allViews
= SOSViewCopyViewSet(kViewSetAll
);
79 CFSetRef defaultViews
= SOSViewCopyViewSet(kViewSetDefault
);
80 CFSetRef initialViews
= SOSViewCopyViewSet(kViewSetInitial
);
81 CFSetRef alwaysOnViews
= SOSViewCopyViewSet(kViewSetAlwaysOn
);
82 CFSetRef backupRequiredViews
= SOSViewCopyViewSet(kViewSetRequiredForBackup
);
83 CFSetRef V0Views
= SOSViewCopyViewSet(kViewSetV0
);
85 is(CFSetGetCount(allViews
), 22, "make sure count of allViews is correct");
86 is(CFSetGetCount(defaultViews
), 18, "make sure count of defaultViews is correct");
87 is(CFSetGetCount(initialViews
), 5, "make sure count of initialViews is correct");
88 is(CFSetGetCount(alwaysOnViews
), 18, "make sure count of alwaysOnViews is correct");
89 is(CFSetGetCount(backupRequiredViews
), 3, "make sure count of backupRequiredViews is correct");
90 is(CFSetGetCount(V0Views
), 6, "make sure count of V0Views is correct");
92 CFReleaseNull(allViews
);
93 CFReleaseNull(defaultViews
);
94 CFReleaseNull(initialViews
);
95 CFReleaseNull(alwaysOnViews
);
96 CFReleaseNull(backupRequiredViews
);
97 CFReleaseNull(V0Views
);
100 static int kTestTestCount
= 38;
101 static void tests(void)
103 CFErrorRef error
= NULL
;
104 CFDataRef cfpassword
= CFDataCreate(NULL
, (uint8_t *) "FooFooFoo", 10);
105 CFStringRef cfaccount
= CFSTR("test@test.org");
106 CFSetRef nullSet
= CFSetCreateMutableForCFTypes(kCFAllocatorDefault
);
108 SOSDataSourceFactoryRef test_factory
= SOSTestDataSourceFactoryCreate();
109 SOSDataSourceRef test_source
= SOSTestDataSourceCreate();
110 SOSTestDataSourceFactorySetDataSource(test_factory
, CFSTR("TestType"), test_source
);
112 SOSAccountRef account
= CreateAccountForLocalChanges(CFSTR("Test Device"),CFSTR("TestType") );
114 ok(SOSAccountAssertUserCredentialsAndUpdate(account
, cfaccount
, cfpassword
, &error
), "Credential setting (%@)", error
);
115 CFReleaseNull(error
);
116 CFReleaseNull(cfpassword
);
118 ok(SOSAccountJoinCircles_wTxn(account
, &error
), "Join circle: %@", error
);
120 ok(NULL
!= account
, "Created");
122 ok(SOSAccountCheckHasBeenInSync_wTxn(account
), "In sync already");
124 testView(account
, kSOSCCViewNotMember
, kSOSViewKeychainV0
, kSOSCCViewQuery
, "Expected view capability for kSOSViewKeychain");
125 // Default views no longer includes kSOSViewAppleTV
126 testView(account
, kSOSCCViewMember
, kSOSViewAppleTV
, kSOSCCViewQuery
, "Expected view capability for kSOSViewAppleTV");
127 testView(account
, kSOSCCViewMember
, kSOSViewPCSPhotos
, kSOSCCViewQuery
, "Expected no view capability for kSOSViewPCSPhotos");
128 testView(account
, kSOSCCViewMember
, kSOSViewPCSiCloudDrive
, kSOSCCViewQuery
, "Expected no view capability for kSOSViewPCSiCloudDrive");
129 testView(account
, kSOSCCNoSuchView
, CFSTR("FOO"), kSOSCCViewQuery
, "Expected no such view for FOO");
131 testView(account
, kSOSCCViewMember
, kSOSViewPCSiCloudDrive
, kSOSCCViewEnable
, "Expected to enable kSOSViewPCSiCloudDrive");
132 testView(account
, kSOSCCViewMember
, kSOSViewPCSiCloudDrive
, kSOSCCViewQuery
, "Expected view capability for kSOSViewPCSiCloudDrive");
133 testView(account
, kSOSCCViewNotMember
, kSOSViewPCSiCloudDrive
, kSOSCCViewDisable
, "Expected to disable kSOSViewPCSiCloudDrive");
134 testView(account
, kSOSCCViewNotMember
, kSOSViewPCSiCloudDrive
, kSOSCCViewQuery
, "Expected no view capability for kSOSViewPCSiCloudDrive");
136 testView(account
, kSOSCCViewMember
, kSOSViewPCSiCloudDrive
, kSOSCCViewEnable
, "Expected to enable kSOSViewPCSiCloudDrive");
137 testView(account
, kSOSCCViewMember
, kSOSViewPCSiCloudDrive
, kSOSCCViewQuery
, "Expected view capability for kSOSViewPCSiCloudDrive");
138 testView(account
, kSOSCCViewNotMember
, kSOSViewKeychainV0
, kSOSCCViewEnable
, "Expected to enable kSOSViewKeychainV0");
139 testView(account
, kSOSCCViewMember
, kSOSViewPCSiCloudDrive
, kSOSCCViewQuery
, "Expected view capability for kSOSViewPCSiCloudDrive");
140 testView(account
, kSOSCCViewMember
, kSOSViewAppleTV
, kSOSCCViewEnable
, "Expected to enable kSOSViewAppleTV");
142 testView(account
, kSOSCCViewMember
, kSOSViewPCSiCloudDrive
, kSOSCCViewQuery
, "Expected view capability for kSOSViewPCSiCloudDrive");
143 testView(account
, kSOSCCViewNotMember
, kSOSViewKeychainV0
, kSOSCCViewQuery
, "Expected view capability for kSOSViewKeychainV0");
144 testView(account
, kSOSCCViewMember
, kSOSViewAppleTV
, kSOSCCViewQuery
, "Expected view capability for kSOSViewAppleTV");
146 ok(SOSAccountUpdateViewSets(account
, SOSViewsGetV0ViewSet(), nullSet
), "Expect not accepting kSOSKeychainV0");
147 testView(account
, kSOSCCViewNotMember
, kSOSViewKeychainV0
, kSOSCCViewQuery
, "Expected no addition of kSOSKeychainV0");
149 ok(SOSAccountUpdateViewSets(account
, SOSViewsGetV0ViewSet(), nullSet
), "Expect not accepting kSOSKeychainV0");
150 testView(account
, kSOSCCViewNotMember
, kSOSViewKeychainV0
, kSOSCCViewQuery
, "Expected no addition of kSOSKeychainV0");
152 SOSPeerInfoRef pi
= SOSAccountGetMyPeerInfo(account
);
153 ok(pi
, "should have the peerInfo");
154 SOSViewResultCode vr
= SOSViewsEnable(pi
, kSOSViewKeychainV0
, NULL
);
156 ok(vr
== kSOSCCViewMember
, "Set Virtual View manually");
158 ok(!SOSAccountUpdateViewSets(account
, nullSet
, SOSViewsGetV0ViewSet()), "Expect not removing kSOSKeychainV0");
159 testView(account
, kSOSCCViewMember
, kSOSViewKeychainV0
, kSOSCCViewQuery
, "Expected kSOSKeychainV0 is still there");
161 ok(!SOSAccountUpdateViewSets(account
, nullSet
, SOSViewsGetV0ViewSet()), "Expect not removing kSOSKeychainV0");
162 testView(account
, kSOSCCViewMember
, kSOSViewKeychainV0
, kSOSCCViewQuery
, "Expected kSOSKeychainV0 is still there");
166 CFReleaseNull(account
);
168 SOSDataSourceRelease(test_source
, NULL
);
169 SOSDataSourceFactoryRelease(test_factory
);
171 SOSUnregisterAllTransportMessages();
172 SOSUnregisterAllTransportCircles();
173 SOSUnregisterAllTransportKeyParameters();
175 CFArrayRemoveAllValues(key_transports
);
176 CFArrayRemoveAllValues(circle_transports
);
177 CFArrayRemoveAllValues(message_transports
);
181 int secd_80_views_basic(int argc
, char *const *argv
)
183 plan_tests(kTestTestCount
);
185 secd_test_setup_temp_keychain(__FUNCTION__
, NULL
);