]> git.saurik.com Git - apple/security.git/blob - OSX/sec/securityd/Regressions/secd-82-secproperties-basic.c
Security-57740.60.18.tar.gz
[apple/security.git] / OSX / sec / securityd / Regressions / secd-82-secproperties-basic.c
1 //
2 // secd-82-secproperties-basic.c
3 // sec
4 //
5 // Created by Richard Murphy on 4/16/15.
6 //
7 //
8
9 #include <stdio.h>
10 //
11 // secd-80-views-basic.c
12 // sec
13 //
14 // Created by Richard Murphy on 1/26/15.
15 //
16 //
17
18 #include <stdio.h>
19 /*
20 * Copyright (c) 2012-2014 Apple Inc. All Rights Reserved.
21 *
22 * @APPLE_LICENSE_HEADER_START@
23 *
24 * This file contains Original Code and/or Modifications of Original Code
25 * as defined in and that are subject to the Apple Public Source License
26 * Version 2.0 (the 'License'). You may not use this file except in
27 * compliance with the License. Please obtain a copy of the License at
28 * http://www.opensource.apple.com/apsl/ and read it before using this
29 * file.
30 *
31 * The Original Code and all software distributed under the License are
32 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
33 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
34 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
35 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
36 * Please see the License for the specific language governing rights and
37 * limitations under the License.
38 *
39 * @APPLE_LICENSE_HEADER_END@
40 */
41
42
43
44 #include <Security/SecBase.h>
45 #include <Security/SecItem.h>
46
47 #include <Security/SecureObjectSync/SOSAccount.h>
48 #include <Security/SecureObjectSync/SOSCloudCircle.h>
49 #include <Security/SecureObjectSync/SOSInternal.h>
50 #include <Security/SecureObjectSync/SOSFullPeerInfo.h>
51 #include <Security/SecureObjectSync/SOSUserKeygen.h>
52 #include <stdlib.h>
53 #include <unistd.h>
54
55 #include "secd_regressions.h"
56 #include "SOSTestDataSource.h"
57
58 #include "SOSRegressionUtilities.h"
59 #include <utilities/SecCFWrappers.h>
60
61 #include <securityd/SOSCloudCircleServer.h>
62 #include "SecdTestKeychainUtilities.h"
63 #include "SOSAccountTesting.h"
64
65
66 static void testSecurityProperties(SOSAccountRef account, SOSSecurityPropertyResultCode expected, CFStringRef property, SOSSecurityPropertyActionCode action, char *label) {
67 CFErrorRef error = NULL;
68 SOSSecurityPropertyResultCode pcode = 9999;
69 switch(action) {
70 case kSOSCCSecurityPropertyQuery:
71 pcode = SOSAccountSecurityPropertyStatus(account, property, &error);
72 break;
73 case kSOSCCSecurityPropertyEnable:
74 case kSOSCCSecurityPropertyDisable: // fallthrough
75 pcode = SOSAccountUpdateSecurityProperty(account, property, action, &error);
76 break;
77 default:
78 break;
79 }
80 ok((pcode == expected), "%s (%@)", label, error);
81 CFReleaseNull(error);
82 }
83
84 static int kTestTestCount = 13;
85 static void tests(void)
86 {
87 CFErrorRef error = NULL;
88 CFDataRef cfpassword = CFDataCreate(NULL, (uint8_t *) "FooFooFoo", 10);
89 CFStringRef cfaccount = CFSTR("test@test.org");
90
91 SOSDataSourceFactoryRef test_factory = SOSTestDataSourceFactoryCreate();
92 SOSDataSourceRef test_source = SOSTestDataSourceCreate();
93 SOSTestDataSourceFactorySetDataSource(test_factory, CFSTR("TestType"), test_source);
94
95 SOSAccountRef account = CreateAccountForLocalChanges(CFSTR("Test Device"),CFSTR("TestType") );
96
97 ok(SOSAccountAssertUserCredentialsAndUpdate(account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
98 CFReleaseNull(error);
99 CFReleaseNull(cfpassword);
100
101 ok(SOSAccountJoinCircles_wTxn(account, &error), "Join Cirlce");
102
103 ok(NULL != account, "Created");
104
105 testSecurityProperties(account, kSOSCCSecurityPropertyNotValid, kSOSSecPropertyHasEntropy, kSOSCCSecurityPropertyQuery, "Expected no property: kSOSSecPropertyHasEntropy");
106 testSecurityProperties(account, kSOSCCSecurityPropertyNotValid, kSOSSecPropertyScreenLock, kSOSCCSecurityPropertyQuery, "Expected no property: kSOSSecPropertyScreenLock");
107 testSecurityProperties(account, kSOSCCSecurityPropertyNotValid, kSOSSecPropertySEP, kSOSCCSecurityPropertyQuery, "Expected no property: kSOSSecPropertySEP");
108 testSecurityProperties(account, kSOSCCSecurityPropertyNotValid, kSOSSecPropertyIOS, kSOSCCSecurityPropertyQuery, "Expected no property: kSOSSecPropertyIOS");
109 testSecurityProperties(account, kSOSCCSecurityPropertyValid, kSOSSecPropertyIOS, kSOSCCSecurityPropertyEnable, "Expected to add property: kSOSSecPropertyIOS");
110 testSecurityProperties(account, kSOSCCSecurityPropertyValid, kSOSSecPropertyIOS, kSOSCCSecurityPropertyQuery, "Expected no property: kSOSSecPropertyIOS");
111 testSecurityProperties(account, kSOSCCSecurityPropertyNotValid, kSOSSecPropertyIOS, kSOSCCSecurityPropertyDisable, "Expected to disable property: kSOSSecPropertyIOS");
112 testSecurityProperties(account, kSOSCCSecurityPropertyNotValid, kSOSSecPropertyIOS, kSOSCCSecurityPropertyQuery, "Expected no property: kSOSSecPropertyIOS");
113 testSecurityProperties(account, kSOSCCNoSuchSecurityProperty, CFSTR("FOO"), kSOSCCSecurityPropertyQuery, "Expected no such property for FOO");
114
115 CFReleaseNull(account);
116
117 SOSDataSourceRelease(test_source, NULL);
118 SOSDataSourceFactoryRelease(test_factory);
119
120 SOSTestCleanup();
121 }
122
123 int secd_82_secproperties_basic(int argc, char *const *argv)
124 {
125 plan_tests(kTestTestCount);
126
127 secd_test_setup_temp_keychain(__FUNCTION__, NULL);
128
129 tests();
130
131 return 0;
132 }