1# Copyright 2014 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# Most of this code is based on login_GuestAndActualSession, which performs 6# similar ownership clearing/checking tasks. 7 8import gobject 9from dbus.mainloop.glib import DBusGMainLoop 10 11from autotest_lib.client.bin import test 12from autotest_lib.client.common_lib import error 13from autotest_lib.client.common_lib.cros import session_manager 14from autotest_lib.client.cros import cros_ui, cryptohome, ownership 15 16class login_CryptohomeOwnerQuery(test.test): 17 """Verify that the cryptohome owner user query works properly.""" 18 version = 1 19 20 21 def initialize(self): 22 super(login_CryptohomeOwnerQuery, self).initialize() 23 # Ensure a clean beginning. 24 ownership.restart_ui_to_clear_ownership_files() 25 26 bus_loop = DBusGMainLoop(set_as_default=True) 27 self._session_manager = session_manager.connect(bus_loop) 28 self._listener = session_manager.OwnershipSignalListener( 29 gobject.MainLoop()) 30 self._listener.listen_for_new_key_and_policy() 31 32 33 def run_once(self): 34 owner = 'first_user@nowhere.com' 35 36 if cryptohome.get_login_status()['owner_user_exists']: 37 raise error.TestFail('Owner existed before login') 38 39 cryptohome.ensure_clean_cryptohome_for(owner) 40 self._session_manager.StartSession(owner, '') 41 42 self._listener.wait_for_signals(desc='Device ownership complete.') 43 44 if not cryptohome.get_login_status()['owner_user_exists']: 45 raise error.TestFail('Owner does not exist after login') 46 47 48 def cleanup(self): 49 self._session_manager.StopSession('') 50 cros_ui.start(allow_fail=True, wait_for_login_prompt=False) 51