/
test_actions.py
143 lines (115 loc) · 5.6 KB
/
test_actions.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import pytest
import unittest
from mock import patch
from conf import fake_request
from passivetotal.libs.actions import ActionsClient
from passivetotal.common.exceptions import MISSING_FIELD
from passivetotal.common.exceptions import INVALID_VALUE_TYPE
class ActionsTestCase(unittest.TestCase):
"""Test case for action methods."""
def setup_class(self):
self.patch_get = patch('passivetotal.api.Client._get', fake_request)
self.patch_set = patch('passivetotal.api.Client._send_data', fake_request)
self.patch_get.start()
self.patch_set.start()
self.client = ActionsClient('--No-User--', '--No-Key--')
def teardown_class(self):
self.patch_get.stop()
self.patch_set.stop()
def test_dynamic_dns(self):
"""Test various actions for dynamic DNS."""
payload = {'query': 'passivetotal.org'}
response = self.client.get_dynamic_dns_status(**payload)
assert not (response['dynamicDns'])
payload = {'query': 'passivetotal.org', 'status': 'false'}
response = self.client.set_dynamic_dns_status(**payload)
assert not (response['dynamicDns'])
with pytest.raises(MISSING_FIELD) as excinfo:
def missing_field():
payload = {'query': 'passivetotal.org', 'no-status': 'false'}
self.client.set_dynamic_dns_status(**payload)
missing_field()
assert 'field is required' in str(excinfo.value)
def test_sinkhole(self):
"""Test various actions for sinkhole."""
payload = {'query': 'passivetotal.org'}
response = self.client.get_sinkhole_status(**payload)
assert not (response['sinkhole'])
payload = {'query': 'passivetotal.org', 'status': 'false'}
response = self.client.set_sinkhole_status(**payload)
assert not (response['sinkhole'])
with pytest.raises(MISSING_FIELD) as excinfo:
def missing_field():
payload = {'query': 'passivetotal.org', 'no-status': 'false'}
self.client.set_sinkhole_status(**payload)
missing_field()
assert 'field is required' in str(excinfo.value)
def test_ever_compromised(self):
"""Test various actions for ever compromised."""
payload = {'query': 'passivetotal.org'}
response = self.client.get_ever_compromised_status(**payload)
assert not (response['everCompromised'])
payload = {'query': 'passivetotal.org', 'status': 'false'}
response = self.client.set_ever_compromised_status(**payload)
assert not (response['everCompromised'])
with pytest.raises(MISSING_FIELD) as excinfo:
def missing_field():
payload = {'query': 'passivetotal.org', 'no-status': 'false'}
self.client.set_ever_compromised_status(**payload)
missing_field()
assert 'field is required' in str(excinfo.value)
def test_monitor(self):
"""Test various actions for monitors."""
payload = {'query': 'passivetotal.org'}
response = self.client.get_monitor_status(**payload)
assert not (response['monitor'])
payload = {'query': 'passivetotal.org', 'status': 'false'}
response = self.client.set_monitor_status(**payload)
assert not (response['monitor'])
with pytest.raises(MISSING_FIELD) as excinfo:
def missing_field():
payload = {'query': 'passivetotal.org', 'no-status': 'false'}
self.client.set_monitor_status(**payload)
missing_field()
assert 'field is required' in str(excinfo.value)
def test_classification(self):
"""Test various actions for classifications."""
payload = {'query': 'passivetotal.org'}
response = self.client.get_classification_status(**payload)
assert (response['classification']) == 'non-malicious'
payload = {'query': 'passivetotal.org',
'classification': 'non-malicious'}
response = self.client.set_classification_status(**payload)
assert (response['classification']) == 'non-malicious'
with pytest.raises(MISSING_FIELD) as excinfo:
def missing_field():
payload = {'query': 'passivetotal.org',
'no-classification': 'unknown'}
self.client.set_classification_status(**payload)
missing_field()
assert 'field is required' in str(excinfo.value)
with pytest.raises(INVALID_VALUE_TYPE) as excinfo:
def invalid_field():
payload = {'query': 'passivetotal.org', 'classification': '_'}
self.client.set_classification_status(**payload)
invalid_field()
assert 'must be one of the following' in str(excinfo.value)
def test_tags(self):
"""Test various actions for tags."""
payload = {'query': 'passivetotal.org'}
response = self.client.get_tags(**payload)
assert (response['tags'])
assert ('security' in response['tags'])
payload = {'query': 'passivetotal.org', 'tags': 'vendor,security'}
response = self.client.add_tags(**payload)
assert (response['tags'])
response = self.client.remove_tags(**payload)
assert (response['tags'])
response = self.client.set_tags(**payload)
assert (response['tags'])
with pytest.raises(INVALID_VALUE_TYPE) as excinfo:
def invalid_field():
payload = {'query': 'passivetotal.org', 'tags': {}}
self.client.add_tags(**payload)
invalid_field()
assert 'must be a list' in str(excinfo.value)