def testAdmin(self): iq = Iq() iq['id'] = '0' iq['type'] = 'set' iq.enable('mucadmin_query') items = [ ('none', 'test@example/a'), ('owner', 'owner@example/a'), ] for aff, jid in items: item_el = MUCAdminItem() item_el['affiliation'] = aff item_el['jid'] = jid iq['mucadmin_query'].append(item_el) self.check(iq, """ <iq type='set' id='0'> <query xmlns='http://jabber.org/protocol/muc#admin'> <item jid='test@example/a' affiliation='none'/> <item jid='owner@example/a' affiliation='owner'/> </query> </iq> """, use_values=False)
def testMIXLeave(self): iq = Iq() iq['type'] = 'set' iq.enable('mix_leave') self.check(iq, """ <iq type="set"> <leave xmlns='urn:xmpp:mix:core:1'/> </iq> """)
def testMIXUpdateSub(self): iq = Iq() iq['type'] = 'set' iq.enable('mix_updatesub') sub = stanza.Subscribe() sub['node'] = 'urn:xmpp:mix:nodes:someothernode' iq['mix_updatesub'].append(sub) self.check(iq, """ <iq type="set"> <update-subscription xmlns='urn:xmpp:mix:core:1'> <subscribe node='urn:xmpp:mix:nodes:someothernode'/> </update-subscription> </iq> """)
def testInvalidAlgo(self): """Test that invalid algos raise an exception.""" iq = Iq() iq['type'] = 'set' try: iq['hash']['algo'] = 'coucou' except ValueError: pass else: raise self.failureException
def testMIXSetNick(self): iq = Iq() iq['type'] = 'set' iq['mix_setnick']['nick'] = 'A nick' self.check(iq, """ <iq type="set"> <setnick xmlns='urn:xmpp:mix:core:1'> <nick>A nick</nick> </setnick> </iq> """)
def testMAMQuery(self): """Test that we can build a simple MAM query.""" iq = Iq() iq['type'] = 'set' iq['mam']['queryid'] = 'f27' self.check( iq, """ <iq type='set'> <query xmlns='urn:xmpp:mam:2' queryid='f27'/> </iq> """)
def testSimpleElement(self): """Test that the element is created correctly.""" iq = Iq() iq['type'] = 'set' iq['hash']['algo'] = 'sha-256' iq['hash']['value'] = 'EQgS9n+h4fARf289cCQcGkKnsHcRqTwkd8xRbZBC+ds=' self.check(iq, """ <iq type="set"> <hash xmlns="urn:xmpp:hashes:2" algo="sha-256">EQgS9n+h4fARf289cCQcGkKnsHcRqTwkd8xRbZBC+ds=</hash> </iq> """)
def testConvertData(self): """Test that data is converted to base64""" iq = Iq() iq['type'] = 'set' iq['ibb_data']['seq'] = 0 iq['ibb_data']['data'] = 'slixmpp' self.check( iq, """ <iq type="set"> <data xmlns="http://jabber.org/protocol/ibb" seq="0">c2xpeG1wcA==</data> </iq> """)
def testMIXPAMLeave(self): iq = Iq() iq['type'] = 'set' iq['client_leave']['channel'] = JID('*****@*****.**') iq['client_leave'].enable('mix_leave') self.check( iq, """ <iq type="set"> <client-leave xmlns='urn:xmpp:mix:pam:2' channel='*****@*****.**'> <leave xmlns='urn:xmpp:mix:core:1'/> </client-leave> </iq> """)
def testSetAffiliation(self): iq = Iq() iq['type'] = 'set' iq['id'] = '1' iq['mucadmin_query']['item']['jid'] = JID('*****@*****.**') iq['mucadmin_query']['item']['affiliation'] = 'owner' self.check(iq, """ <iq type='set' id='1'> <query xmlns='http://jabber.org/protocol/muc#admin'> <item jid='*****@*****.**' affiliation='owner'/> </query> </iq> """, use_values=False)
def testMAMQueryOptions(self): """Test that we can build a mam query with all options.""" iq = Iq() iq['type'] = 'set' iq['mam']['with'] = JID('*****@*****.**') iq['mam']['start'] = '2010-06-07T00:00:00Z' iq['mam']['end'] = '2010-07-07T13:23:54Z' iq['mam']['after_id'] = 'id1' iq['mam']['before_id'] = 'id2' iq['mam']['ids'] = ['a', 'b', 'c'] self.check(iq, """ <iq type='set'> <query xmlns='urn:xmpp:mam:2'> <x xmlns='jabber:x:data' type='submit'> <field var='FORM_TYPE' type='hidden'> <value>urn:xmpp:mam:2</value> </field> <field var='with'> <value>[email protected]</value> </field> <field var='start'> <value>2010-06-07T00:00:00Z</value> </field> <field var='end'> <value>2010-07-07T13:23:54Z</value> </field> <field var='after-id'> <value>id1</value> </field> <field var='before-id'> <value>id2</value> </field> <field var='ids'> <value>a</value> <value>b</value> <value>c</value> </field> </x> </query> </iq> """, use_values=False)
def testMAMMetadata(self): """Test that we can build a MAM metadata payload""" iq = Iq() iq['type'] = 'result' iq['mam_metadata']['start']['id'] = 'YWxwaGEg' iq['mam_metadata']['start']['timestamp'] = '2008-08-22T21:09:04Z' iq['mam_metadata']['end']['id'] = 'b21lZ2Eg' iq['mam_metadata']['end']['timestamp'] = '2020-04-20T14:34:21Z' self.check( iq, """ <iq type='result'> <metadata xmlns='urn:xmpp:mam:2'> <start id='YWxwaGEg' timestamp='2008-08-22T21:09:04Z' /> <end id='b21lZ2Eg' timestamp='2020-04-20T14:34:21Z' /> </metadata> </iq> """)
def testModerate(self): iq = Iq() iq['type'] = 'set' iq['id'] = 'a' iq['apply_to']['id'] = 'some-id' iq['apply_to']['moderate'].enable('retract') iq['apply_to']['moderate']['reason'] = 'R' self.check(iq, """ <iq type='set' id='a'> <apply-to id="some-id" xmlns="urn:xmpp:fasten:0"> <moderate xmlns='urn:xmpp:message-moderate:0'> <retract xmlns='urn:xmpp:message-retract:0'/> <reason>R</reason> </moderate> </apply-to> </iq> """, use_values=False)
def testMIXJoin(self): """Test that data is converted to base64""" iq = Iq() iq['type'] = 'set' for node in BASE_NODES: sub = stanza.Subscribe() sub['node'] = node iq['mix_join'].append(sub) iq['mix_join']['nick'] = 'Toto' self.check(iq, """ <iq type="set"> <join xmlns='urn:xmpp:mix:core:1'> <subscribe node='urn:xmpp:mix:nodes:messages'/> <subscribe node='urn:xmpp:mix:nodes:participants'/> <subscribe node='urn:xmpp:mix:nodes:info'/> <nick>Toto</nick> </join> </iq> """)
def testInvalidBase64PrefixEqual(self): """ Test detecting invalid base64 data with = as a prefix to the character data. """ iq = Iq(xml=ET.fromstring(""" <iq type="set" id="0" to="tester@localhost"> <data xmlns="http://jabber.org/protocol/ibb" seq="0"> =ABCDEFGH </data> </iq> """)) errored = False try: data = iq['ibb_data']['data'] except XMPPError: errored = True self.assertTrue(errored, "=ABCDEFGH did not raise base64 error")
def testInvalidBase64Alphabet(self): """ Test detecting invalid base64 data with characters outside of the base64 alphabet. """ iq = Iq(xml=ET.fromstring(""" <iq type="set" id="0" to="tester@localhost"> <data xmlns="http://jabber.org/protocol/ibb" seq="0"> ABCD?EFGH </data> </iq> """)) errored = False try: data = iq['ibb_data']['data'] except XMPPError: errored = True self.assertTrue(errored, "ABCD?EFGH did not raise base64 error")
def testMIXPAMJoin(self): """Test that data is converted to base64""" iq = Iq() iq['type'] = 'set' iq['client_join']['channel'] = JID('*****@*****.**') for node in BASE_NODES: sub = mstanza.Subscribe() sub['node'] = node iq['client_join']['mix_join'].append(sub) iq['client_join']['mix_join']['nick'] = 'Toto' self.check( iq, """ <iq type="set"> <client-join xmlns='urn:xmpp:mix:pam:2' channel='*****@*****.**'> <join xmlns='urn:xmpp:mix:core:1'> <subscribe node='urn:xmpp:mix:nodes:messages'/> <subscribe node='urn:xmpp:mix:nodes:participants'/> <subscribe node='urn:xmpp:mix:nodes:info'/> <nick>Toto</nick> </join> </client-join> </iq> """)