示例#1
0
    def initialize(self):
        super(logging_UserCrash, self).initialize()

        # If the device has a GUI, return the device to the sign-in screen, as
        # some tests will fail inside a user session.
        if upstart.has_service('ui'):
            cros_ui.restart()
    def run_once(self):
        expected_owner = '*****@*****.**'
        other_user = '******'
        self.__start_session_for(expected_owner)
        self.__start_session_for(other_user)
        self._listener.wait_for_signals(desc='Initial policy push complete.')

        # Ensure that the first user got to be the owner.
        retrieved_policy = policy.get_policy(self._session_manager)
        if retrieved_policy is None: raise error.TestFail('Policy not found')
        policy.compare_policy_response(self.srcdir,
                                       retrieved_policy,
                                       owner=expected_owner)
        # bounce the session manager and wait for it to come back up before
        # reconnecting.
        cros_ui.restart()
        self._session_manager = session_manager.connect(self._bus_loop)

        # Destroy the owner's cryptohome and start sessions again in a
        # different order
        self.__start_session_for(other_user)
        self.__start_session_for(expected_owner)

        self._listener.wait_for_signals(
            desc='Re-taking of ownership complete.')

        # Ensure that the first user still gets to be the owner.
        retrieved_policy = policy.get_policy(self._session_manager)
        if retrieved_policy is None: raise error.TestFail('Policy not found')
        policy.compare_policy_response(self.srcdir,
                                       retrieved_policy,
                                       owner=expected_owner)
示例#3
0
    def initialize(self):
        user_crash_test.UserCrashTest.initialize(self)

        # If the device has a GUI, return the device to the sign-in screen, as
        # some tests will fail inside a user session.
        if upstart.has_service('ui'):
            cros_ui.restart()
    def run_once(self):
        # Mount the vault, connect to session_manager and start the session.
        self._cryptohome_proxy.mount(ownership.TESTUSER,
                                     ownership.TESTPASS,
                                     create=True)
        sm = session_manager.connect(self._bus_loop)
        sm.StartSession(ownership.TESTUSER, '')

        # No policy stored yet.
        retrieved_policy = sm.RetrievePolicyEx(
            session_manager.make_user_policy_descriptor(ownership.TESTUSER),
            byte_arrays=True)
        if retrieved_policy:
            raise error.TestError('session_manager already has user policy!')

        # And no user key exists.
        key_file = ownership.get_user_policy_key_filename(ownership.TESTUSER)
        if os.path.exists(key_file):
            raise error.TestFail('%s exists before storing user policy!' %
                                 key_file)

        # Now store a policy. This is building a device policy protobuf, but
        # that's fine as far as the session_manager is concerned; it's the
        # outer PolicyFetchResponse that contains the public_key.
        public_key = ownership.known_pubkey()
        private_key = ownership.known_privkey()
        policy_data = policy.build_policy_data()
        policy_response = policy.generate_policy(private_key, public_key,
                                                 policy_data)
        try:
            sm.StorePolicyEx(
                session_manager.make_user_policy_descriptor(
                    ownership.TESTUSER), dbus.ByteArray(policy_response))
        except dbus.exceptions.DBusException as e:
            raise error.TestFail('Failed to store user policy', e)

        # The policy key should have been created now.
        self._verify_key_file(key_file)

        # Restart the ui; the key should be deleted.
        self._cryptohome_proxy.unmount(ownership.TESTUSER)
        cros_ui.restart()
        if os.path.exists(key_file):
            raise error.TestFail('%s exists after restarting ui!' % key_file)

        # Starting a new session will restore the key that was previously
        # stored. Reconnect to the session_manager, since the restart killed it.
        self._cryptohome_proxy.mount(ownership.TESTUSER,
                                     ownership.TESTPASS,
                                     create=True)
        sm = session_manager.connect(self._bus_loop)
        sm.StartSession(ownership.TESTUSER, '')
        self._verify_key_file(key_file)
class platform_SessionManagerBlockDevmodeSetting(test.test):
    """Verifies that session_manager updates the block_devmode flag to be in
    sync with the corresponding device setting."""
    version = 1

    def initialize(self):
        super(platform_SessionManagerBlockDevmodeSetting, self).initialize()
        ownership.restart_ui_to_clear_ownership_files()
        self._bus_loop = DBusGMainLoop(set_as_default=True)

    def run_once(self):
        try:
            if utils.system_output('crossystem mainfw_type') == 'nonchrome':
                raise error.TestNAError(
                    'State key generation only works on Chrome OS hardware')
        except error.CmdError, e:
            raise error.TestError('Failed to run crossystem: %s' % e)

        # Make sure that the flag sticks when there is no owner.
        set_block_devmode(True)
        cros_ui.restart()
        cros_ui.stop()
        if not get_block_devmode():
            raise error.TestFail("Flag got reset for non-owned device.")

        # Test whether the flag gets reset when taking ownership.
        listener = session_manager.OwnershipSignalListener(gobject.MainLoop())
        listener.listen_for_new_key_and_policy()
        with chrome.Chrome() as cr:
            listener.wait_for_signals(desc='Ownership files written to disk.')
            if get_block_devmode():
                raise error.TestFail(
                    "Flag not clear after ownership got established.")

        # Put a new owner key and policy blob in place, the latter of which
        # specifies block_devmode=true.
        cros_ui.stop(allow_fail=True)
        shutil.copyfile(os.path.join(self.bindir, 'owner.key'),
                        constants.OWNER_KEY_FILE)
        shutil.copyfile(
            os.path.join(self.bindir, 'policy_block_devmode_enabled'),
            constants.SIGNED_POLICY_FILE)
        cros_ui.start()
        if not get_block_devmode():
            raise error.TestFail(
                "Flag not set after starting with policy enabled.")

        # Send a new policy blob to session_manager that disables block_devmode.
        listener.listen_for_new_policy()
        with open(os.path.join(self.bindir,
                               'policy_block_devmode_disabled')) as f:
            session_manager_proxy = session_manager.connect(self._bus_loop)
            session_manager_proxy.StorePolicyEx(
                session_manager.make_device_policy_descriptor(), f.read())
        listener.wait_for_signals(desc='Policy updated.')

        if get_block_devmode():
            raise error.TestFail(
                "Flag set after updating policy to clear flag.")
 def cleanup(self):
     if self._tempdir: self._tempdir.clean()
     cros_ui.restart()
     self._cryptohome_proxy.remove(ownership.TESTUSER)
     super(login_OwnershipRetaken, self).cleanup()
示例#7
0
 def initialize(self):
     super(login_RetrieveActiveSessions, self).initialize()
     cros_ui.restart()
示例#8
0
 def initialize(self):
     super(login_SameSessionTwice, self).initialize()
     cros_ui.restart()
示例#9
0
 def cleanup(self):
     cros_ui.restart()
     self._cryptohome_proxy.remove(ownership.TESTUSER)
     super(login_UserPolicyKeys, self).cleanup()