def test_post_extract_1(self): mq = MethodQueryCanonicalizer('POST', 'application/x-www-form-urlencoded', len(self.post_data), BytesIO(self.post_data)) assert mq.append_query('http://example.com/') == 'http://example.com/?foo=bar&dir=/baz' assert mq.append_query('http://example.com/?123=ABC') == 'http://example.com/?123=ABC&foo=bar&dir=/baz'
def test_post_extract_1(self): mq = MethodQueryCanonicalizer('POST', 'application/x-www-form-urlencoded', len(self.post_data), BytesIO(self.post_data)) assert mq.append_query('http://example.com/') == 'http://example.com/?foo=bar&dir=/baz' assert mq.append_query('http://example.com/?123=ABC') == 'http://example.com/?123=ABC&foo=bar&dir=/baz'
def test_post_extract_length_invalid_ignore(self): mq = MethodQueryCanonicalizer('POST', 'application/x-www-form-urlencoded', 0, BytesIO(self.post_data)) assert mq.append_query('http://example.com/') == 'http://example.com/' mq = MethodQueryCanonicalizer('POST', 'application/x-www-form-urlencoded', 'abc', BytesIO(self.post_data)) assert mq.append_query('http://example.com/') == 'http://example.com/'
def test_post_extract_length_invalid_ignore(self): mq = MethodQueryCanonicalizer('POST', 'application/x-www-form-urlencoded', 0, BytesIO(self.post_data)) assert mq.append_query('http://example.com/') == 'http://example.com/' mq = MethodQueryCanonicalizer('POST', 'application/x-www-form-urlencoded', 'abc', BytesIO(self.post_data)) assert mq.append_query('http://example.com/') == 'http://example.com/'
def test_post_extract_wrong_method(self): mq = MethodQueryCanonicalizer('PUT', 'application/x-www-form-urlencoded', len(self.post_data), BytesIO(self.post_data)) assert mq.append_query('http://example.com/') == 'http://example.com/'
def test_post_extract_no_boundary_in_multipart_form_mimetype(self): mq = MethodQueryCanonicalizer('POST', 'multipart/form-data', len(self.post_data), BytesIO(self.post_data)) assert mq.append_query( 'http://example.com/' ) == 'http://example.com/?__wb_method=POST&__wb_post_data=Zm9vPWJhciZkaXI9JTJGYmF6'
def test_post_extract_json(self): post_data = b'{"a": "b", "c": {"a": 2}, "d": "e"}' mq = MethodQueryCanonicalizer('POST', 'application/json', len(post_data), BytesIO(post_data)) assert mq.append_query( 'http://example.com/' ) == 'http://example.com/?__wb_method=POST&a=b&a.2_=2&d=e'
def test_post_extract_length_too_short(self): mq = MethodQueryCanonicalizer('POST', 'application/x-www-form-urlencoded', len(self.post_data) - 4, BytesIO(self.post_data)) assert mq.append_query( 'http://example.com/') == 'http://example.com/?foo=bar&dir=%2'
def test_post_extract_non_form_data_2(self): mq = MethodQueryCanonicalizer('POST', 'text/plain', len(self.post_data), BytesIO(self.post_data)) #base64 encoded data assert mq.append_query( 'http://example.com/pathbar?id=123' ) == 'http://example.com/pathbar?id=123&__wb_method=POST&__wb_post_data=Zm9vPWJhciZkaXI9JTJGYmF6'
def test_post_extract_non_form_data_1(self): mq = MethodQueryCanonicalizer('POST', 'application/octet-stream', len(self.post_data), BytesIO(self.post_data)) #base64 encoded data assert mq.append_query( 'http://example.com/' ) == 'http://example.com/?__wb_method=POST&__wb_post_data=Zm9vPWJhciZkaXI9JTJGYmF6'
def test_post_extract_malformed_form_data(self): mq = MethodQueryCanonicalizer('POST', 'application/x-www-form-urlencoded', len(self.binary_post_data), BytesIO(self.binary_post_data)) #base64 encoded data assert mq.append_query( 'http://example.com/' ) == 'http://example.com/?__wb_method=POST&__wb_post_data=gTZsYEygNFAO4HICtYkZAGZQ2w6wAiw='
def test_post_extract_non_form_data_1(self): mq = MethodQueryCanonicalizer('POST', 'application/octet-stream', len(self.post_data), BytesIO(self.post_data)) #base64 encoded data assert mq.append_query('http://example.com/') == 'http://example.com/?__wb_post_data=Zm9vPWJhciZkaXI9JTJGYmF6'
def test_options(self): mq = MethodQueryCanonicalizer('OPTIONS', '', 0, BytesIO()) assert mq.append_query( 'http://example.com/') == 'http://example.com/?__wb_method=OPTIONS'
def test_head(self): mq = MethodQueryCanonicalizer('HEAD', '', 0, BytesIO()) assert mq.append_query('http://example.com/') == 'http://example.com/?__pywb_method=head'
def test_options(self): mq = MethodQueryCanonicalizer('OPTIONS', '', 0, BytesIO()) assert mq.append_query('http://example.com/') == 'http://example.com/?__pywb_method=options'
def test_post_extract_length_too_short(self): mq = MethodQueryCanonicalizer('POST', 'application/x-www-form-urlencoded', len(self.post_data) - 4, BytesIO(self.post_data)) assert mq.append_query('http://example.com/') == 'http://example.com/?foo=bar&dir=%2'
def test_post_extract_non_form_data_2(self): mq = MethodQueryCanonicalizer('POST', 'text/plain', len(self.post_data), BytesIO(self.post_data)) #base64 encoded data assert mq.append_query('http://example.com/pathbar?id=123') == 'http://example.com/pathbar?id=123&__wb_post_data=Zm9vPWJhciZkaXI9JTJGYmF6'
def test_head(self): mq = MethodQueryCanonicalizer('HEAD', '', 0, BytesIO()) assert mq.append_query( 'http://example.com/') == 'http://example.com/?__wb_method=HEAD'
def test_post_extract_wrong_method(self): mq = MethodQueryCanonicalizer('PUT', 'application/x-www-form-urlencoded', len(self.post_data), BytesIO(self.post_data)) assert mq.append_query('http://example.com/') == 'http://example.com/'