forked from redcanaryco/openapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
executable file
·121 lines (95 loc) · 4.43 KB
/
Copy pathtest.py
File metadata and controls
executable file
·121 lines (95 loc) · 4.43 KB
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
#!/usr/bin/env python
import logging
import unittest
import redcanary
class Test(unittest.TestCase):
def setUp(self):
logging.basicConfig(level=logging.DEBUG)
# To hardcode in the info
# self.client = redcanary.RedCanaryClient('demo', 'xxxxxxxxx')
# Or use the .env
self.client = redcanary.RedCanaryClient()
def test_detections(self):
print "DETECTIONS"
for i, detection in enumerate(self.client.detections):
print i, detection.headline
print ' TIMELINE'
for entry in detection.timeline:
print entry
print ' ENDPOINT'
print ' %s' % detection.endpoint.hostname
# force the load of the full object
print ' %s' % detection.endpoint.operating_system
if len(detection.response_plans) > 0:
print ' RESPONSE PLAN'
print ' %s' % detection.response_plans[0].state
# force the load of the full object
print ' %s' % detection.response_plans[0].creator
if detection.num_indicators > 0:
print ' INDICATORS'
i = 0
for i, indicator in enumerate(detection.indicators):
print ' %d %s' % (i, indicator.type)
self.assertTrue(i == detection.num_indicators - 1)
print ''
def test_detections_since(self):
print "DETECTIONS SINCE"
second_newest = self.client.detections.next()
num_since_second_newest = len(self.client.detections(since=second_newest.date))
self.assertTrue(num_since_second_newest == 1)
self.assertTrue(len(self.client.detections(since='1970-01-01')) == len(self.client.detections))
def test_indicators(self):
print "INDICATORS"
for i, indicator in enumerate(self.client.indicators):
print indicator
print i, indicator.type
if len(indicator.detections) > 0:
# force the load of the full object
print ' %s' % indicator.detections[0].summary
print ''
def test_limit(self):
print "LIMIT"
for type in ['indicators', 'detections', 'endpoints', 'response_plans']:
collection = getattr(self.client, type)
print 'checking with limit'
self.assertTrue(len(list(collection(limit=2))) == 2)
self.assertTrue(len(collection(limit=2)) == 2)
print 'checking with no limit'
self.assertTrue(len(list(collection(limit=None))) > 2)
self.assertTrue(len(collection(limit=None)) > 2)
print 'checking normal' # can't be tested above because getattr doesn't get @property
self.assertTrue(len(list(self.client.indicators)) > 2)
self.assertTrue(len(self.client.indicators) > 2)
self.assertTrue(len(list(self.client.detections)) > 2)
self.assertTrue(len(self.client.detections) > 2)
self.assertTrue(len(list(self.client.endpoints)) > 2)
self.assertTrue(len(self.client.endpoints) > 2)
self.assertTrue(len(list(self.client.response_plans)) > 2)
self.assertTrue(len(self.client.response_plans) > 2)
def test_response_plans(self):
print "RESPONSE_PLANS"
for i, response_plan in enumerate(self.client.response_plans):
print "plan %d for detection [%s] on [%s]" % \
(i, response_plan.detection.headline, response_plan.endpoint.hostname)
print ' %s' % response_plan.endpoint.hostname
# force the load of the full object
print ' %s' % response_plan.endpoint.operating_system
print ' %s' % response_plan.detection.headline
# force the load of the full object
print ' %s' % response_plan.detection.summary
print ''
def test_endpoints(self):
print "ENDPOINTS"
for i, endpoint in enumerate(self.client.endpoints):
print i, endpoint.hostname
print ' ', endpoint.ip_addresses
print ' ', endpoint.sensor
print ' ', 'detections (snippets):'
print ' ', endpoint.detections
# force the load of the full object
if len(endpoint.detections) > 0:
print ' ', 'first detection - full object:'
print ' ', endpoint.detections[0].summary
print
if __name__ == '__main__':
unittest.main()