2 * Copyright (c) 2012-2016 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
25 // secd-80-views-alwayson.c
32 #include <CoreFoundation/CFDictionary.h>
33 #include <utilities/SecCFWrappers.h>
35 #include "keychain/SecureObjectSync/SOSAccount.h"
37 #include "secd_regressions.h"
38 #include "SOSAccountTesting.h"
39 #include "SecdTestKeychainUtilities.h"
41 static void testView(SOSAccount* account, SOSViewResultCode expected, CFStringRef view, SOSViewActionCode action, char *label) {
42 CFErrorRef error = NULL;
43 SOSViewResultCode vcode = 9999;
46 vcode = [account.trust viewStatus:account name:view err:&error];
48 case kSOSCCViewEnable:
49 case kSOSCCViewDisable: // fallthrough
50 vcode = [account.trust updateView:account name:view code:action err:&error];
55 is(vcode, expected, "%s (%@)", label, error);
60 Make a circle with two peers - alice and bob
61 Check for ContinuityUnlock View on Alice - it should be there
62 turn off ContinuityUnlock on Alice
63 Change the password with Bob - makeing Alice invalid
64 Update Alice with the new password
65 see that ContinuityUnlock is automatically back on because it's "always on"
68 static void alwaysOnTest()
70 CFDataRef cfpassword = CFDataCreate(NULL, (uint8_t *) "FooFooFoo", 10);
71 CFDataRef cfpasswordNew = CFDataCreate(NULL, (uint8_t *) "FooFooFo2", 10);
72 CFStringRef cfaccount = CFSTR("test@test.org");
74 CFMutableDictionaryRef changes = CFDictionaryCreateMutableForCFTypes(kCFAllocatorDefault);
75 SOSAccount* alice_account = CreateAccountForLocalChanges(CFSTR("Alice"), CFSTR("TestSource"));
76 SOSAccount* bob_account = CreateAccountForLocalChanges(CFSTR("Bob"), CFSTR("TestSource"));
79 ok(SOSTestStartCircleWithAccount(alice_account, changes, cfaccount, cfpassword), "Have Alice start a circle");
80 is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, NULL), 1, "updates");
81 ok(SOSTestJoinWithApproval(cfpassword, cfaccount, changes, alice_account, bob_account, KEEP_USERKEY, 2, false), "Bob Joins");
82 CFReleaseNull(cfpassword);
84 testView(alice_account, kSOSCCViewMember, kSOSViewContinuityUnlock, kSOSCCViewQuery, "Expected view capability for kSOSViewContinuityUnlock");
85 testView(alice_account, kSOSCCViewMember, kSOSViewContinuityUnlock, kSOSCCViewDisable, "Not expected to disable kSOSViewContinuityUnlock - it's always-on");
87 ok(SOSAccountAssertUserCredentialsAndUpdate(bob_account, cfaccount, cfpasswordNew, NULL), "Bob changes the password");
88 testView(alice_account, kSOSCCViewMember, kSOSViewContinuityUnlock, kSOSCCViewQuery, "Expected kSOSViewContinuityUnlock is on for alice still");
89 ok(SOSAccountAssertUserCredentialsAndUpdate(alice_account, cfaccount, cfpasswordNew, NULL), "Alice sets the new password");
90 CFReleaseNull(cfpasswordNew);
91 testView(alice_account, kSOSCCViewMember, kSOSViewContinuityUnlock, kSOSCCViewQuery, "Expected view capability for kSOSViewContinuityUnlock");
93 CFReleaseNull(changes);
98 int secd_80_views_alwayson(int argc, char *const *argv)
101 secd_test_clear_testviews();
102 secd_test_setup_temp_keychain(__FUNCTION__, NULL);