summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--slixmpp/plugins/xep_0405/mix_pam.py2
-rw-r--r--tests/test_stanza_xep_0403.py32
-rw-r--r--tests/test_stream_xep_0405.py181
3 files changed, 214 insertions, 1 deletions
diff --git a/slixmpp/plugins/xep_0405/mix_pam.py b/slixmpp/plugins/xep_0405/mix_pam.py
index 2b132526..7d87158e 100644
--- a/slixmpp/plugins/xep_0405/mix_pam.py
+++ b/slixmpp/plugins/xep_0405/mix_pam.py
@@ -70,7 +70,7 @@ class XEP_0405(BasePlugin):
iq['client_join']['mix_join'].append(sub)
result = await iq.send(**iqkwargs)
result_nodes = {sub['node'] for sub in result['client_join']['mix_join']}
- return result_nodes.difference(subscribe)
+ return subscribe.difference(result_nodes)
async def leave_channel(self, room: JID, *,
ito: Optional[JID] = None,
diff --git a/tests/test_stanza_xep_0403.py b/tests/test_stanza_xep_0403.py
new file mode 100644
index 00000000..7d7a5daa
--- /dev/null
+++ b/tests/test_stanza_xep_0403.py
@@ -0,0 +1,32 @@
+import unittest
+from slixmpp import Presence, JID
+from slixmpp.test import SlixTest
+from slixmpp.plugins.xep_0403 import stanza
+
+
+class TestMIXPresenceStanza(SlixTest):
+
+ def setUp(self):
+ stanza.register_plugins()
+
+ def testMIXPresence(self):
+ """Test that data is converted to base64"""
+ pres = Presence()
+ pres['show'] = 'dnd'
+ pres['status'] = 'Hey there!'
+ pres['mix']['jid'] = JID('toto@example.com')
+ pres['mix']['nick'] = 'Toto toto'
+
+ self.check(pres, """
+ <presence>
+ <show>dnd</show>
+ <status>Hey there!</status>
+ <mix xmlns="urn:xmpp:mix:presence:0">
+ <jid>toto@example.com</jid>
+ <nick>Toto toto</nick>
+ </mix>
+ </presence>
+ """)
+
+
+suite = unittest.TestLoader().loadTestsFromTestCase(TestMIXPresenceStanza)
diff --git a/tests/test_stream_xep_0405.py b/tests/test_stream_xep_0405.py
new file mode 100644
index 00000000..9bc01601
--- /dev/null
+++ b/tests/test_stream_xep_0405.py
@@ -0,0 +1,181 @@
+import unittest
+from slixmpp.test import SlixTest
+from slixmpp import JID
+
+
+class TestMIXPAM(SlixTest):
+
+ def setUp(self):
+ self.stream_start(plugins=['xep_0405'])
+
+ def tearDown(self):
+ self.stream_close()
+
+ def testGetRosterEmpty(self):
+ """Test requesting an empty annotated roster"""
+
+ fut = self.xmpp.wrap(self.xmpp['xep_0405'].get_mix_roster())
+
+ self.wait_()
+ self.send("""
+ <iq type="get" id="1">
+ <query xmlns="jabber:iq:roster">
+ <annotate xmlns='urn:xmpp:mix:roster:0' />
+ </query>
+ </iq>
+ """)
+
+ self.recv("""
+ <iq type="result" id="1"
+ to="tester@localhost" />
+ """)
+
+ result = self.run_coro(fut)
+
+ def testGetRoster(self):
+ """Test requesting an annotated roster"""
+
+ fut = self.xmpp.wrap(self.xmpp['xep_0405'].get_mix_roster())
+
+ self.wait_()
+ self.send("""
+ <iq type="get" id="1">
+ <query xmlns="jabber:iq:roster">
+ <annotate xmlns='urn:xmpp:mix:roster:0' />
+ </query>
+ </iq>
+ """)
+
+ self.recv("""
+ <iq type="result" id="1" to="tester@localhost">
+ <query xmlns="jabber:iq:roster">
+ <item jid='romeo@example.net'/>
+ <item jid='juliet@example.net'/>
+ <item jid='balcony@example.net'>
+ <channel xmlns='urn:xmpp:mix:roster:0'
+ participant-id='123456'/>
+ </item>
+ </query>
+ </iq>
+ """)
+
+ self.wait_()
+ contacts, channels = fut.result()
+ self.assertEqual(len(contacts), 2)
+ self.assertEqual(contacts[0]['jid'], 'romeo@example.net')
+ self.assertEqual(contacts[1]['jid'], 'juliet@example.net')
+ self.assertEqual(len(channels), 1)
+ self.assertEqual(channels[0]['jid'], 'balcony@example.net')
+ self.assertEqual(
+ channels[0]['channel']['participant-id'],
+ '123456'
+ )
+
+ def testClientJoin(self):
+ """Test a client join"""
+
+ fut = self.xmpp.wrap(self.xmpp['xep_0405'].join_channel(
+ JID('coven@mix.shakespeare.example'),
+ 'toto',
+ ))
+ self.send("""
+ <iq type='set' to='tester@localhost' id='1'>
+ <client-join xmlns='urn:xmpp:mix:pam:2'
+ channel='coven@mix.shakespeare.example'>
+ <join xmlns='urn:xmpp:mix:core:1'>
+ <nick>toto</nick>
+ <subscribe node='urn:xmpp:mix:nodes:messages'/>
+ <subscribe node='urn:xmpp:mix:nodes:participants'/>
+ <subscribe node='urn:xmpp:mix:nodes:info'/>
+ </join>
+ </client-join>
+ </iq>
+ """)
+ self.recv("""
+ <iq type='result'
+ from='tester@localhost'
+ to='tester@localhost/resource'
+ id='1'>
+ <client-join xmlns='urn:xmpp:mix:pam:2'>
+ <join xmlns='urn:xmpp:mix:core:1'
+ jid='123456#coven@mix.shakespeare.example'>
+ <subscribe node='urn:xmpp:mix:nodes:messages'/>
+ <subscribe node='urn:xmpp:mix:nodes:participants'/>
+ <subscribe node='urn:xmpp:mix:nodes:info'/>
+ </join>
+ </client-join>
+ </iq>
+ """)
+ self.wait_()
+ self.assertEqual(fut.result(), set())
+
+ def testClientJoinNotAllNodes(self):
+ """Test a client join where one of the nodes is rejected"""
+
+ fut = self.xmpp.wrap(self.xmpp['xep_0405'].join_channel(
+ JID('coven@mix.shakespeare.example'),
+ 'toto',
+ ))
+ self.send("""
+ <iq type='set' to='tester@localhost' id='1'>
+ <client-join xmlns='urn:xmpp:mix:pam:2'
+ channel='coven@mix.shakespeare.example'>
+ <join xmlns='urn:xmpp:mix:core:1'>
+ <nick>toto</nick>
+ <subscribe node='urn:xmpp:mix:nodes:messages'/>
+ <subscribe node='urn:xmpp:mix:nodes:participants'/>
+ <subscribe node='urn:xmpp:mix:nodes:info'/>
+ </join>
+ </client-join>
+ </iq>
+ """)
+ self.recv("""
+ <iq type='result'
+ from='tester@localhost'
+ to='tester@localhost/resource'
+ id='1'>
+ <client-join xmlns='urn:xmpp:mix:pam:2'>
+ <join xmlns='urn:xmpp:mix:core:1'
+ jid='123456#coven@mix.shakespeare.example'>
+ <subscribe node='urn:xmpp:mix:nodes:messages'/>
+ <subscribe node='urn:xmpp:mix:nodes:participants'/>
+ </join>
+ </client-join>
+ </iq>
+ """)
+ self.wait_()
+ self.assertEqual(fut.result(), {'urn:xmpp:mix:nodes:info'})
+
+ def testClientLeave(self):
+ """Test a client leave"""
+
+ fut = self.xmpp.wrap(self.xmpp['xep_0405'].leave_channel(
+ JID('coven@mix.shakespeare.example'),
+ ))
+ self.send("""
+ <iq type='set'
+ to='tester@localhost'
+ id='1'>
+ <client-leave xmlns='urn:xmpp:mix:pam:2'
+ channel='coven@mix.shakespeare.example'>
+ <leave xmlns='urn:xmpp:mix:core:1'/>
+ </client-leave>
+ </iq>
+ """)
+ self.recv("""
+ <iq type='result'
+ from='tester@localhost'
+ to='tester@localhost/resource'
+ id='1'>
+ <client-leave xmlns='urn:xmpp:mix:pam:2'
+ channel='coven@mix.shakespeare.example'>
+ <leave xmlns='urn:xmpp:mix:core:1'/>
+ </client-leave>
+ </iq>
+ """)
+
+ self.assertEqual(fut.done(), True)
+ self.assertEqual(fut.exception(), None)
+
+
+suite = unittest.TestLoader().loadTestsFromTestCase(TestMIXPAM)