-
Notifications
You must be signed in to change notification settings - Fork 6
/
test.py
127 lines (97 loc) · 4.11 KB
/
test.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import unittest
import urllib2
import urllib
import requests
import json
BASE_URL = 'http://localhost:8899/ida/api/v1.0'
class HttpTestCase(unittest.TestCase):
def setUp(self):
self.url = BASE_URL + '/cursor'
def _check_json_codes(self, r):
self.assertEqual(r.headers['content-type'], 'application/json')
response = r.json()
self.assertTrue('code' in response, "missing code from response")
self.assertEqual(response['code'], 200)
self.assertTrue('msg' in response, "missing msg from response")
def test_get(self):
r = requests.get(self.url)
self.assertEqual(r.status_code, 200, "bad status code on generic GET")
self._check_json_codes(r)
def test_post(self):
r = requests.post(self.url)
self.assertEqual(r.status_code, 200, "bad status code on generic POST")
self._check_json_codes(r)
def test_get_invalid_url(self):
r = requests.get(BASE_URL + '/bad_api')
self.assertEqual(r.status_code, 404, "failed to detect invalid api URL")
def test_post_invalid_url(self):
r = requests.post(BASE_URL + '/bad_api')
self.assertEqual(r.status_code, 404, "failed to detect invalid api URL")
def test_post_bad_content_type(self):
r = requests.post(self.url, data={'ea' : '0x8888'})
self.assertEqual(r.status_code, 400, "failed to detect bad content-type")
def test_multiple_instance_of_param(self):
r = requests.get(self.url + '?ea=0x93232&ea=0x8888')
self.assertEqual(r.status_code, 400,
"failed to multiple instances of 1 param")
def test_post_json_invalid(self):
headers = {'content-type': 'application/json'}
r = requests.post(self.url,
data=json.dumps({'ea' : '0x8888'})+'foo}}}{{',
headers={'content-type': 'application/json'})
self.assertEqual(r.status_code, 400, "failed to detect invalid json POST")
def test_post_json(self):
r = requests.post(self.url, data=json.dumps({'ea' : '0x8888'}))
self.assertEqual(r.status_code, 200, "failed to POST json")
def _verify_jsonp(self, r):
self.assertEqual(r.status_code, 200)
self.assertEqual(r.headers['content-type'], 'application/javascript')
self.assertTrue(r.text.startswith('foobar('))
self.assertTrue(r.text.endswith(');'))
def test_post_jsonp_response(self):
r = requests.post(self.url, params={'callback': 'foobar'})
self._verify_jsonp(r)
def test_get_jsonp_response(self):
r = requests.get(self.url, params={'callback': 'foobar'})
self._verify_jsonp(r)
class CursorTestCase(unittest.TestCase):
def setUp(self):
self.url = BASE_URL + '/cursor'
def _check_json_codes(self, r):
self.assertEqual(r.headers['content-type'], 'application/json')
response = r.json()
self.assertTrue('code' in response, "missing code from response")
self.assertEqual(response['code'], 200)
self.assertTrue('msg' in response, "missing msg from response")
def test_get_cursor(self):
r = requests.get(self.url)
self._check_json_codes(r)
def test_set_cursor(self):
r = requests.get(self.url, params={'ea': '0x67a82'})
response = r.json()
self.assertEqual(response['code'], 200)
def test_set_invalid_cursor(self):
r = requests.get(self.url, params={'ea': 'hhhhhh'})
response = r.json()
self.assertEqual(response['code'], 400)
class SegmentsTestCase(unittest.TestCase):
def setUp(self):
self.url = BASE_URL + '/segments'
def test_get_all_segments(self):
self.fail()
def test_get_segment_by_address(self):
self.fail()
class NamesTestCase(unittest.TestCase):
def setUp(self):
self.url = BASE_URL + '/names'
def test_get_names(self):
self.fail()
class ColorTestCase(unittest.TestCase):
def setUp(self):
self.url = BASE_URL + '/color'
def test_get_address_color(self):
self.fail()
def test_set_address_color(self):
self.fail()
if __name__ == '__main__':
unittest.main()