1# Copyright (c) 2012 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
5from autotest_lib.client.bin import test
6from autotest_lib.client.common_lib import error
7from autotest_lib.client.cros import cryptohome
8
9class platform_CryptohomeMount(test.test):
10    """Validates basic cryptohome creation and mounting."""
11    version = 1
12
13
14    def run_once(self):
15        test_user = 'this_is_a_local_test_account@chromium.org';
16        test_password = 'this_is_a_test_password';
17
18        # Remove the test user account (if it exists), create it and
19        # mount it
20        cryptohome.ensure_clean_cryptohome_for(test_user, test_password)
21
22        # Unmount the vault and ensure it's not there
23        cryptohome.unmount_vault(test_user)
24
25        # Make sure that an incorrect password fails
26        incorrect_password = 'this_is_an_incorrect_password'
27        try:
28            cryptohome.mount_vault(test_user, incorrect_password)
29        except:
30            pass
31        else:
32            raise error.TestFail('Cryptohome mounted with a bad password')
33
34        # Ensure that the user directory is not mounted
35        if cryptohome.is_permanent_vault_mounted(test_user, allow_fail=True):
36            raise error.TestFail('Cryptohome mounted even though mount failed')
37
38        # Remove the test user account
39        cryptohome.remove_vault(test_user)
40