Switch login_MultipleSessions to use CryptohomeProxy
Instead of shelling out to the cryptohome command line tool,
use CryptohomeProxy to speak to cryptohomed over DBus.
BUG=chromium:344862
TEST=login_MultipleSessions
Change-Id: Ib79cf092b2385b2d922abbc81cf6bd744fe8a0da
Reviewed-on: https://chromium-review.googlesource.com/190088
Tested-by: Chris Masone <cmasone@chromium.org>
Reviewed-by: Will Drewry <wad@chromium.org>
Commit-Queue: Chris Masone <cmasone@chromium.org>
diff --git a/client/cros/cryptohome.py b/client/cros/cryptohome.py
index 822cff1..6101eb8 100644
--- a/client/cros/cryptohome.py
+++ b/client/cros/cryptohome.py
@@ -298,6 +298,7 @@
)
DBUS_PROPERTIES_INTERFACE = 'org.freedesktop.DBus.Properties'
+
def __init__(self):
self.main_loop = gobject.MainLoop()
bus_loop = DBusGMainLoop(set_as_default=True)
@@ -313,6 +314,7 @@
self.ASYNC_CALL_STATUS_SIGNAL,
self.ASYNC_CALL_STATUS_SIGNAL_ARGUMENTS)
+
# Wrap all proxied calls to catch cryptohomed failures.
def __call(self, method, *args):
try:
@@ -324,6 +326,7 @@
raise ChromiumOSError('cryptohomed aborted. Check crashes!')
raise e
+
def __wait_for_specific_signal(self, signal, data):
"""Wait for the |signal| with matching |data|
Returns the resulting dict on success or {} on error.
@@ -340,6 +343,7 @@
return {}
return result
+
# Perform a data-less async call.
# TODO(wad) Add __async_data_call.
def __async_call(self, method, *args):
@@ -360,6 +364,7 @@
raise ChromiumOSError('cryptohomed aborted. Check crashes!')
return result
+
def mount(self, user, password, create=False, async=True):
"""Mounts a cryptohome.
@@ -374,6 +379,7 @@
# Sync returns (return code, return status)
return out[1] if len(out) > 1 else False
+
def unmount(self, user):
"""Unmounts a cryptohome.
@@ -383,16 +389,19 @@
"""
return self.__call(self.iface.Unmount)
+
def is_mounted(self, user):
"""Tests whether a user's cryptohome is mounted."""
return (utils.is_mountpoint(user_path(user))
and utils.is_mountpoint(system_path(user)))
+
def require_mounted(self, user):
"""Raises a test failure if a user's cryptohome is not mounted."""
utils.require_mountpoint(user_path(user))
utils.require_mountpoint(system_path(user))
+
def migrate(self, user, oldkey, newkey, async=True):
"""Migrates the specified user's cryptohome from one key to another."""
if async:
@@ -400,8 +409,21 @@
user, oldkey, newkey)['return_status']
return self.__call(self.iface.MigrateKey, user, oldkey, newkey)
+
def remove(self, user, async=True):
if async:
return self.__async_call(self.iface.AsyncRemove,
user)['return_status']
return self.__call(self.iface.Remove, user)
+
+
+ def ensure_clean_cryptohome_for(self, user, password=None):
+ """Ensure a fresh cryptohome exists for user.
+
+ @param user: user who needs a shiny new cryptohome.
+ @param password: if unset, a random password will be used.
+ """
+ if not password:
+ password = ''.join(random.sample(string.ascii_lowercase, 6))
+ self.remove(user)
+ self.mount(user, password, create=True)
diff --git a/client/site_tests/login_MultipleSessions/login_MultipleSessions.py b/client/site_tests/login_MultipleSessions/login_MultipleSessions.py
index 62ef954..facfe18 100644
--- a/client/site_tests/login_MultipleSessions/login_MultipleSessions.py
+++ b/client/site_tests/login_MultipleSessions/login_MultipleSessions.py
@@ -77,7 +77,7 @@
@raises error.TestFail: if the session cannot be started.
"""
- cryptohome.ensure_clean_cryptohome_for(user)
+ cryptohome.CryptohomeProxy().ensure_clean_cryptohome_for(user)
if not self._session_manager.StartSession(user, ''):
raise error.TestFail('Could not start session for ' + user)