summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNicoco K <nicoco@nicoco.fr>2021-02-18 20:05:25 +0100
committermathieui <mathieui@mathieui.net>2021-02-18 20:05:25 +0100
commitcef7b5cf0526f4abf1a8e8adac756dbe2f3cd955 (patch)
tree03b0b5b1a4d6f40fa9056d74639d14b48b9011da /tests
parent5d7918b122bc95d0fa1117e5fea41e742a4a1f76 (diff)
downloadslixmpp-cef7b5cf0526f4abf1a8e8adac756dbe2f3cd955.tar.gz
slixmpp-cef7b5cf0526f4abf1a8e8adac756dbe2f3cd955.tar.bz2
slixmpp-cef7b5cf0526f4abf1a8e8adac756dbe2f3cd955.tar.xz
slixmpp-cef7b5cf0526f4abf1a8e8adac756dbe2f3cd955.zip
Add registration to components
Diffstat (limited to 'tests')
-rw-r--r--tests/test_stream_xep_0077.py112
1 files changed, 112 insertions, 0 deletions
diff --git a/tests/test_stream_xep_0077.py b/tests/test_stream_xep_0077.py
new file mode 100644
index 00000000..c47c4de5
--- /dev/null
+++ b/tests/test_stream_xep_0077.py
@@ -0,0 +1,112 @@
+"""
+This only covers the component registration side of the XEP-0077 plugin
+"""
+
+import unittest
+
+from slixmpp import ComponentXMPP, Iq
+from slixmpp.xmlstream import register_stanza_plugin
+from slixmpp.test import SlixTest
+from slixmpp.plugins.xep_0077 import Register
+
+
+class TestRegistration(SlixTest):
+ def setUp(self):
+ self.stream_start(
+ mode="component", plugins=["xep_0077"], jid="shakespeare.lit", server="lit"
+ )
+
+ def testRegistrationForm(self):
+ self.stream_start(
+ mode="component", plugins=["xep_0077"], jid="shakespeare.lit", server="lit"
+ )
+ self.recv(
+ """
+ <iq type='get' id='reg1' to='shakespeare.lit' from='bill@server/resource'>
+ <query xmlns='jabber:iq:register'/>
+ </iq>
+ """,
+ )
+ self.send(
+ f"""
+ <iq type='result' id='reg1' from='shakespeare.lit' to='bill@server/resource'>
+ <query xmlns='jabber:iq:register'>
+ <instructions>{self.xmpp["xep_0077"].form_instructions}</instructions>
+ <username/>
+ <password/>
+ </query>
+ </iq>
+ """,
+ use_values=False # Fails inconsistently without this
+ )
+
+ def testRegistrationSuccessAndModif(self):
+ self.recv(
+ """
+ <iq type='set' id='reg2' to='shakespeare.lit' from="bill@server/resource">
+ <query xmlns='jabber:iq:register'>
+ <username>bill</username>
+ <password>Calliope</password>
+ </query>
+ </iq>
+ """
+ )
+ self.send("<iq type='result' id='reg2' from='shakespeare.lit' to='bill@server/resource'/>")
+ user_store = self.xmpp["xep_0077"]._user_store
+ self.assertEqual(user_store["bill@server"]["username"], "bill")
+ self.assertEqual(user_store["bill@server"]["password"], "Calliope")
+
+ self.recv(
+ """
+ <iq type='get' id='reg1' to='shakespeare.lit' from="bill@server/resource">
+ <query xmlns='jabber:iq:register'/>
+ </iq>
+ """,
+ )
+ self.send(
+ f"""
+ <iq type='result' id='reg1' to="bill@server/resource" from='shakespeare.lit'>
+ <query xmlns='jabber:iq:register'>
+ <instructions>{self.xmpp["xep_0077"].form_instructions}</instructions>
+ <username>bill</username>
+ <password>Calliope</password>
+ <registered />
+ </query>
+ </iq>
+ """,
+ use_values=False # Fails inconsistently without this
+ )
+
+ def testRegistrationAndRemove(self):
+ self.recv(
+ """
+ <iq type='set' id='reg2' to='shakespeare.lit' from="bill@shakespeare.lit/globe">
+ <query xmlns='jabber:iq:register'>
+ <username>bill</username>
+ <password>Calliope</password>
+ </query>
+ </iq>
+ """
+ )
+ self.send("<iq type='result' id='reg2' from='shakespeare.lit' to='bill@shakespeare.lit/globe'/>")
+ pseudo_iq = self.xmpp.Iq()
+ pseudo_iq["from"] = "bill@shakespeare.lit/globe"
+ user = self.xmpp["xep_0077"].api["user_get"](None, None, None, pseudo_iq)
+ self.assertEqual(user["username"], "bill")
+ self.assertEqual(user["password"], "Calliope")
+ self.recv(
+ """
+ <iq type='set' from='bill@shakespeare.lit/globe' id='unreg1'>
+ <query xmlns='jabber:iq:register'>
+ <remove/>
+ </query>
+ </iq>
+ """
+ )
+ self.send("<iq type='result' to='bill@shakespeare.lit/globe' id='unreg1'/>")
+ user_store = self.xmpp["xep_0077"]._user_store
+ self.assertIs(user_store.get("bill@shakespeare.lit"), None)
+
+
+
+suite = unittest.TestLoader().loadTestsFromTestCase(TestRegistration)