diff options
author | David Laban <david.laban@collabora.co.uk> | 2010-12-13 20:34:52 +0000 |
---|---|---|
committer | David Laban <david.laban@collabora.co.uk> | 2010-12-15 14:34:32 +0000 |
commit | fd3166fc69faa317c2d7d9f9770c6471d57e5a8d (patch) | |
tree | 59d4bfcaa168c39646b5e58ae3b0d54dddf2ab53 | |
parent | d2a65899f22ea3d91d7c47793298c55082668be1 (diff) |
test registering without a password
and using a sasl channel to request the password if the server challenges,
or not asking for a password if the server doesn't challenge.
-rw-r--r-- | tests/twisted/Makefile.am | 1 | ||||
-rw-r--r-- | tests/twisted/sofiatest.py | 9 | ||||
-rw-r--r-- | tests/twisted/test-register-sasl.py | 36 | ||||
-rw-r--r-- | tests/twisted/test-register.py | 2 |
4 files changed, 46 insertions, 2 deletions
diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am index 5988592..086e437 100644 --- a/tests/twisted/Makefile.am +++ b/tests/twisted/Makefile.am @@ -2,6 +2,7 @@ TWISTED_TESTS = \ cm/protocol.py \ test-register.py \ test-register-fail.py \ + test-register-sasl.py \ test-handle-normalisation.py \ test-message.py \ test-self-alias.py \ diff --git a/tests/twisted/sofiatest.py b/tests/twisted/sofiatest.py index 2ec5b75..94263b9 100644 --- a/tests/twisted/sofiatest.py +++ b/tests/twisted/sofiatest.py @@ -20,6 +20,9 @@ class SipProxy(sip.RegisterProxy): def register(self, message, host, port): if hasattr(self, 'registrar_handler'): + self.event_func(servicetest.Event('sip-register', + uri=str(message.uri), headers=message.headers, body=message.body, + sip_message=message, host=host, port=port)) if self.registrar_handler(message, host, port): sip.RegisterProxy.register(self, message, host, port) else: @@ -48,7 +51,11 @@ def prepare_test(event_func, register_cb, params=None): } if params is not None: - actual_params.update(params) + for k, v in params.items(): + if v is None: + actual_params.pop(k, None) + else: + actual_params[k] = v bus = dbus.SessionBus() conn = servicetest.make_connection(bus, event_func, diff --git a/tests/twisted/test-register-sasl.py b/tests/twisted/test-register-sasl.py new file mode 100644 index 0000000..f4ef924 --- /dev/null +++ b/tests/twisted/test-register-sasl.py @@ -0,0 +1,36 @@ +""" +Test SIP registration failure. +""" + +import dbus + +from sofiatest import exec_test + +def test(q, bus, conn, sip): + conn.Connect() + q.expect('dbus-signal', signal='StatusChanged', args=[1, 1]) + + q.expect('sip-register') + + nc = q.expect('dbus-signal', signal='NewChannels') + (((path, props),),) = nc.args + assert props['org.freedesktop.Telepathy.Channel.ChannelType'] == \ + 'org.freedesktop.Telepathy.Channel.Type.ServerAuthentication' + assert props['org.freedesktop.Telepathy.Channel.Interface.SASLAuthentication.AvailableMechanisms'] == \ + ['X-TELEPATHY-PASSWORD'] + + chan = dbus.Interface(bus.get_object(conn._named_service, path), + "org.freedesktop.Telepathy.Channel.Interface.SASLAuthentication") + + chan.StartMechanismWithData('X-TELEPATHY-PASSWORD', 'wrong password') + chan.AcceptSASL() + + q.expect('sip-register') + + q.expect('dbus-signal', signal='StatusChanged', args=[2, 3]) + return True + +if __name__ == '__main__': + exec_test(test, register_cb=lambda *args: False, + params={"password": None}) + diff --git a/tests/twisted/test-register.py b/tests/twisted/test-register.py index b44b93d..9a292e7 100644 --- a/tests/twisted/test-register.py +++ b/tests/twisted/test-register.py @@ -13,5 +13,5 @@ def test(q, bus, conn, sip): return True if __name__ == '__main__': - exec_test(test) + exec_test(test, params={"password": None}) |