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        if not self.proxy.mount(user, old_pass, create=True):
18            raise error.TestFail('Could not create good user.')
19        if not self.proxy.unmount(user):
20            raise error.TestFail('Could not unmount good user.')
21        if not self.proxy.migrate(user, old_pass, new_pass):
22            raise error.TestFail('Could not migrate good user.')
23        if self.proxy.mount(user, old_pass):
24            raise error.TestFail('Old password still works.')
25        if not self.proxy.mount(user, new_pass):
26            raise error.TestFail('Could not mount good user.')
27        if not self.proxy.unmount(user):
28            raise error.TestFail('Could not unmount good user.')
29        self.proxy.remove(user)
30
31    def bad_password(self):
32        user = utils.random_username()
33        old_pass = 'old'
34        new_pass = 'new'
35        if not self.proxy.mount(user, old_pass, create=True):
36            raise error.TestFail('Could not create bad user.')
37        if not self.proxy.unmount(user):
38            raise error.TestFail('Could not unmount bad user.')
39        if self.proxy.migrate(user, 'bad', new_pass):
40            raise error.TestFail('Migrated with bad password.')
41        self.proxy.remove(user)
42
43    def nonexistent_user(self):
44        user = utils.random_username()
45        old_pass = 'old'
46        new_pass = 'new'
47        if self.proxy.migrate(user, old_pass, new_pass):
48            raise error.TestFail('Migration nonexistent user.')
49
50    def run_once(self):
51        self.proxy = cryptohome.CryptohomeProxy()
52        self.good()
53        self.bad_password()
54        self.nonexistent_user()
55