1# Copyright (c) 2013 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 5import gobject 6from dbus.mainloop.glib import DBusGMainLoop 7 8 9from autotest_lib.client.bin import test 10from autotest_lib.client.common_lib import error 11from autotest_lib.client.common_lib.cros import policy, session_manager 12from autotest_lib.client.cros import constants, cros_ui, cryptohome, ownership 13 14 15class login_GuestAndActualSession(test.test): 16 """Ensure that the session_manager correctly handles ownership when a guest 17 signs in before a real user. 18 """ 19 version = 1 20 21 22 def initialize(self): 23 super(login_GuestAndActualSession, self).initialize() 24 policy.install_protobufs(self.autodir, self.job) 25 # Ensure a clean beginning. 26 ownership.restart_ui_to_clear_ownership_files() 27 28 bus_loop = DBusGMainLoop(set_as_default=True) 29 self._session_manager = session_manager.connect(bus_loop) 30 self._listener = session_manager.OwnershipSignalListener( 31 gobject.MainLoop()) 32 self._listener.listen_for_new_key_and_policy() 33 34 35 def run_once(self): 36 owner = 'first_user@nowhere.com' 37 38 cryptohome.mount_guest() 39 self._session_manager.StartSession(constants.GUEST_USER, '') 40 cryptohome.ensure_clean_cryptohome_for(owner) 41 self._session_manager.StartSession(owner, '') 42 self._listener.wait_for_signals(desc='Device ownership complete.') 43 44 # Ensure that the first real user got to be the owner. 45 retrieved_policy = policy.get_policy(self._session_manager) 46 if retrieved_policy is None: raise error.TestFail('Policy not found') 47 policy.compare_policy_response(retrieved_policy, owner=owner) 48 49 50 def cleanup(self): 51 # Testing is done, so just stop the UI instead of calling StopSession. 52 # The latter can fail if Chrome is hanging: https://crbug.com/876197 53 cros_ui.stop(allow_fail=True) 54 cros_ui.start(allow_fail=True, wait_for_login_prompt=False) 55