|
7 | 7 | MissingAlgorithmError, |
8 | 8 | MissingEncryptionError, |
9 | 9 | DecodeError, |
| 10 | + ExceededSizeError, |
10 | 11 | ) |
11 | 12 | from joserfc.util import json_b64encode |
12 | 13 | from tests.base import load_key |
@@ -176,6 +177,25 @@ def test_with_zip_header(self): |
176 | 177 | obj = decrypt_compact(result, private_key) |
177 | 178 | self.assertEqual(obj.plaintext, plaintext) |
178 | 179 |
|
| 180 | + def test_decompress_zip_with_gzip_head(self): |
| 181 | + key = OctKey.import_key({'k': 'pyL42ncDFSYnenl-GiZjRw', 'kty': 'oct'}) |
| 182 | + s = ( |
| 183 | + 'eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4R0NNIiwiemlwIjoiREVGIn0..' |
| 184 | + 'YbDfdYa6p-wAEFul.YK7j0MsH-Dko6ifsEg.wES6-QAOEbErZqXiS0JHRw' |
| 185 | + ) |
| 186 | + result = decrypt_compact(s, key) |
| 187 | + self.assertEqual(result.plaintext, b'hello') |
| 188 | + self.assertEqual(result.headers().get('zip'), 'DEF') |
| 189 | + |
| 190 | + def test_decompress_zip_exceeds_size(self): |
| 191 | + key = OctKey.import_key({'k': 'pyL42ncDFSYnenl-GiZjRw', 'kty': 'oct'}) |
| 192 | + result = encrypt_compact( |
| 193 | + {"alg": "dir", "enc": "A128GCM", "zip": "DEF"}, |
| 194 | + b'h' * 300000, |
| 195 | + key |
| 196 | + ) |
| 197 | + self.assertRaises(ExceededSizeError, decrypt_compact, result, key) |
| 198 | + |
179 | 199 | def test_invalid_compact_data(self): |
180 | 200 | private_key: RSAKey = load_key('rsa-openssl-private.pem') |
181 | 201 | value = b"a.b.c.d.e.f.g" |
|
0 commit comments