2 // secd-82-secproperties-basic.c
5 // Created by Richard Murphy on 4/16/15.
11 // secd-80-views-basic.c
14 // Created by Richard Murphy on 1/26/15.
20 * Copyright (c) 2012-2014 Apple Inc. All Rights Reserved.
22 * @APPLE_LICENSE_HEADER_START@
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
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.
39 * @APPLE_LICENSE_HEADER_END@
44 #include <Security/SecBase.h>
45 #include <Security/SecItem.h>
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>
55 #include "secd_regressions.h"
56 #include "SOSTestDataSource.h"
58 #include "SOSRegressionUtilities.h"
59 #include <utilities/SecCFWrappers.h>
61 #include <securityd/SOSCloudCircleServer.h>
62 #include "SecdTestKeychainUtilities.h"
63 #include "SOSAccountTesting.h"
66 static void testSecurityProperties(SOSAccount* account, SOSSecurityPropertyResultCode expected, CFStringRef property, SOSSecurityPropertyActionCode action, char *label) {
67 CFErrorRef error = NULL;
68 SOSSecurityPropertyResultCode pcode = 9999;
70 case kSOSCCSecurityPropertyQuery:
71 pcode = [account.trust SecurityPropertyStatus:property err:&error];
73 case kSOSCCSecurityPropertyEnable:
74 case kSOSCCSecurityPropertyDisable: // fallthrough
75 pcode = [account.trust UpdateSecurityProperty:account property:property code:action err:&error];
80 ok((pcode == expected), "%s (%@)", label, error);
84 static int kTestTestCount = 13;
85 static void tests(void)
87 CFErrorRef error = NULL;
88 CFDataRef cfpassword = CFDataCreate(NULL, (uint8_t *) "FooFooFoo", 10);
89 CFStringRef cfaccount = CFSTR("test@test.org");
91 SOSDataSourceFactoryRef test_factory = SOSTestDataSourceFactoryCreate();
92 SOSDataSourceRef test_source = SOSTestDataSourceCreate();
93 SOSTestDataSourceFactorySetDataSource(test_factory, CFSTR("TestType"), test_source);
95 SOSAccount* account = CreateAccountForLocalChanges(CFSTR("Test Device"),CFSTR("TestType") );
97 ok(SOSAccountAssertUserCredentialsAndUpdate(account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
99 CFReleaseNull(cfpassword);
101 ok(SOSAccountJoinCircles_wTxn(account, &error), "Join Cirlce");
103 ok(NULL != account, "Created");
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 SOSDataSourceRelease(test_source, NULL);
115 SOSDataSourceFactoryRelease(test_factory);
120 int secd_82_secproperties_basic(int argc, char *const *argv)
122 plan_tests(kTestTestCount);
124 secd_test_setup_temp_keychain(__FUNCTION__, NULL);