]> git.saurik.com Git - apple/security.git/blob - OSX/sec/securityd/Regressions/secd-80-views-basic.c
Security-57337.40.85.tar.gz
[apple/security.git] / OSX / sec / securityd / Regressions / secd-80-views-basic.c
1 //
2 // secd-80-views-basic.c
3 // sec
4 //
5 // Created by Richard Murphy on 1/26/15.
6 //
7 //
8
9 #include <stdio.h>
10 /*
11 * Copyright (c) 2012-2014 Apple Inc. All Rights Reserved.
12 *
13 * @APPLE_LICENSE_HEADER_START@
14 *
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
20 * file.
21 *
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.
29 *
30 * @APPLE_LICENSE_HEADER_END@
31 */
32
33
34
35 #include <Security/SecBase.h>
36 #include <Security/SecItem.h>
37
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 <stdlib.h>
44 #include <unistd.h>
45
46 #include "secd_regressions.h"
47 #include "SOSTestDataSource.h"
48
49 #include "SOSRegressionUtilities.h"
50 #include <utilities/SecCFWrappers.h>
51
52 #include <securityd/SOSCloudCircleServer.h>
53 #include "SecdTestKeychainUtilities.h"
54 #include "SOSAccountTesting.h"
55
56
57 static void testView(SOSAccountRef account, SOSViewResultCode expected, CFStringRef view, SOSViewActionCode action, char *label) {
58 CFErrorRef error = NULL;
59 SOSViewResultCode vcode = 9999;
60 switch(action) {
61 case kSOSCCViewQuery:
62 vcode = SOSAccountViewStatus(account, view, &error);
63 break;
64 case kSOSCCViewEnable:
65 case kSOSCCViewDisable: // fallthrough
66 vcode = SOSAccountUpdateView(account, view, action, &error);
67 break;
68 default:
69 break;
70 }
71 is(vcode, expected, "%s (%@)", label, error);
72 CFReleaseNull(error);
73 }
74
75 static int kTestTestCount = 21;
76 static void tests(void)
77 {
78 CFErrorRef error = NULL;
79 CFDataRef cfpassword = CFDataCreate(NULL, (uint8_t *) "FooFooFoo", 10);
80 CFStringRef cfaccount = CFSTR("test@test.org");
81
82 SOSDataSourceFactoryRef test_factory = SOSTestDataSourceFactoryCreate();
83 SOSDataSourceRef test_source = SOSTestDataSourceCreate();
84 SOSTestDataSourceFactorySetDataSource(test_factory, CFSTR("TestType"), test_source);
85
86 SOSAccountRef account = CreateAccountForLocalChanges(CFSTR("Test Device"),CFSTR("TestType") );
87
88 ok(SOSAccountAssertUserCredentialsAndUpdate(account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
89 CFReleaseNull(error);
90 CFReleaseNull(cfpassword);
91
92 ok(SOSAccountJoinCircles(account, &error), "Join circle: %@", error);
93
94 ok(NULL != account, "Created");
95
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");
102
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");
107
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");
113
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");
117
118 CFReleaseNull(account);
119
120 SOSDataSourceRelease(test_source, NULL);
121 SOSDataSourceFactoryRelease(test_factory);
122
123 SOSUnregisterAllTransportMessages();
124 SOSUnregisterAllTransportCircles();
125 SOSUnregisterAllTransportKeyParameters();
126
127 CFArrayRemoveAllValues(key_transports);
128 CFArrayRemoveAllValues(circle_transports);
129 CFArrayRemoveAllValues(message_transports);
130
131 }
132
133 int secd_80_views_basic(int argc, char *const *argv)
134 {
135 plan_tests(kTestTestCount);
136
137 secd_test_setup_temp_keychain(__FUNCTION__, NULL);
138
139 tests();
140
141 return 0;
142 }