Add the 'connecting' event
[slixmpp.git] / tests / test_stanza_xep_0047.py
blobdffa7561aed43f8b9aa49cc07e8ba252f0dbe90e
1 import unittest
2 from slixmpp.exceptions import XMPPError
3 from slixmpp import Iq
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):
11 def setUp(self):
12 register_stanza_plugin(Iq, Data)
14 def testInvalidBase64MidEqual(self):
15 """
16 Test detecting invalid base64 data with = inside the
17 character data instead of at the end.
18 """
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">
22 ABC=DEFGH
23 </data>
24 </iq>
25 """))
27 errored = False
29 try:
30 data = iq['ibb_data']['data']
31 except XMPPError:
32 errored = True
34 self.assertTrue(errored, "ABC=DEFGH did not raise base64 error")
36 def testInvalidBase64PrefixEqual(self):
37 """
38 Test detecting invalid base64 data with = as a prefix
39 to the character data.
40 """
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">
44 =ABCDEFGH
45 </data>
46 </iq>
47 """))
49 errored = False
51 try:
52 data = iq['ibb_data']['data']
53 except XMPPError:
54 errored = True
56 self.assertTrue(errored, "=ABCDEFGH did not raise base64 error")
58 def testInvalidBase64Alphabet(self):
59 """
60 Test detecting invalid base64 data with characters
61 outside of the base64 alphabet.
62 """
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">
66 ABCD?EFGH
67 </data>
68 </iq>
69 """))
71 errored = False
73 try:
74 data = iq['ibb_data']['data']
75 except XMPPError:
76 errored = True
78 self.assertTrue(errored, "ABCD?EFGH did not raise base64 error")
80 def testConvertData(self):
81 """Test that data is converted to base64"""
82 iq = Iq()
83 iq['type'] = 'set'
84 iq['ibb_data']['seq'] = 0
85 iq['ibb_data']['data'] = 'slixmpp'
87 self.check(iq, """
88 <iq type="set">
89 <data xmlns="http://jabber.org/protocol/ibb" seq="0">c2xlZWt4bXBw</data>
90 </iq>
91 """)
94 suite = unittest.TestLoader().loadTestsFromTestCase(TestIBB)