| OLD | NEW |
| 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import logging | 5 import logging |
| 6 import os | 6 import os |
| 7 import re | 7 import re |
| 8 import shutil | 8 import shutil |
| 9 | 9 |
| 10 from autotest_lib.client.bin import test | 10 from autotest_lib.client.bin import site_cryptohome, test |
| 11 from autotest_lib.client.common_lib import error, utils | 11 from autotest_lib.client.common_lib import error, utils |
| 12 | 12 |
| 13 class platform_CryptohomeTestAuth(test.test): | 13 class platform_CryptohomeTestAuth(test.test): |
| 14 version = 1 | 14 version = 1 |
| 15 | 15 |
| 16 def __run_cmd(self, cmd): | 16 |
| 17 result = utils.system_output(cmd + ' 2>&1', retain_output=True, | 17 def run_once(self): |
| 18 ignore_status=True) | 18 test_user = 'this_is_a_local_test_account@chromium.org' |
| 19 return result | 19 test_password = 'this_is_a_test_password' |
| 20 |
| 21 user_hash = site_cryptohome.get_user_hash(test_user) |
| 20 | 22 |
| 21 | 23 |
| 22 def run_once(self): | 24 # Ensure that the user directory is unmounted and does not exist. |
| 23 test_user = 'this_is_a_local_test_account@chromium.org'; | 25 site_cryptohome.unmount_vault() |
| 24 test_password = 'this_is_a_test_password'; | 26 site_cryptohome.remove_vault(test_user) |
| 25 # Get the hash for the test user account | 27 if os.path.exists(os.path.join('/home/.shadow', user_hash)): |
| 26 cmd = ('/usr/sbin/cryptohome --action=obfuscate_user --user=' | 28 raise error.TestFail('Could not remove the test user.') |
| 27 + test_user) | |
| 28 user_hash = self.__run_cmd(cmd).strip() | |
| 29 | 29 |
| 30 # Remove the test user account | 30 # Mount the test user account, which ensures that the vault is |
| 31 cmd = ('/usr/sbin/cryptohome --action=remove --force --user=' | 31 # created, and that the mount succeeds. |
| 32 + test_user) | 32 site_cryptohome.mount_vault(test_user, test_password, create=True) |
| 33 self.__run_cmd(cmd) | |
| 34 # Ensure that the user directory does not exist | |
| 35 if os.path.exists('/home/.shadow/' + user_hash): | |
| 36 raise error.TestFail('Cryptohome could not remove the test user.') | |
| 37 | |
| 38 # Mount the test user account | |
| 39 cmd = ('/usr/sbin/cryptohome --action=mount --user=' + test_user | |
| 40 + ' --password=' + test_password) | |
| 41 self.__run_cmd(cmd) | |
| 42 # Ensure that the user directory exists | |
| 43 if not os.path.exists('/home/.shadow/' + user_hash): | |
| 44 raise error.TestFail('Cryptohome could not create the test user.') | |
| 45 # Ensure that the user directory is mounted | |
| 46 cmd = ('/usr/sbin/cryptohome --action=is_mounted') | |
| 47 if (self.__run_cmd(cmd).strip() == 'false'): | |
| 48 raise error.TestFail('Cryptohome created the user but did not mount.') | |
| 49 | 33 |
| 50 # Test credentials when the user's directory is mounted | 34 # Test credentials when the user's directory is mounted |
| 51 cmd = ('/usr/sbin/cryptohome --action=test_auth --user=' + test_user | 35 if not site_cryptohome.test_auth(test_user, test_password): |
| 52 + ' --password=' + test_password) | 36 raise error.TestFail('Valid credentials should authenticate ' |
| 53 result = self.__run_cmd(cmd) | 37 'while mounted.') |
| 54 if (result.find("Authentication succeeded") < 0): | |
| 55 self.__run_cmd('/usr/sbin/cryptohome --action=unmount') | |
| 56 raise error.TestFail('Test authentication of valid credentials for' | |
| 57 + ' the logged in user failed.') | |
| 58 | 38 |
| 59 # Make sure that an incorrect password fails | 39 # Make sure that an incorrect password fails |
| 60 incorrect_password = 'this_is_an_incorrect_password' | 40 if site_cryptohome.test_auth(test_user, 'badpass'): |
| 61 cmd = ('/usr/sbin/cryptohome --action=test_auth --user=' + test_user | 41 raise error.TestFail('Invalid credentials should not authenticate ' |
| 62 + ' --password=' + incorrect_password) | 42 'while mounted.') |
| 63 result = self.__run_cmd(cmd) | |
| 64 if (result.find("Authentication succeeded") >= 0): | |
| 65 self.__run_cmd('/usr/sbin/cryptohome --action=unmount') | |
| 66 raise error.TestFail('Test authentication of invalid credentials for' | |
| 67 + ' the logged in user failed.') | |
| 68 | 43 |
| 69 # Unmount the directory | 44 # Unmount the directory |
| 70 cmd = ('/usr/sbin/cryptohome --action=unmount') | 45 site_cryptohome.unmount_vault() |
| 71 self.__run_cmd(cmd) | |
| 72 # Ensure that the user directory is not mounted | 46 # Ensure that the user directory is not mounted |
| 73 cmd = ('/usr/sbin/cryptohome --action=is_mounted') | 47 if site_cryptohome.is_mounted(allow_fail=True): |
| 74 if (self.__run_cmd(cmd).strip() != 'false'): | 48 raise error.TestFail('Cryptohome did not unmount the user.') |
| 75 raise error.TestFail('Cryptohome did not unmount the user.') | |
| 76 | 49 |
| 77 # Test credentials when the user's directory is not mounted | 50 # Test valid credentials when the user's directory is not mounted |
| 78 cmd = ('/usr/sbin/cryptohome --action=test_auth --user=' + test_user | 51 if not site_cryptohome.test_auth(test_user, test_password): |
| 79 + ' --password=' + test_password) | 52 raise error.TestFail('Valid credentials should authenticate ' |
| 80 result = self.__run_cmd(cmd) | 53 ' while mounted.') |
| 81 if (result.find("Authentication succeeded") < 0): | |
| 82 raise error.TestFail('Test authentication of valid credentials for' | |
| 83 + ' an offline user failed.') | |
| 84 | 54 |
| 85 # Make sure that an incorrect password fails | 55 # Test invalid credentials fails while not mounted. |
| 86 incorrect_password = 'this_is_an_incorrect_password' | 56 if site_cryptohome.test_auth(test_user, 'badpass'): |
| 87 cmd = ('/usr/sbin/cryptohome --action=test_auth --user=' + test_user | 57 raise error.TestFail('Invalid credentials should not authenticate ' |
| 88 + ' --password=' + incorrect_password) | 58 'when unmounted.') |
| 89 result = self.__run_cmd(cmd) | |
| 90 if (result.find("Authentication succeeded") >= 0): | |
| 91 raise error.TestFail('Test authentication of invalid credentials for' | |
| 92 + ' an offline user failed.') | |
| 93 | 59 |
| 94 # Remove the test user account | 60 |
| 95 cmd = ('/usr/sbin/cryptohome --action=remove --force --user=' | 61 # Re-mount existing test user vault, verifying that the mount succeeds. |
| 96 + test_user) | 62 site_cryptohome.mount_vault(test_user, test_password) |
| 97 self.__run_cmd(cmd) | 63 |
| 64 # Remove the test user account. |
| 65 site_cryptohome.remove_vault(test_user) |
| 66 |
| 67 # Finally, unmount and destroy the vault again. |
| 68 site_cryptohome.unmount_vault() |
| 69 site_cryptohome.remove_vault(test_user) |
| 70 if os.path.exists(os.path.join('/home/.shadow', user_hash)): |
| 71 raise error.TestFail('Could not destroy the vault.') |
| OLD | NEW |