• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_permanent_vault_mounted(username):
25                raise error.TestFail('Expected to find a mounted vault.')
26
27        if cryptohome.is_vault_mounted(user=username,
28                                       allow_fail=True):
29            raise error.TestFail('Expected to not find a mounted vault.')
30
31        # Remove our vault, mount another vault, create a test file
32        # in the other vault, and ensure that the file no longer exists
33        # after we log back in.
34        cryptohome.remove_vault(username)
35
36        cryptohome.mount_vault(TEST_USER, TEST_PASS, create=True)
37        test_file = os.path.join(cryptohome.user_path(TEST_USER), 'hello')
38        open(test_file, 'w').close()
39        cryptohome.unmount_vault(TEST_USER)
40
41        with chrome.Chrome():
42            if not cryptohome.is_permanent_vault_mounted(username):
43                raise error.TestFail('Expected to find user\'s mounted vault.')
44            if os.path.exists(test_file):
45                raise error.TestFail('Expected to not find the test file.')
46
47        cryptohome.remove_vault(TEST_USER)
48