From ac330b5c6c7a24eda0e91d4fc70414cfff014545 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Mon, 25 Oct 2010 12:52:32 -0400 Subject: [PATCH] Fixed bug in presence subscription handling. Subscription requests and responses were not setting the correct 'to' attribute. --- sleekxmpp/basexmpp.py | 4 ++-- tests/test_stream_presence.py | 42 +++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/sleekxmpp/basexmpp.py b/sleekxmpp/basexmpp.py index bef4711..1e8441a 100644 --- a/sleekxmpp/basexmpp.py +++ b/sleekxmpp/basexmpp.py @@ -621,8 +621,8 @@ class BaseXMPP(XMLStream): None * Disable automatic handling and use a custom handler. """ - presence = self.Presence() - presence['to'] = presence['from'].bare + presence.reply() + presence['to'] = presence['to'].bare # We are using trinary logic, so conditions have to be # more explicit than usual. diff --git a/tests/test_stream_presence.py b/tests/test_stream_presence.py index 135d8ee..994d4e1 100644 --- a/tests/test_stream_presence.py +++ b/tests/test_stream_presence.py @@ -82,5 +82,47 @@ class TestStreamPresence(SleekTest): self.assertEqual(events, ['got_offline'], "Got offline incorrectly triggered: %s" % events) + def testAutoAuthorizeAndSubscribe(self): + """ + Test auto authorizing and auto subscribing + to subscription requests. + """ + + events = set() + + def presence_subscribe(p): + events.add('presence_subscribe') + + def changed_subscription(p): + events.add('changed_subscription') + + self.stream_start(jid='tester@localhost') + + self.xmpp.add_event_handler('changed_subscription', + changed_subscription) + self.xmpp.add_event_handler('presence_subscribe', + presence_subscribe) + + # With these settings we should accept a subscription + # and request a subscription in return. + self.xmpp.auto_authorize = True + self.xmpp.auto_subscribe = True + + self.stream_recv(""" + + """) + + self.stream_send_presence(""" + + """) + + self.stream_send_presence(""" + + """) + + expected = set(('presence_subscribe', 'changed_subscription')) + self.assertEqual(events, expected, + "Incorrect events triggered: %s" % events) + suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamPresence)