diff options
author | R. David Murray <rdmurray@bitdance.com> | 2010-11-11 20:09:20 (GMT) |
---|---|---|
committer | R. David Murray <rdmurray@bitdance.com> | 2010-11-11 20:09:20 (GMT) |
commit | 6495136e4018b626c40500bbd564fdfda9825587 (patch) | |
tree | 3d49ba6a59663e6cff25a7f5f16942b7c5c8a3b0 /Lib/test/test_base64.py | |
parent | 49afa380fd86dfa07e68e7838adcdad38d3d8ba6 (diff) | |
download | cpython-6495136e4018b626c40500bbd564fdfda9825587.zip cpython-6495136e4018b626c40500bbd564fdfda9825587.tar.gz cpython-6495136e4018b626c40500bbd564fdfda9825587.tar.bz2 |
#1466065: add validate option to base64.b64decode
Patch by Neil Tallim. This provides a mechanism for module
users to achieve RFC 3548 compliance in the cases where ignoring
non-base64-alphabet input characters is *not* mandated by the RFC that
references RFC 3548.
Diffstat (limited to 'Lib/test/test_base64.py')
-rw-r--r-- | Lib/test/test_base64.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/Lib/test/test_base64.py b/Lib/test/test_base64.py index 49edf39..228a0fb 100644 --- a/Lib/test/test_base64.py +++ b/Lib/test/test_base64.py @@ -138,9 +138,25 @@ class BaseXYTestCase(unittest.TestCase): eq(base64.urlsafe_b64decode(b'01a-b_cd'), b'\xd3V\xbeo\xf7\x1d') self.assertRaises(TypeError, base64.urlsafe_b64decode, "") - def test_b64decode_error(self): + def test_b64decode_padding_error(self): self.assertRaises(binascii.Error, base64.b64decode, b'abc') + def test_b64decode_invalid_chars(self): + # issue 1466065: Test some invalid characters. + tests = ((b'%3d==', b'\xdd'), + (b'$3d==', b'\xdd'), + (b'[==', b''), + (b'YW]3=', b'am'), + (b'3{d==', b'\xdd'), + (b'3d}==', b'\xdd'), + (b'@@', b''), + (b'!', b''), + (b'YWJj\nYWI=', b'abcab')) + for bstr, res in tests: + self.assertEquals(base64.b64decode(bstr), res) + with self.assertRaises(binascii.Error): + base64.b64decode(bstr, validate=True) + def test_b32encode(self): eq = self.assertEqual eq(base64.b32encode(b''), b'') |