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, utils 6from autotest_lib.client.common_lib import error 7from autotest_lib.client.cros import cryptohome 8 9class platform_CryptohomeMigrateKey(test.test): 10 version = 1 11 12 def good(self): 13 user = utils.random_username() 14 old_pass = 'old' 15 new_pass = 'new' 16 17 cryptohome.mount_vault(user, old_pass, create=True) 18 cryptohome.unmount_vault(user) 19 cryptohome.change_password(user, old_pass, new_pass) 20 try: 21 cryptohome.mount_vault(user, old_pass) 22 except: 23 pass 24 else: 25 raise error.TestFail('Old password still works.') 26 cryptohome.mount_vault(user, new_pass) 27 cryptohome.unmount_vault(user) 28 cryptohome.remove_vault(user) 29 30 31 def bad_password(self): 32 user = utils.random_username() 33 old_pass = 'old' 34 new_pass = 'new' 35 cryptohome.mount_vault(user, old_pass, create=True) 36 cryptohome.unmount_vault(user) 37 try: 38 cryptohome.change_password(user, 'bad', new_pass) 39 except: 40 pass 41 else: 42 raise error.TestFail('Migrated with bad password.') 43 cryptohome.remove_vault(user) 44 45 46 def nonexistent_user(self): 47 user = utils.random_username() 48 old_pass = 'old' 49 new_pass = 'new' 50 try: 51 cryptohome.change_password(user, old_pass, new_pass) 52 except: 53 pass 54 else: 55 raise error.TestFail('Migrated a nonexistent user.') 56 57 def run_once(self): 58 self.good() 59 self.bad_password() 60 self.nonexistent_user() 61