From 39dacfcb39f259f71a6006caf9a3d4b5e460c988 Mon Sep 17 00:00:00 2001 From: s3lph Date: Tue, 28 Aug 2018 21:20:14 +0200 Subject: [PATCH] Full coverage in util. --- matemat/webserver/test/test_parse_request.py | 26 ++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/matemat/webserver/test/test_parse_request.py b/matemat/webserver/test/test_parse_request.py index d144ac1..8f3d35b 100644 --- a/matemat/webserver/test/test_parse_request.py +++ b/matemat/webserver/test/test_parse_request.py @@ -204,6 +204,32 @@ class TestParseRequest(unittest.TestCase): self.assertEqual(b'1337', args['bar'].get_bytes()) self.assertEqual('Hello, World!', args['baz'].get_str()) + def test_parse_post_multipart_names(self): + """ + Test that multipart names work both with and without quotation marks + """ + path, args = parse_args('/', + postbody=b'--testBoundary1337\r\n' + b'Content-Disposition: form-data; name="foo"\r\n' + b'Content-Type: text/plain\r\n\r\n' + b'42\r\n' + b'--testBoundary1337\r\n' + b'Content-Disposition: form-data; name=bar\r\n' + b'Content-Type: text/plain\r\n\r\n' + b'Hello, World!\r\n' + b'--testBoundary1337--\r\n', + enctype='multipart/form-data; boundary=testBoundary1337') + self.assertEqual('/', path) + self.assertEqual(2, len(args)) + self.assertIn('foo', args) + self.assertIn('bar', args) + self.assertTrue(args['foo'].is_scalar) + self.assertTrue(args['bar'].is_scalar) + self.assertEqual('text/plain', args['foo'].get_content_type()) + self.assertEqual('text/plain', args['bar'].get_content_type()) + self.assertEqual('42', args['foo'].get_str()) + self.assertEqual('Hello, World!', args['bar'].get_str()) + def test_parse_post_multipart_zero_arg(self): """ Test that a multipart POST request with an empty argument is parsed correctly.