mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-24 03:00:15 +00:00
Fix data stanza based on test results.
This commit is contained in:
parent
bd52a5e6c1
commit
4665c5cf1a
2 changed files with 82 additions and 2 deletions
|
@ -46,14 +46,17 @@ class Data(ElementBase):
|
|||
self._set_attr('seq', str(value))
|
||||
|
||||
def get_data(self):
|
||||
b64_data = self._get_sub_text('data', '')
|
||||
b64_data = self.xml.text
|
||||
if VALID_B64.match(b64_data).group() == b64_data:
|
||||
return from_b64(b64_data)
|
||||
else:
|
||||
raise XMPPError('not-acceptable')
|
||||
|
||||
def set_data(self, value):
|
||||
self._set_sub_text('data', to_b64(value))
|
||||
self.xml.text = to_64(value)
|
||||
|
||||
def del_data(self):
|
||||
self.xml.text = ''
|
||||
|
||||
|
||||
class Close(ElementBase):
|
||||
|
|
77
tests/test_stanza_xep_0047.py
Normal file
77
tests/test_stanza_xep_0047.py
Normal file
|
@ -0,0 +1,77 @@
|
|||
from sleekxmpp.test import *
|
||||
from sleekxmpp.plugins.xep_0047 import Data
|
||||
|
||||
|
||||
class TestIBB(SleekTest):
|
||||
|
||||
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")
|
||||
|
||||
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(TestIBB)
|
Loading…
Reference in a new issue