forked from midnightslacker/SigSciApiPy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_SigSci.py
60 lines (45 loc) · 1.8 KB
/
test_SigSci.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
from __future__ import print_function
from builtins import str
import unittest
import mock
from SigSciApiPy.SigSci import SigSciAPI
def mocked_requests_get(*args, **kwargs):
class MockResponse(object):
def __init__(self, json_data, status_code):
self.json_data = json_data
self.status_code = status_code
# TODO: add an actual "next" URI to make sure looping works etc.
self.text = '{"next": {"uri": ""}, "data": {"id": "testid", "serverHostname": "testhost"}}'
def json(self):
return self.json_data
return MockResponse({"key1": "value1"}, 200)
def mocked_requests_post(*args, **kwargs):
class MockResponse(object):
def __init__(self, json_data, status_code):
self.status_code = status_code
self.json_data = json_data
self.cookies = {}
def json(self):
return self.json_data
return MockResponse({"token": "testtoken"}, 200)
class TestSigSciAPI(unittest.TestCase):
@mock.patch("requests.get", side_effect=mocked_requests_get)
@mock.patch("requests.post", side_effect=mocked_requests_post)
def test_fetch(self, mock_get, mock_post):
# Assert requests.get calls
sigsci = SigSciAPI()
sigsci.email = "testemail"
sigsci.password = "testpass"
sigsci.corp = "testcorp"
sigsci.site = "testsite"
sigsci.authenticate()
sigsci.get_feed_requests()
sigsci.get_list_events()
def test_build_search_query(self):
sigsci = SigSciAPI()
sigsci.tags = ['SQLI', 'XSS']
sigsci.ip = '127.0.0.1'
sigsci.build_search_query()
self.assertEqual(str(sigsci.query).rstrip(), 'from:-1h ip:127.0.0.1 tag:SQLI tag:XSS sort:time-asc')
if __name__ == "__main__":
unittest.main()