-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_external.py
82 lines (63 loc) · 2.39 KB
/
test_external.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# -*- coding: utf-8 -*-
import pytest
from urllib.parse import quote, quote_plus, unquote_plus
from headers import Header
from settings import Sets
sets = Sets()
head = Header(sets.parent_folder, sets.addr)
@pytest.mark.parametrize('req', [('get=love'),
('get=777&post=sure'),
('get=777&post=sure or not'),
('get=777&post=sure+or+not'),
('slash=last/laugh'),
('percent=100%20percent')])
def test_php_get_req(req):
request = quote(req, safe='/=&')
if '&' in req:
main_splits = req.split('&')
else:
main_splits = [req]
string = 'array(' + str(len(main_splits)) + ')' + ' {\n'
for requ in main_splits:
splits = requ.split('=')
string += ' ["' + splits[0] + '"]=>\n string(' + \
str(len(splits[1])) + ') "' + splits[1] + '"\n'
string += '}\n'
ret_value = string
print('ret: ', ret_value)
req_string = 'GET /_tests/phpGetReq.php?' + request + ' HTTP/1.1'
head.getRequest(bytes(req_string, 'utf-8'))
resp = head.computeResponse()
str_resp = str(resp, 'UTF-8')
splitted = str_resp.split('\r\n\r\n')
body_str = splitted[-1]
print('splits: ', str_resp)
assert body_str == ret_value
@pytest.mark.parametrize('req', [('ordinarytext'),
('ordinary text'),
('4'),
('~`!@#$%^&*()_-+=')])
def test_php_post_req(req):
parsed = quote_plus(req)
request = req = 'test_string=' + parsed
if '&' in req:
main_splits = req.split('&')
else:
main_splits = [req]
string = 'array(' + str(len(main_splits)) + ')' + ' {\n'
for requ in main_splits:
splits = requ.split('=')
splits[1] = unquote_plus(splits[1])
string += ' ["' + splits[0] + '"]=>\n string(' + \
str(len(splits[1])) + ') "' + splits[1] + '"\n'
string += '}\n'
ret_value = string
print('ret: ', ret_value)
req_string = 'POST /_tests/phpPostReq.php HTTP/1.1\r\n\r\n' + request
head.getRequest(bytes(req_string, 'utf-8'))
resp = head.computeResponse()
str_resp = str(resp, 'UTF-8')
splitted = str_resp.split('\r\n\r\n')
body_str = splitted[-1]
print('splits: ', body_str)
assert body_str == ret_value