예제 #1
0
    def test_encode_file_null(self):
        _files = [('file', NamedStringIO('\0hello world', name='test.txt'))]

        _, encoded = multipart_encode((), _files, boundary='fakeboundary')

        EXPECTED = '--fakeboundary\r\nContent-Disposition: form-data; name="file";'\
                   ' filename="test.txt"\r\nContent-Type: text/plain\r\n\r\n\x00'\
                   'hello world\r\n--fakeboundary--\r\n\r\n'
        self.assertEqual(EXPECTED, encoded)
예제 #2
0
    def test_encode_file_null(self):
        _files = [('file', NamedStringIO('\0hello world', name='test.txt'))]

        _, encoded = multipart_encode((), _files, boundary='fakeboundary')

        EXPECTED = '--fakeboundary\r\nContent-Disposition: form-data; name="file";'\
                   ' filename="test.txt"\r\nContent-Type: text/plain\r\n\r\n\x00'\
                   'hello world\r\n--fakeboundary--\r\n\r\n'
        self.assertEqual(EXPECTED, encoded)
예제 #3
0
    def test_encode_vars_files(self):
        _vars = [('a', 'b')]
        _files = [('file', NamedStringIO('file content', name='test.txt'))]

        _, encoded = multipart_encode(_vars, _files, boundary='fakeboundary')

        EXPECTED = '--fakeboundary\r\nContent-Disposition: form-data; name="a"'\
                   '\r\n\r\nb\r\n--fakeboundary\r\nContent-Disposition: form-data;'\
                   ' name="file"; filename="test.txt"\r\nContent-Type: text/plain'\
                   '\r\n\r\nfile content\r\n--fakeboundary--\r\n\r\n'
        self.assertEqual(EXPECTED, encoded)
예제 #4
0
    def test_encode_vars_files(self):
        _vars = [('a', 'b')]
        _files = [('file', NamedStringIO('file content', name='test.txt'))]

        _, encoded = multipart_encode(_vars, _files, boundary='fakeboundary')

        EXPECTED = '--fakeboundary\r\nContent-Disposition: form-data; name="a"'\
                   '\r\n\r\nb\r\n--fakeboundary\r\nContent-Disposition: form-data;'\
                   ' name="file"; filename="test.txt"\r\nContent-Type: text/plain'\
                   '\r\n\r\nfile content\r\n--fakeboundary--\r\n\r\n'
        self.assertEqual(EXPECTED, encoded)
예제 #5
0
    def test_multipart_post(self):
        boundary, post_data = multipart_encode([("a", "bcd")], [])

        headers = Headers(
            [("content-length", str(len(post_data))), ("content-type", "multipart/form-data; boundary=%s" % boundary)]
        )

        fr = create_fuzzable_request_from_parts(self.url, add_headers=headers, post_data=post_data, method="POST")

        self.assertEqual(fr.get_url(), self.url)
        self.assertEqual(fr.get_headers(), headers)
        self.assertTrue("multipart/form-data" in fr.get_headers()["content-type"])
        self.assertEqual(fr.get_method(), "POST")
        self.assertEqual(fr.get_dc(), {"a": ["bcd"]})
        self.assertIsInstance(fr, HTTPPostDataRequest)
예제 #6
0
    def test_invalid_multipart_post(self):
        _, post_data = multipart_encode([("a", "bcd")], [])

        # It is invalid because there is a missing boundary parameter in the
        # content-type header
        headers = Headers([("content-length", str(len(post_data))), ("content-type", "multipart/form-data")])

        fr = create_fuzzable_request_from_parts(self.url, add_headers=headers, post_data=post_data, method="POST")

        self.assertEqual(fr.get_url(), self.url)
        self.assertEqual(fr.get_headers(), headers)
        self.assertEqual(fr.get_method(), "POST")

        # And this is how it affects the result:
        self.assertEqual(fr.get_data(), "")
        self.assertEqual(fr.get_dc(), {})

        self.assertIsInstance(fr, HTTPPostDataRequest)
예제 #7
0
    def test_multipart_post(self):
        boundary, post_data = multipart_encode([
            ('a', 'bcd'),
        ], [])

        headers = Headers([('content-length', str(len(post_data))),
                           ('content-type',
                            'multipart/form-data; boundary=%s' % boundary)])

        fr = create_fuzzable_request_from_parts(self.url,
                                                add_headers=headers,
                                                post_data=post_data,
                                                method='POST')

        self.assertEqual(fr.get_url(), self.url)
        self.assertEqual(fr.get_headers(), headers)
        self.assertTrue(
            'multipart/form-data' in fr.get_headers()['content-type'])
        self.assertEqual(fr.get_method(), 'POST')
        self.assertEqual(fr.get_dc(), {'a': [
            'bcd',
        ]})
        self.assertIsInstance(fr, HTTPPostDataRequest)
예제 #8
0
    def test_invalid_multipart_post(self):
        _, post_data = multipart_encode([
            ('a', 'bcd'),
        ], [])

        # It is invalid because there is a missing boundary parameter in the
        # content-type header
        headers = Headers([('content-length', str(len(post_data))),
                           ('content-type', 'multipart/form-data')])

        fr = create_fuzzable_request_from_parts(self.url,
                                                add_headers=headers,
                                                post_data=post_data,
                                                method='POST')

        self.assertEqual(fr.get_url(), self.url)
        self.assertEqual(fr.get_headers(), headers)
        self.assertEqual(fr.get_method(), 'POST')

        # And this is how it affects the result:
        self.assertEqual(fr.get_data(), '')
        self.assertEqual(fr.get_dc(), {})

        self.assertIsInstance(fr, HTTPPostDataRequest)
예제 #9
0
 def test_encode_vars(self):
     _, encoded = multipart_encode([('a', 'b')], {},
                                   boundary='fakeboundary')
     EXPECTED = '--fakeboundary\r\nContent-Disposition: form-data; name="a"'\
                '\r\n\r\nb\r\n--fakeboundary--\r\n\r\n'
     self.assertEqual(EXPECTED, encoded)
예제 #10
0
 def test_encode_vars(self):
     _, encoded = multipart_encode(
         [('a', 'b')], {}, boundary='fakeboundary')
     EXPECTED = '--fakeboundary\r\nContent-Disposition: form-data; name="a"'\
                '\r\n\r\nb\r\n--fakeboundary--\r\n\r\n'
     self.assertEqual(EXPECTED, encoded)