From 651915f31cc1f967df35ff016b6823312d84bf5e Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Thu, 6 Feb 2014 09:13:28 -0800 Subject: [PATCH] Add test for wrong sender in IQ --- tests/test_stream_handlers.py | 53 +++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/tests/test_stream_handlers.py b/tests/test_stream_handlers.py index ef46da6a..0208cd16 100644 --- a/tests/test_stream_handlers.py +++ b/tests/test_stream_handlers.py @@ -1,4 +1,5 @@ import time +import threading import unittest from sleekxmpp.test import SleekTest @@ -226,5 +227,57 @@ class TestHandlers(SleekTest): """) + def testWrongSender(self): + """ + Test that using the wrong sender JID in a IQ result + doesn't trigger handlers. + """ + + events = [] + + def run_test(): + # Check that Iq was sent by waiter_handler + iq = self.Iq() + iq['id'] = 'test' + iq['to'] = 'tester@sleekxmpp.com/test' + iq['type'] = 'set' + iq['query'] = 'test' + result = iq.send() + events.append(result['from'].full) + + t = threading.Thread(name="sender_test", target=run_test) + t.start() + + self.recv(""" + + + + """) + self.recv(""" + + + + """) + self.recv(""" + + + + """) + + # Now for a good one + self.recv(""" + + + + """) + + t.join() + + time.sleep(0.1) + + self.assertEqual(events, ['tester@sleekxmpp.com/test'], "Did not timeout on bad sender") + + + suite = unittest.TestLoader().loadTestsFromTestCase(TestHandlers)