| Index: client/site_tests/platform_CryptohomeTestAuth/platform_CryptohomeTestAuth.py
|
| diff --git a/client/site_tests/platform_CryptohomeTestAuth/platform_CryptohomeTestAuth.py b/client/site_tests/platform_CryptohomeTestAuth/platform_CryptohomeTestAuth.py
|
| index 2c2f59a3d0b08d89ebe4acf265ee617ba8afc756..fdf3544b86cb2953dd1511f27996cfd0d7a12df8 100644
|
| --- a/client/site_tests/platform_CryptohomeTestAuth/platform_CryptohomeTestAuth.py
|
| +++ b/client/site_tests/platform_CryptohomeTestAuth/platform_CryptohomeTestAuth.py
|
| @@ -7,91 +7,65 @@ import os
|
| import re
|
| import shutil
|
|
|
| -from autotest_lib.client.bin import test
|
| +from autotest_lib.client.bin import site_cryptohome, test
|
| from autotest_lib.client.common_lib import error, utils
|
|
|
| class platform_CryptohomeTestAuth(test.test):
|
| version = 1
|
|
|
| - def __run_cmd(self, cmd):
|
| - result = utils.system_output(cmd + ' 2>&1', retain_output=True,
|
| - ignore_status=True)
|
| - return result
|
| -
|
|
|
| def run_once(self):
|
| - test_user = 'this_is_a_local_test_account@chromium.org';
|
| - test_password = 'this_is_a_test_password';
|
| - # Get the hash for the test user account
|
| - cmd = ('/usr/sbin/cryptohome --action=obfuscate_user --user='
|
| - + test_user)
|
| - user_hash = self.__run_cmd(cmd).strip()
|
| -
|
| - # Remove the test user account
|
| - cmd = ('/usr/sbin/cryptohome --action=remove --force --user='
|
| - + test_user)
|
| - self.__run_cmd(cmd)
|
| - # Ensure that the user directory does not exist
|
| - if os.path.exists('/home/.shadow/' + user_hash):
|
| - raise error.TestFail('Cryptohome could not remove the test user.')
|
| -
|
| - # Mount the test user account
|
| - cmd = ('/usr/sbin/cryptohome --action=mount --user=' + test_user
|
| - + ' --password=' + test_password)
|
| - self.__run_cmd(cmd)
|
| - # Ensure that the user directory exists
|
| - if not os.path.exists('/home/.shadow/' + user_hash):
|
| - raise error.TestFail('Cryptohome could not create the test user.')
|
| - # Ensure that the user directory is mounted
|
| - cmd = ('/usr/sbin/cryptohome --action=is_mounted')
|
| - if (self.__run_cmd(cmd).strip() == 'false'):
|
| - raise error.TestFail('Cryptohome created the user but did not mount.')
|
| + test_user = 'this_is_a_local_test_account@chromium.org'
|
| + test_password = 'this_is_a_test_password'
|
| +
|
| + user_hash = site_cryptohome.get_user_hash(test_user)
|
| +
|
| +
|
| + # Ensure that the user directory is unmounted and does not exist.
|
| + site_cryptohome.unmount_vault()
|
| + site_cryptohome.remove_vault(test_user)
|
| + if os.path.exists(os.path.join('/home/.shadow', user_hash)):
|
| + raise error.TestFail('Could not remove the test user.')
|
| +
|
| + # Mount the test user account, which ensures that the vault is
|
| + # created, and that the mount succeeds.
|
| + site_cryptohome.mount_vault(test_user, test_password, create=True)
|
|
|
| # Test credentials when the user's directory is mounted
|
| - cmd = ('/usr/sbin/cryptohome --action=test_auth --user=' + test_user
|
| - + ' --password=' + test_password)
|
| - result = self.__run_cmd(cmd)
|
| - if (result.find("Authentication succeeded") < 0):
|
| - self.__run_cmd('/usr/sbin/cryptohome --action=unmount')
|
| - raise error.TestFail('Test authentication of valid credentials for'
|
| - + ' the logged in user failed.')
|
| + if not site_cryptohome.test_auth(test_user, test_password):
|
| + raise error.TestFail('Valid credentials should authenticate '
|
| + 'while mounted.')
|
|
|
| # Make sure that an incorrect password fails
|
| - incorrect_password = 'this_is_an_incorrect_password'
|
| - cmd = ('/usr/sbin/cryptohome --action=test_auth --user=' + test_user
|
| - + ' --password=' + incorrect_password)
|
| - result = self.__run_cmd(cmd)
|
| - if (result.find("Authentication succeeded") >= 0):
|
| - self.__run_cmd('/usr/sbin/cryptohome --action=unmount')
|
| - raise error.TestFail('Test authentication of invalid credentials for'
|
| - + ' the logged in user failed.')
|
| + if site_cryptohome.test_auth(test_user, 'badpass'):
|
| + raise error.TestFail('Invalid credentials should not authenticate '
|
| + 'while mounted.')
|
|
|
| # Unmount the directory
|
| - cmd = ('/usr/sbin/cryptohome --action=unmount')
|
| - self.__run_cmd(cmd)
|
| + site_cryptohome.unmount_vault()
|
| # Ensure that the user directory is not mounted
|
| - cmd = ('/usr/sbin/cryptohome --action=is_mounted')
|
| - if (self.__run_cmd(cmd).strip() != 'false'):
|
| - raise error.TestFail('Cryptohome did not unmount the user.')
|
| -
|
| - # Test credentials when the user's directory is not mounted
|
| - cmd = ('/usr/sbin/cryptohome --action=test_auth --user=' + test_user
|
| - + ' --password=' + test_password)
|
| - result = self.__run_cmd(cmd)
|
| - if (result.find("Authentication succeeded") < 0):
|
| - raise error.TestFail('Test authentication of valid credentials for'
|
| - + ' an offline user failed.')
|
| + if site_cryptohome.is_mounted(allow_fail=True):
|
| + raise error.TestFail('Cryptohome did not unmount the user.')
|
|
|
| - # Make sure that an incorrect password fails
|
| - incorrect_password = 'this_is_an_incorrect_password'
|
| - cmd = ('/usr/sbin/cryptohome --action=test_auth --user=' + test_user
|
| - + ' --password=' + incorrect_password)
|
| - result = self.__run_cmd(cmd)
|
| - if (result.find("Authentication succeeded") >= 0):
|
| - raise error.TestFail('Test authentication of invalid credentials for'
|
| - + ' an offline user failed.')
|
| -
|
| - # Remove the test user account
|
| - cmd = ('/usr/sbin/cryptohome --action=remove --force --user='
|
| - + test_user)
|
| - self.__run_cmd(cmd)
|
| + # Test valid credentials when the user's directory is not mounted
|
| + if not site_cryptohome.test_auth(test_user, test_password):
|
| + raise error.TestFail('Valid credentials should authenticate '
|
| + ' while mounted.')
|
| +
|
| + # Test invalid credentials fails while not mounted.
|
| + if site_cryptohome.test_auth(test_user, 'badpass'):
|
| + raise error.TestFail('Invalid credentials should not authenticate '
|
| + 'when unmounted.')
|
| +
|
| +
|
| + # Re-mount existing test user vault, verifying that the mount succeeds.
|
| + site_cryptohome.mount_vault(test_user, test_password)
|
| +
|
| + # Remove the test user account.
|
| + site_cryptohome.remove_vault(test_user)
|
| +
|
| + # Finally, unmount and destroy the vault again.
|
| + site_cryptohome.unmount_vault()
|
| + site_cryptohome.remove_vault(test_user)
|
| + if os.path.exists(os.path.join('/home/.shadow', user_hash)):
|
| + raise error.TestFail('Could not destroy the vault.')
|
|
|