]> git.saurik.com Git - apple/security.git/blob - OSX/sec/securityd/Regressions/secd-80-views-alwayson.c
Security-57740.60.18.tar.gz
[apple/security.git] / OSX / sec / securityd / Regressions / secd-80-views-alwayson.c
1 /*
2 * Copyright (c) 2012-2016 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 //
25 // secd-80-views-alwayson.c
26 // Security
27 //
28 //
29 //
30
31
32 #include <CoreFoundation/CFDictionary.h>
33 #include <utilities/SecCFWrappers.h>
34
35 #include <Security/SecureObjectSync/SOSAccount.h>
36
37 #include "secd_regressions.h"
38 #include "SOSAccountTesting.h"
39 #include "SecdTestKeychainUtilities.h"
40
41 static int kTestTestCount = 46;
42
43
44 static void testView(SOSAccountRef account, SOSViewResultCode expected, CFStringRef view, SOSViewActionCode action, char *label) {
45 CFErrorRef error = NULL;
46 SOSViewResultCode vcode = 9999;
47 switch(action) {
48 case kSOSCCViewQuery:
49 vcode = SOSAccountViewStatus(account, view, &error);
50 break;
51 case kSOSCCViewEnable:
52 case kSOSCCViewDisable: // fallthrough
53 vcode = SOSAccountUpdateView(account, view, action, &error);
54 break;
55 default:
56 break;
57 }
58 is(vcode, expected, "%s (%@)", label, error);
59 CFReleaseNull(error);
60 }
61
62 /*
63 Make a circle with two peers - alice and bob
64 Check for ContinuityUnlock View on Alice - it should be there
65 turn off ContinuityUnlock on Alice
66 Change the password with Bob - makeing Alice invalid
67 Update Alice with the new password
68 see that ContinuityUnlock is automatically back on because it's "always on"
69 */
70
71 static void alwaysOnTest()
72 {
73 CFDataRef cfpassword = CFDataCreate(NULL, (uint8_t *) "FooFooFoo", 10);
74 CFDataRef cfpasswordNew = CFDataCreate(NULL, (uint8_t *) "FooFooFo2", 10);
75 CFStringRef cfaccount = CFSTR("test@test.org");
76
77 CFMutableDictionaryRef changes = CFDictionaryCreateMutableForCFTypes(kCFAllocatorDefault);
78 SOSAccountRef alice_account = CreateAccountForLocalChanges(CFSTR("Alice"), CFSTR("TestSource"));
79 SOSAccountRef bob_account = CreateAccountForLocalChanges(CFSTR("Bob"), CFSTR("TestSource"));
80
81 // Start Circle
82 ok(SOSTestStartCircleWithAccount(alice_account, changes, cfaccount, cfpassword), "Have Alice start a circle");
83 is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, NULL), 1, "updates");
84 ok(SOSTestJoinWithApproval(cfpassword, cfaccount, changes, alice_account, bob_account, KEEP_USERKEY, 2, false), "Bob Joins");
85
86 testView(alice_account, kSOSCCViewMember, kSOSViewContinuityUnlock, kSOSCCViewQuery, "Expected view capability for kSOSViewContinuityUnlock");
87 testView(alice_account, kSOSCCViewNotMember, kSOSViewContinuityUnlock, kSOSCCViewDisable, "Expected to disable kSOSViewContinuityUnlock");
88
89 ok(SOSAccountAssertUserCredentialsAndUpdate(bob_account, cfaccount, cfpasswordNew, NULL), "Bob changes the password");
90 testView(alice_account, kSOSCCViewNotMember, kSOSViewContinuityUnlock, kSOSCCViewQuery, "Expected kSOSViewContinuityUnlock is off for alice still");
91 ok(SOSAccountAssertUserCredentialsAndUpdate(alice_account, cfaccount, cfpasswordNew, NULL), "Alice sets the new password");
92 testView(alice_account, kSOSCCViewMember, kSOSViewContinuityUnlock, kSOSCCViewQuery, "Expected view capability for kSOSViewContinuityUnlock");
93
94 CFReleaseNull(alice_account);
95 CFReleaseNull(bob_account);
96 CFReleaseNull(changes);
97
98 SOSTestCleanup();
99 }
100
101 int secd_80_views_alwayson(int argc, char *const *argv)
102 {
103 plan_tests(kTestTestCount);
104
105 secd_test_setup_temp_keychain(__FUNCTION__, NULL);
106 alwaysOnTest();
107 return 0;
108 }