2013-07-26 11:02:26 +00:00
|
|
|
import unittest
|
2014-07-17 12:19:04 +00:00
|
|
|
from slixmpp.exceptions import XMPPError
|
|
|
|
from slixmpp import Iq
|
|
|
|
from slixmpp.test import SlixTest
|
|
|
|
from slixmpp.plugins.xep_0047 import Data
|
|
|
|
from slixmpp.xmlstream import register_stanza_plugin, ET
|
2012-02-02 18:19:50 +00:00
|
|
|
|
|
|
|
|
2014-07-17 12:19:04 +00:00
|
|
|
class TestIBB(SlixTest):
|
2012-02-02 18:19:50 +00:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
register_stanza_plugin(Iq, Data)
|
|
|
|
|
|
|
|
def testInvalidBase64MidEqual(self):
|
|
|
|
"""
|
|
|
|
Test detecting invalid base64 data with = inside the
|
|
|
|
character data instead of at the end.
|
|
|
|
"""
|
|
|
|
iq = Iq(xml=ET.fromstring("""
|
|
|
|
<iq type="set" id="0" to="tester@localhost">
|
|
|
|
<data xmlns="http://jabber.org/protocol/ibb" seq="0">
|
|
|
|
ABC=DEFGH
|
|
|
|
</data>
|
|
|
|
</iq>
|
|
|
|
"""))
|
|
|
|
|
|
|
|
errored = False
|
|
|
|
|
|
|
|
try:
|
|
|
|
data = iq['ibb_data']['data']
|
|
|
|
except XMPPError:
|
|
|
|
errored = True
|
|
|
|
|
|
|
|
self.assertTrue(errored, "ABC=DEFGH did not raise base64 error")
|
|
|
|
|
|
|
|
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")
|
|
|
|
|
2012-02-03 15:03:46 +00:00
|
|
|
def testConvertData(self):
|
|
|
|
"""Test that data is converted to base64"""
|
|
|
|
iq = Iq()
|
|
|
|
iq['type'] = 'set'
|
|
|
|
iq['ibb_data']['seq'] = 0
|
2014-07-17 12:19:04 +00:00
|
|
|
iq['ibb_data']['data'] = 'slixmpp'
|
2012-02-03 15:03:46 +00:00
|
|
|
|
|
|
|
self.check(iq, """
|
|
|
|
<iq type="set">
|
2015-02-12 11:23:47 +00:00
|
|
|
<data xmlns="http://jabber.org/protocol/ibb" seq="0">c2xpeG1wcA==</data>
|
2012-02-03 15:03:46 +00:00
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
2012-02-02 18:19:50 +00:00
|
|
|
|
|
|
|
suite = unittest.TestLoader().loadTestsFromTestCase(TestIBB)
|