summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_stream_handlers.py53
-rw-r--r--tests/test_stream_xep_0323.py22
2 files changed, 64 insertions, 11 deletions
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):
</message>
""")
+ 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("""
+ <iq id="test" from="evil@sleekxmpp.com/bad" type="result">
+ <query xmlns="test" />
+ </iq>
+ """)
+ self.recv("""
+ <iq id="test" from="evil2@sleekxmpp.com" type="result">
+ <query xmlns="test" />
+ </iq>
+ """)
+ self.recv("""
+ <iq id="test" from="evil.com" type="result">
+ <query xmlns="test" />
+ </iq>
+ """)
+
+ # Now for a good one
+ self.recv("""
+ <iq id="test" from="tester@sleekxmpp.com/test" type="result">
+ <query xmlns="test" />
+ </iq>
+ """)
+
+ t.join()
+
+ time.sleep(0.1)
+
+ self.assertEqual(events, ['tester@sleekxmpp.com/test'], "Did not timeout on bad sender")
+
+
+
suite = unittest.TestLoader().loadTestsFromTestCase(TestHandlers)
diff --git a/tests/test_stream_xep_0323.py b/tests/test_stream_xep_0323.py
index b10f0b0d..fd2ad225 100644
--- a/tests/test_stream_xep_0323.py
+++ b/tests/test_stream_xep_0323.py
@@ -572,16 +572,16 @@ class TestStreamSensorData(SleekTest):
self.failUnlessEqual(results, ["accepted","fields","done"]);
# self.assertIn("nodeId", callback_data);
- self.assertTrue(callback_data.has_key("nodeId"));
+ self.assertTrue("nodeId" in callback_data)
self.failUnlessEqual(callback_data["nodeId"], "Device33");
# self.assertIn("timestamp", callback_data);
- self.assertTrue(callback_data.has_key("timestamp"));
+ self.assertTrue("timestamp" in callback_data);
self.failUnlessEqual(callback_data["timestamp"], "2000-01-01T00:01:02");
#self.assertIn("field_Voltage", callback_data);
- self.assertTrue(callback_data.has_key("field_Voltage"));
+ self.assertTrue("field_Voltage" in callback_data);
self.failUnlessEqual(callback_data["field_Voltage"], {"name": "Voltage", "value": "230.4", "typename": "numeric", "unit": "V", "flags": {"invoiced": "true"}});
#self.assertIn("field_TestBool", callback_data);
- self.assertTrue(callback_data.has_key("field_TestBool"));
+ self.assertTrue("field_TestBool" in callback_data);
self.failUnlessEqual(callback_data["field_TestBool"], {"name": "TestBool", "value": "true", "typename": "boolean" });
def testServiceDiscoveryClient(self):
@@ -693,13 +693,13 @@ class TestStreamSensorData(SleekTest):
self.failUnlessEqual(results, ["accepted","failure"]);
# self.assertIn("nodeId", callback_data);
- self.assertTrue(callback_data.has_key("nodeId"));
+ self.assertTrue("nodeId" in callback_data);
self.failUnlessEqual(callback_data["nodeId"], "Device33");
# self.assertIn("timestamp", callback_data);
- self.assertTrue(callback_data.has_key("timestamp"));
+ self.assertTrue("timestamp" in callback_data);
self.failUnlessEqual(callback_data["timestamp"], "2013-03-07T17:13:30");
# self.assertIn("error_msg", callback_data);
- self.assertTrue(callback_data.has_key("error_msg"));
+ self.assertTrue("error_msg" in callback_data);
self.failUnlessEqual(callback_data["error_msg"], "Timeout.");
def testDelayedRequest(self):
@@ -1095,16 +1095,16 @@ class TestStreamSensorData(SleekTest):
self.failUnlessEqual(results, ["queued","started","fields","done"]);
# self.assertIn("nodeId", callback_data);
- self.assertTrue(callback_data.has_key("nodeId"));
+ self.assertTrue("nodeId" in callback_data);
self.failUnlessEqual(callback_data["nodeId"], "Device33");
# self.assertIn("timestamp", callback_data);
- self.assertTrue(callback_data.has_key("timestamp"));
+ self.assertTrue("timestamp" in callback_data);
self.failUnlessEqual(callback_data["timestamp"], "2000-01-01T00:01:02");
# self.assertIn("field_Voltage", callback_data);
- self.assertTrue(callback_data.has_key("field_Voltage"));
+ self.assertTrue("field_Voltage" in callback_data);
self.failUnlessEqual(callback_data["field_Voltage"], {"name": "Voltage", "value": "230.4", "typename": "numeric", "unit": "V", "flags": {"invoiced": "true"}});
# self.assertIn("field_TestBool", callback_data);
- self.assertTrue(callback_data.has_key("field_TestBool"));
+ self.assertTrue("field_TestBool" in callback_data);
self.failUnlessEqual(callback_data["field_TestBool"], {"name": "TestBool", "value": "true", "typename": "boolean" });