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>
46 #include "secd_regressions.h"
47 #include "SOSTestDataSource.h"
49 #include "SOSRegressionUtilities.h"
50 #include <utilities/SecCFWrappers.h>
52 #include <securityd/SOSCloudCircleServer.h>
53 #include "SecdTestKeychainUtilities.h"
54 #include "SOSAccountTesting.h"
57 static void testView(SOSAccountRef account
, SOSViewResultCode expected
, CFStringRef view
, SOSViewActionCode action
, char *label
) {
58 CFErrorRef error
= NULL
;
59 SOSViewResultCode vcode
= 9999;
62 vcode
= SOSAccountViewStatus(account
, view
, &error
);
64 case kSOSCCViewEnable
:
65 case kSOSCCViewDisable
: // fallthrough
66 vcode
= SOSAccountUpdateView(account
, view
, action
, &error
);
71 is(vcode
, expected
, "%s (%@)", label
, error
);
75 static int kTestTestCount
= 21;
76 static void tests(void)
78 CFErrorRef error
= NULL
;
79 CFDataRef cfpassword
= CFDataCreate(NULL
, (uint8_t *) "FooFooFoo", 10);
80 CFStringRef cfaccount
= CFSTR("test@test.org");
82 SOSDataSourceFactoryRef test_factory
= SOSTestDataSourceFactoryCreate();
83 SOSDataSourceRef test_source
= SOSTestDataSourceCreate();
84 SOSTestDataSourceFactorySetDataSource(test_factory
, CFSTR("TestType"), test_source
);
86 SOSAccountRef account
= CreateAccountForLocalChanges(CFSTR("Test Device"),CFSTR("TestType") );
88 ok(SOSAccountAssertUserCredentialsAndUpdate(account
, cfaccount
, cfpassword
, &error
), "Credential setting (%@)", error
);
90 CFReleaseNull(cfpassword
);
92 ok(SOSAccountJoinCircles(account
, &error
), "Join Cirlce");
94 ok(NULL
!= account
, "Created");
96 testView(account
, kSOSCCViewNotMember
, kSOSViewKeychainV0
, kSOSCCViewQuery
, "Expected view capability for kSOSViewKeychain");
97 // Default views no longer includes kSOSViewAppleTV
98 testView(account
, kSOSCCViewMember
, kSOSViewAppleTV
, kSOSCCViewQuery
, "Expected view capability for kSOSViewAppleTV");
99 testView(account
, kSOSCCViewMember
, kSOSViewPCSPhotos
, kSOSCCViewQuery
, "Expected no view capability for kSOSViewPCSPhotos");
100 testView(account
, kSOSCCViewMember
, kSOSViewPCSiCloudDrive
, kSOSCCViewQuery
, "Expected no view capability for kSOSViewPCSiCloudDrive");
101 testView(account
, kSOSCCNoSuchView
, CFSTR("FOO"), kSOSCCViewQuery
, "Expected no such view for FOO");
103 testView(account
, kSOSCCViewMember
, kSOSViewPCSiCloudDrive
, kSOSCCViewEnable
, "Expected to enable kSOSViewPCSiCloudDrive");
104 testView(account
, kSOSCCViewMember
, kSOSViewPCSiCloudDrive
, kSOSCCViewQuery
, "Expected view capability for kSOSViewPCSiCloudDrive");
105 testView(account
, kSOSCCViewNotMember
, kSOSViewPCSiCloudDrive
, kSOSCCViewDisable
, "Expected to disable kSOSViewPCSiCloudDrive");
106 testView(account
, kSOSCCViewNotMember
, kSOSViewPCSiCloudDrive
, kSOSCCViewQuery
, "Expected no view capability for kSOSViewPCSiCloudDrive");
108 testView(account
, kSOSCCViewMember
, kSOSViewPCSiCloudDrive
, kSOSCCViewEnable
, "Expected to enable kSOSViewPCSiCloudDrive");
109 testView(account
, kSOSCCViewMember
, kSOSViewPCSiCloudDrive
, kSOSCCViewQuery
, "Expected view capability for kSOSViewPCSiCloudDrive");
110 testView(account
, kSOSCCViewNotMember
, kSOSViewKeychainV0
, kSOSCCViewEnable
, "Expected to enable kSOSViewKeychainV0");
111 testView(account
, kSOSCCViewMember
, kSOSViewPCSiCloudDrive
, kSOSCCViewQuery
, "Expected view capability for kSOSViewPCSiCloudDrive");
112 testView(account
, kSOSCCViewMember
, kSOSViewAppleTV
, kSOSCCViewEnable
, "Expected to enable kSOSViewAppleTV");
114 testView(account
, kSOSCCViewMember
, kSOSViewPCSiCloudDrive
, kSOSCCViewQuery
, "Expected view capability for kSOSViewPCSiCloudDrive");
115 testView(account
, kSOSCCViewNotMember
, kSOSViewKeychainV0
, kSOSCCViewQuery
, "Expected view capability for kSOSViewKeychainV0");
116 testView(account
, kSOSCCViewMember
, kSOSViewAppleTV
, kSOSCCViewQuery
, "Expected view capability for kSOSViewAppleTV");
118 CFReleaseNull(account
);
120 SOSDataSourceRelease(test_source
, NULL
);
121 SOSDataSourceFactoryRelease(test_factory
);
123 SOSUnregisterAllTransportMessages();
124 SOSUnregisterAllTransportCircles();
125 SOSUnregisterAllTransportKeyParameters();
127 CFArrayRemoveAllValues(key_transports
);
128 CFArrayRemoveAllValues(circle_transports
);
129 CFArrayRemoveAllValues(message_transports
);
133 int secd_80_views_basic(int argc
, char *const *argv
)
135 plan_tests(kTestTestCount
);
137 secd_test_setup_temp_keychain(__FUNCTION__
, NULL
);