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, os 6from dbus.mainloop.glib import DBusGMainLoop 7 8 9from autotest_lib.client.bin import test, utils 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 def setup(self): 22 os.chdir(self.srcdir) 23 utils.make('OUT_DIR=.') 24 25 26 def initialize(self): 27 super(login_GuestAndActualSession, self).initialize() 28 # Ensure a clean beginning. 29 ownership.restart_ui_to_clear_ownership_files() 30 31 bus_loop = DBusGMainLoop(set_as_default=True) 32 self._session_manager = session_manager.connect(bus_loop) 33 self._listener = session_manager.OwnershipSignalListener( 34 gobject.MainLoop()) 35 self._listener.listen_for_new_key_and_policy() 36 37 38 def run_once(self): 39 owner = 'first_user@nowhere.com' 40 41 cryptohome.mount_guest() 42 self._session_manager.StartSession(constants.GUEST_USER, '') 43 cryptohome.ensure_clean_cryptohome_for(owner) 44 self._session_manager.StartSession(owner, '') 45 self._listener.wait_for_signals(desc='Device ownership complete.') 46 47 # Ensure that the first real user got to be the owner. 48 retrieved_policy = policy.get_policy(self._session_manager) 49 if retrieved_policy is None: raise error.TestFail('Policy not found') 50 policy.compare_policy_response(self.srcdir, retrieved_policy, 51 owner=owner) 52 53 54 def cleanup(self): 55 self._session_manager.StopSession('') 56 cros_ui.start(allow_fail=True, wait_for_login_prompt=False) 57