From d7a76939e9a11c5d8b5b2e62c892998834cc5040 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 13 Nov 2013 17:42:09 +0000 Subject: [PATCH 13/26] Add some missing test coverage: IdentifyAccount failing hard --- tests/twisted/account-manager/bad-cm.py | 11 +++++++++- tests/twisted/mctest.py | 38 +++++++++++++++++++++++++-------- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/tests/twisted/account-manager/bad-cm.py b/tests/twisted/account-manager/bad-cm.py index 74277b4..008ac60 100644 --- a/tests/twisted/account-manager/bad-cm.py +++ b/tests/twisted/account-manager/bad-cm.py @@ -22,11 +22,12 @@ import dbus from servicetest import call_async, assertEquals, assertContains -from mctest import exec_test, AccountManager +from mctest import (exec_test, SimulatedConnectionManager, AccountManager) import constants as cs def test(q, bus, mc): am = AccountManager(bus) + simulated_cm = SimulatedConnectionManager(q, bus) def call_create(cm='fakecm', protocol='fakeprotocol', parameters=None): if parameters is None: @@ -74,5 +75,13 @@ def test(q, bus, mc): assertEquals(cs.INVALID_ARGUMENT, e.name) assertContains("password", e.message) + # Create an account that will fail IdentifyAccount + call_create(parameters={ "account": "", + "password": "ohai", + }) + e = q.expect('dbus-error', method='CreateAccount') + assertEquals(cs.INVALID_HANDLE, e.name) + assertContains("Invalid account name", e.message) + if __name__ == '__main__': exec_test(test, {}) diff --git a/tests/twisted/mctest.py b/tests/twisted/mctest.py index b093ee8..4267af2 100644 --- a/tests/twisted/mctest.py +++ b/tests/twisted/mctest.py @@ -1025,12 +1025,11 @@ class SimulatedConnectionManager(object): for protocol_name in protocol_names: assert '-' not in protocol_name - q.add_dbus_method_impl(self.IdentifyAccount, - path=self.object_path + '/' + protocol_name, - interface=cs.PROTOCOL, method='IdentifyAccount') - q.add_dbus_method_impl(self.NormalizeContact, - path=self.object_path + '/' + protocol_name, - interface=cs.PROTOCOL, method='NormalizeContact') + + q.add_dbus_method_impl(self.IdentifyAccount, + interface=cs.PROTOCOL, method='IdentifyAccount') + q.add_dbus_method_impl(self.NormalizeContact, + interface=cs.PROTOCOL, method='NormalizeContact') def release_name(self): del self._bus_name_ref @@ -1139,11 +1138,32 @@ class SimulatedConnectionManager(object): }, signature='a{sv}', bus=self.bus) def IdentifyAccount(self, e): + if e.path.startswith(self.object_path + '/'): + protocol = e.path[len(self.object_path + '/'):] + + if protocol not in self.protocol_names: + self.q.dbus_raise(e.message, cs.DBUS_ERROR_UNKNOWN_METHOD, + 'Not my protocol') + return + else: + self.q.dbus_raise(e.message, cs.DBUS_ERROR_UNKNOWN_METHOD, + 'Not even my object path') + return + + if protocol in ('serializable', 'defaults') and 's' in e.args[0]: + ret = e.args[0]['s'].lower() + if ret: + self.q.dbus_return(e.message, ret, signature='s') + return + if 'account' in e.args[0]: ret = e.args[0]['account'].lower() - else: - ret = 'account' - self.q.dbus_return(e.message, ret, signature='s') + if ret: + self.q.dbus_return(e.message, ret, signature='s') + return + + self.q.dbus_raise(e.message, cs.INVALID_HANDLE, + 'Invalid account name %r' % e.args[0].get('account')) def NormalizeContact(self, e): self.q.dbus_return(e.message, e.args[0].lower(), signature='s') -- 1.8.4.3