-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_continue.py
73 lines (62 loc) · 2.97 KB
/
test_continue.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
import json
import requests
import unittest
import time
#url = "http://localhost:5000/url"
url = "http://10.0.0.3/~michal/con/con.php"
class TestContinuation(unittest.TestCase):
def test_incorrect_post(self):
r = requests.post(url)
self.assertEqual(r.text, "Incorrect data")
self.assertEqual(r.status_code, 400)
def test_correct_post(self):
payload = {'client': 'data'}
r = requests.post(url, data=json.dumps(payload))
self.assertEqual(r.status_code, 200)
def test_incorrect_get(self):
r = requests.get(url + "?text=bla")
self.assertEqual(r.text, "Incorrect key")
self.assertEqual(r.status_code, 403)
def test_correct_get(self):
payload = {'client': 'key=value', 'url':'/'}
r = requests.post(url, data=json.dumps(payload))
r = requests.get(url + json.loads(r.text), allow_redirects=False)
self.assertEqual(r.status_code, 302)
def test_long_url(self):
redir_url = 'http://'+'long.url/'*1000
payload = {'client': 'key=value', 'url': redir_url}
r = requests.post(url, data=json.dumps(payload))
r = requests.get(url + json.loads(r.text), allow_redirects=False)
self.assertEqual(r.headers['location'], redir_url)
self.assertEqual(r.status_code, 302)
def test_incorrect_key_get(self):
payload = {'client': 'key=value', 'url':'/'}
r = requests.post(url, data=json.dumps(payload))
postfix = json.loads(r.text)[1:]
args = postfix.split('&')
new_args = [ 'text=badmsg' if s.startswith('text=') else s \
for s in args]
new_postfix = '&'.join(new_args)
r = requests.get(url + '?' + new_postfix, allow_redirects=False)
self.assertEqual(r.status_code, 403)
self.assertEqual(r.text, 'Incorrect key')
def test_correct_cookies(self):
payload = {'client': 'key=value', 'url':'/'}
header = {'cookie': 'flavour=chocolate; session=eyJ1c2VybmFtZSI6Im1pcmphbSJ9.BnJ10A.VSuoI0CLPpDDbundvRuaP2v-9OM'}
r = requests.post(url, data=json.dumps(payload), headers=header)
r = requests.get(url+ json.loads(r.text), allow_redirects=False)
self.assertEqual(r.status_code, 302)
cookies = sorted([(cookie.name, cookie.value) for cookie in r.cookies])
self.assertEqual(cookies, [('flavour', 'chocolate'), ('key', 'value'), ('session', 'eyJ1c2VybmFtZSI6Im1pcmphbSJ9.BnJ10A.VSuoI0CLPpDDbundvRuaP2v-9OM')])
def test_delete_key(self):
payload = {'client': 'key=value', 'url': '/some_url'}
r = requests.post(url, data=json.dumps(payload))
suffix = json.loads(r.text)
self.assertEqual(r.status_code, 200)
r = requests.get(url + suffix, allow_redirects=False)
self.assertEqual(r.status_code, 302)
r = requests.get(url + suffix, allow_redirects=False)
self.assertEqual(r.status_code, 403)
self.assertEqual(r.text, 'Incorrect key')
if __name__ == '__main__':
unittest.main()