diff options
author | mathieui <mathieui@mathieui.net> | 2021-02-18 20:05:25 +0100 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2021-02-18 20:05:25 +0100 |
commit | 626bf5ff8ac5bc4c8758cd437e52f4e7c86ec179 (patch) | |
tree | f3d8d1d3c91b59e6e2467fe20615267853904c15 /tests | |
parent | 8d92027d0176107bacab26b03172cdb461a2882b (diff) | |
parent | cef7b5cf0526f4abf1a8e8adac756dbe2f3cd955 (diff) | |
download | slixmpp-626bf5ff8ac5bc4c8758cd437e52f4e7c86ec179.tar.gz slixmpp-626bf5ff8ac5bc4c8758cd437e52f4e7c86ec179.tar.bz2 slixmpp-626bf5ff8ac5bc4c8758cd437e52f4e7c86ec179.tar.xz slixmpp-626bf5ff8ac5bc4c8758cd437e52f4e7c86ec179.zip |
Merge branch 'component-registration' into 'master'
Add registration to components
See merge request poezio/slixmpp!130
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_stream_xep_0077.py | 112 |
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) |