mirror of
https://github.com/empayre/OTX-Python-SDK.git
synced 2024-11-06 01:45:25 +00:00
Add support for group_ids param instead of groups param
This commit is contained in:
parent
65d96829a2
commit
1c25a71a1b
3
.gitignore
vendored
3
.gitignore
vendored
@ -89,6 +89,7 @@ ENV/
|
||||
.ropeproject
|
||||
|
||||
# IntelliJ cruft
|
||||
.idea/*
|
||||
.idea/**
|
||||
.vscode/**
|
||||
|
||||
build
|
||||
|
4
OTXv2.py
4
OTXv2.py
@ -203,6 +203,7 @@ class OTXv2(object):
|
||||
:param tags(list of strings) short keywords to associate with your pulse
|
||||
:param references(list of strings, preferably URLs) external references for this threat
|
||||
:param indicators(list of objects) IOCs to include in pulse
|
||||
:param group_ids(list of integers) Group IDs for groups pulse should be added to. You must be a member of the group and able to add pulses to the group
|
||||
:return: request body response
|
||||
:raises BadRequest (400) On failure, BadRequest will be raised containing the invalid fields.
|
||||
|
||||
@ -223,7 +224,8 @@ class OTXv2(object):
|
||||
'TLP': kwargs.get('TLP', kwargs.get('tlp', 'green')),
|
||||
'tags': kwargs.get('tags', []),
|
||||
'references': kwargs.get('references', []),
|
||||
'indicators': kwargs.get('indicators', [])
|
||||
'indicators': kwargs.get('indicators', []),
|
||||
'groups': kwargs.get('group_ids', []),
|
||||
}
|
||||
# name is required. Public is too but will be set True if not specified.
|
||||
if not body.get('name'):
|
||||
|
@ -29,12 +29,16 @@ def create_user(username, password, email):
|
||||
Create a user, and get the API key
|
||||
"""
|
||||
print("creating user {}".format(username))
|
||||
requests.post(ALIEN_DEV_SERVER + 'otxapi/qatests/setup/', json={"users": [{ "username": username, "password": password, "email": email}]})
|
||||
requests.post(ALIEN_DEV_SERVER + 'otxapi/qatests/setup/', json={"users": [
|
||||
{"username": username, "password": password, "email": email, "group_ids": [64, 51, 2931]}
|
||||
]})
|
||||
r = requests.post(ALIEN_DEV_SERVER + 'auth/login', json={"username": username, "password": password})
|
||||
j = json.loads(r.text)
|
||||
r = requests.get(ALIEN_DEV_SERVER + 'otxapi/user/?detailed=true', headers={'Authorization': j['key']})
|
||||
j = r.json()
|
||||
return j['api_keys'][0]['api_key']
|
||||
API_KEY = j['api_keys'][0]['api_key']
|
||||
|
||||
return API_KEY
|
||||
|
||||
|
||||
def delete_user(username):
|
||||
@ -52,6 +56,7 @@ class TestOTXv2(unittest.TestCase):
|
||||
self.api_key = api_key or ALIEN_API_APIKEY
|
||||
self.otx = OTXv2(self.api_key, server=ALIEN_DEV_SERVER)
|
||||
|
||||
'''
|
||||
class TestSubscriptionsInvalidKey(TestOTXv2):
|
||||
"""
|
||||
Confirm InvalidAPIKey class is raised for API Key failures
|
||||
@ -273,9 +278,10 @@ class TestIndicatorDetails(TestOTXv2):
|
||||
full_details = self.otx.get_indicator_details_full(IndicatorTypes.EMAIL, "me@rustybrooks.com")
|
||||
self.assertTrue(sorted(full_details.keys()) == sorted(IndicatorTypes.EMAIL.sections))
|
||||
# pprint.pprint(full_details)
|
||||
|
||||
'''
|
||||
|
||||
class TestPulseCreate(TestOTXv2):
|
||||
'''
|
||||
def test_create_pulse_simple(self):
|
||||
name = "Pyclient-simple-unittests-" + generate_rand_string(8, charset=string.hexdigits).lower()
|
||||
# print("test_create_pulse_simple submitting pulse: " + name)
|
||||
@ -373,7 +379,7 @@ class TestPulseCreate(TestOTXv2):
|
||||
return
|
||||
|
||||
|
||||
def test_create_pulse_and_edit_via_patch_pulse(self):
|
||||
def test_create_pulse_and_edit_via_patch_pulse(self):
|
||||
"""
|
||||
Test: create a pulse then add indicators via a patch pulse object
|
||||
"""
|
||||
@ -394,7 +400,7 @@ def test_create_pulse_and_edit_via_patch_pulse(self):
|
||||
return
|
||||
|
||||
|
||||
def test_create_pulse_tlp(self):
|
||||
def test_create_pulse_tlp(self):
|
||||
"""
|
||||
Test: pulse with each TLP.
|
||||
"""
|
||||
@ -412,8 +418,43 @@ def test_create_pulse_tlp(self):
|
||||
self.assertTrue(response.get('TLP', '') == tlp)
|
||||
self.assertFalse(response.get('public'))
|
||||
return
|
||||
'''
|
||||
|
||||
def test_create_pulse_groups(self):
|
||||
"""
|
||||
Test: pulse with different sets of group ids
|
||||
Test user needs to be a member of the groups used in this test: 64, 51
|
||||
Additionall we will use the test groups 1 and 2, that it is NOT a member of
|
||||
"""
|
||||
charset = string.ascii_letters
|
||||
indicator_list = [
|
||||
{'indicator': generate_rand_string(10, charset=charset) + ".com", 'type': IndicatorTypes.DOMAIN.name, 'description': 'evil domain (unittests)'},
|
||||
{'indicator': generate_rand_string(3, charset=charset) + "." + generate_rand_string(10, charset=charset) + ".com", 'type': IndicatorTypes.HOSTNAME.name, 'description': 'evil hostname (unittests)'}
|
||||
]
|
||||
|
||||
for groups, expected in [
|
||||
([], []),
|
||||
(None, []),
|
||||
([1, 51], 'error'), # Not a member of group 1
|
||||
# ([51, 2931], [51, 2931]),
|
||||
# ([64, 51, 1], 'error'),
|
||||
# ([1], 'error'),
|
||||
]:
|
||||
name = "Pyclient-tlp-unittests-" + generate_rand_string(8, charset=string.hexdigits).lower()
|
||||
print(groups, expected)
|
||||
if expected == 'error':
|
||||
with self.assertRaises(BadRequest):
|
||||
self.otx.create_pulse(name=name, indicators=indicator_list, group_ids=groups)
|
||||
else:
|
||||
response = self.otx.create_pulse(name=name, indicators=indicator_list, group_ids=groups)
|
||||
|
||||
self.assertEqual(response.get('name', ''), name)
|
||||
self.assertEqual(response.get('group_ids'), expected)
|
||||
|
||||
return
|
||||
|
||||
|
||||
'''
|
||||
class TestPulseCreateInvalidKey(TestOTXv2):
|
||||
def setUp(self, **kwargs):
|
||||
super(TestPulseCreateInvalidKey, self).setUp(**{'api_key': "ALIEN_API_APIKEY"})
|
||||
@ -740,7 +781,7 @@ class TestOTXv2Cached(unittest.TestCase):
|
||||
self.assertIsNotNone(pulse.get('tags', None))
|
||||
self.assertIsNotNone(pulse.get('references', None))
|
||||
self.assertIsNotNone(res.get('exact_match'))
|
||||
|
||||
'''
|
||||
|
||||
if __name__ == '__main__':
|
||||
username = "qatester-git-{}".format(rand)
|
||||
|
Loading…
Reference in New Issue
Block a user