Skip to content
This repository has been archived by the owner on Jan 30, 2018. It is now read-only.

Commit

Permalink
Fixed bug in presence subscription handling.
Browse files Browse the repository at this point in the history
Subscription requests and responses were not setting the correct 'to'
attribute.
  • Loading branch information
legastero committed Oct 25, 2010
1 parent 46ffa8e commit ac330b5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sleekxmpp/basexmpp.py
Expand Up @@ -621,8 +621,8 @@ def _handle_subscribe(self, presence):
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.
Expand Down
42 changes: 42 additions & 0 deletions tests/test_stream_presence.py
Expand Up @@ -82,5 +82,47 @@ def got_offline(presence):
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("""
<presence from="user@localhost" type="subscribe" />
""")

self.stream_send_presence("""
<presence to="user@localhost" type="subscribed" />
""")

self.stream_send_presence("""
<presence to="user@localhost" type="subscribe" />
""")

expected = set(('presence_subscribe', 'changed_subscription'))
self.assertEqual(events, expected,
"Incorrect events triggered: %s" % events)


suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamPresence)

0 comments on commit ac330b5

Please sign in to comment.