OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2011 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 |
| 5 import dbus |
| 6 import gobject |
| 7 import logging |
| 8 import sys |
| 9 import os |
| 10 import tempfile |
| 11 |
| 12 from autotest_lib.client.bin import test, utils |
| 13 from autotest_lib.client.common_lib import autotemp, error |
| 14 from autotest_lib.client.cros import constants, cros_ui, cryptohome, login |
| 15 from autotest_lib.client.cros import cros_ui_test, ownership |
| 16 |
| 17 from dbus.mainloop.glib import DBusGMainLoop |
| 18 |
| 19 |
| 20 class login_OwnershipRetaken(cros_ui_test.UITest): |
| 21 version = 1 |
| 22 |
| 23 _got_new_key = False |
| 24 _got_new_policy = False |
| 25 |
| 26 def setup(self): |
| 27 os.chdir(self.srcdir) |
| 28 utils.make('OUT_DIR=.') |
| 29 |
| 30 |
| 31 def __handle_new_key(self, success): |
| 32 self._got_new_key = (success == 'success') |
| 33 |
| 34 |
| 35 def __handle_new_policy(self, success): |
| 36 self._got_new_policy = (success == 'success') |
| 37 |
| 38 |
| 39 def __received_signals(self): |
| 40 """Process dbus events""" |
| 41 context = gobject.MainLoop().get_context() |
| 42 while context.iteration(False): |
| 43 pass |
| 44 return self._got_new_key and self._got_new_policy |
| 45 |
| 46 |
| 47 def initialize(self, creds='$mockowner'): |
| 48 assert creds == '$mockowner', "Must use mockowner creds for this test." |
| 49 super(login_OwnershipRetaken, self).initialize(creds) |
| 50 ownership.listen_to_session_manager_signal(self.__handle_new_key, |
| 51 'SetOwnerKeyComplete') |
| 52 ownership.listen_to_session_manager_signal(self.__handle_new_policy, |
| 53 'PropertyChangeComplete') |
| 54 |
| 55 |
| 56 def run_once(self): |
| 57 # wait for new-owner-key signal, property-changed signal. |
| 58 utils.poll_for_condition( |
| 59 condition=lambda: self.__received_signals(), |
| 60 desc='Retaking of ownership complete.', |
| 61 timeout=constants.DEFAULT_OWNERSHIP_TIMEOUT) |
| 62 |
| 63 # grab key, ensure that it's different than known key |
| 64 if (utils.read_file(constants.OWNER_KEY_FILE) == |
| 65 ownership.known_pubkey()): |
| 66 raise error.TestFail('Owner key should have changed!') |
| 67 |
| 68 # RetrievePolicy, check sig against new key, check properties |
| 69 sm = ownership.connect_to_session_manager() |
| 70 retrieved_policy = sm.RetrievePolicy(byte_arrays=True) |
| 71 if retrieved_policy is None: |
| 72 raise error.TestFail('Policy not found') |
| 73 self.validate_basic_policy(retrieved_policy) |
OLD | NEW |