2 from slixmpp
.exceptions
import XMPPError
4 from slixmpp
.test
import SlixTest
5 from slixmpp
.plugins
.xep_0047
import Data
6 from slixmpp
.xmlstream
import register_stanza_plugin
, ET
9 class TestIBB(SlixTest
):
12 register_stanza_plugin(Iq
, Data
)
14 def testInvalidBase64MidEqual(self
):
16 Test detecting invalid base64 data with = inside the
17 character data instead of at the end.
19 iq
= Iq(xml
=ET
.fromstring("""
20 <iq type="set" id="0" to="tester@localhost">
21 <data xmlns="http://jabber.org/protocol/ibb" seq="0">
30 data
= iq
['ibb_data']['data']
34 self
.assertTrue(errored
, "ABC=DEFGH did not raise base64 error")
36 def testInvalidBase64PrefixEqual(self
):
38 Test detecting invalid base64 data with = as a prefix
39 to the character data.
41 iq
= Iq(xml
=ET
.fromstring("""
42 <iq type="set" id="0" to="tester@localhost">
43 <data xmlns="http://jabber.org/protocol/ibb" seq="0">
52 data
= iq
['ibb_data']['data']
56 self
.assertTrue(errored
, "=ABCDEFGH did not raise base64 error")
58 def testInvalidBase64Alphabet(self
):
60 Test detecting invalid base64 data with characters
61 outside of the base64 alphabet.
63 iq
= Iq(xml
=ET
.fromstring("""
64 <iq type="set" id="0" to="tester@localhost">
65 <data xmlns="http://jabber.org/protocol/ibb" seq="0">
74 data
= iq
['ibb_data']['data']
78 self
.assertTrue(errored
, "ABCD?EFGH did not raise base64 error")
80 def testConvertData(self
):
81 """Test that data is converted to base64"""
84 iq
['ibb_data']['seq'] = 0
85 iq
['ibb_data']['data'] = 'slixmpp'
89 <data xmlns="http://jabber.org/protocol/ibb" seq="0">c2xlZWt4bXBw</data>
94 suite
= unittest
.TestLoader().loadTestsFromTestCase(TestIBB
)