1# Copyright (c) 2013 The Chromium OS Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import os 6 7from autotest_lib.client.bin import test 8from autotest_lib.client.common_lib import error 9from autotest_lib.client.common_lib.cros import chrome 10from autotest_lib.client.cros import cryptohome 11 12TEST_USER = 'cryptohome_test@chromium.org' 13TEST_PASS = 'testme' 14 15class login_Cryptohome(test.test): 16 """Verify the cryptohome is mounted only after login.""" 17 version = 1 18 19 20 def run_once(self): 21 username = '' 22 with chrome.Chrome() as cr: 23 username = cr.username 24 if not cryptohome.is_vault_mounted(user=username, 25 allow_fail=False): 26 raise error.TestFail('Expected to find a mounted vault.') 27 28 if cryptohome.is_vault_mounted(user=username, 29 allow_fail=True): 30 raise error.TestFail('Expected to not find a mounted vault.') 31 32 # Remove our vault, mount another vault, create a test file 33 # in the other vault, and ensure that the file no longer exists 34 # after we log back in. 35 cryptohome.remove_vault(username) 36 37 cryptohome.mount_vault(TEST_USER, TEST_PASS, create=True) 38 test_file = os.path.join(cryptohome.user_path(TEST_USER), 'hello') 39 open(test_file, 'w').close() 40 cryptohome.unmount_vault(TEST_USER) 41 42 with chrome.Chrome(): 43 if not cryptohome.is_vault_mounted(user=username, 44 allow_fail=False): 45 raise error.TestFail('Expected to find user\'s mounted vault.') 46 if os.path.exists(test_file): 47 raise error.TestFail('Expected to not find the test file.') 48