• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
8from autotest_lib.client.bin import test
9from autotest_lib.client.common_lib import error
10from autotest_lib.client.common_lib.cros import policy, session_manager
11from autotest_lib.client.cros import cros_ui, cryptohome, ownership
12
13
14class login_MultipleSessions(test.test):
15    """Ensure that the session_manager can handle multiple calls to StartSession
16       correctly.
17    """
18    version = 1
19
20
21    def initialize(self):
22        super(login_MultipleSessions, self).initialize()
23        policy.install_protobufs(self.autodir, self.job)
24        # Ensure a clean beginning.
25        ownership.restart_ui_to_clear_ownership_files()
26
27        self._bus_loop = DBusGMainLoop(set_as_default=True)
28        self._session_manager = session_manager.connect(self._bus_loop)
29        self._listener = session_manager.OwnershipSignalListener(
30                gobject.MainLoop())
31        self._listener.listen_for_new_key_and_policy()
32
33        self._cryptohome_proxy = cryptohome.CryptohomeProxy(
34            self._bus_loop, self.autodir, self.job)
35
36
37    def run_once(self):
38        expected_owner = 'first_user@nowhere.com'
39        other_user = 'second_user@nowhere.com'
40        self.__start_session_for(expected_owner)
41        self.__start_session_for(other_user)
42        self._listener.wait_for_signals(desc='Initial policy push complete.')
43
44        # Ensure that the first 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=expected_owner)
48        # bounce the session manager and wait for it to come back up before
49        # reconnecting.
50        cros_ui.restart()
51        self._session_manager = session_manager.connect(self._bus_loop)
52
53        # Destroy the owner's cryptohome and start sessions again in a
54        # different order
55        self.__start_session_for(other_user)
56        self.__start_session_for(expected_owner)
57
58        self._listener.wait_for_signals(desc='Re-taking of ownership complete.')
59
60        # Ensure that the first user still gets to be the owner.
61        retrieved_policy = policy.get_policy(self._session_manager)
62        if retrieved_policy is None: raise error.TestFail('Policy not found')
63        policy.compare_policy_response(retrieved_policy, owner=expected_owner)
64
65
66    def __start_session_for(self, user):
67        """Call StartSession() for user, ensure he has clean on-device state
68
69        Make a fresh cryptohome for user, and then start a session for him
70        with the session manager.
71
72        @param user: the user to start a session for.
73
74        @raises error.TestFail: if the session cannot be started.
75        """
76        self._cryptohome_proxy.ensure_clean_cryptohome_for(user)
77        self._session_manager.StartSession(user, '')
78
79
80    def cleanup(self):
81        # Bounce UI, without waiting for the browser to come back. Best effort.
82        cros_ui.stop(allow_fail=True)
83        cros_ui.start(allow_fail=True, wait_for_login_prompt=False)
84