Ensure API key is used

This commit is contained in:
Wes Lambert
2022-05-03 12:48:06 +00:00
parent efb229cfcb
commit 8b5666b238
2 changed files with 5 additions and 4 deletions

View File

@@ -19,7 +19,8 @@ def sendReq(conf, meta, ip):
url = url + 'v3/community/' + ip url = url + 'v3/community/' + ip
elif conf['api_version'] == 'investigate' or 'automate': elif conf['api_version'] == 'investigate' or 'automate':
url = url + 'v2/noise/context/' + ip url = url + 'v2/noise/context/' + ip
response = requests.request('GET', url) headers = {"key": conf['api_key']}
response = requests.request('GET', url=url, headers=headers)
return response.json() return response.json()

View File

@@ -37,7 +37,7 @@ class TestGreynoiseMethods(unittest.TestCase):
conf = {"base_url": "https://myurl/", "api_key": "abcd1234", "api_version": "community"} conf = {"base_url": "https://myurl/", "api_key": "abcd1234", "api_version": "community"}
ip = "192.168.1.1" ip = "192.168.1.1"
response = greynoise.sendReq(conf=conf, meta=meta, ip=ip) response = greynoise.sendReq(conf=conf, meta=meta, ip=ip)
mock.assert_called_once_with("GET", "https://myurl/v3/community/192.168.1.1") mock.assert_called_once_with("GET", headers={'key': 'abcd1234'}, url="https://myurl/v3/community/192.168.1.1")
self.assertIsNotNone(response) self.assertIsNotNone(response)
def test_sendReq_investigate(self): def test_sendReq_investigate(self):
@@ -46,7 +46,7 @@ class TestGreynoiseMethods(unittest.TestCase):
conf = {"base_url": "https://myurl/", "api_key": "abcd1234", "api_version": "investigate"} conf = {"base_url": "https://myurl/", "api_key": "abcd1234", "api_version": "investigate"}
ip = "192.168.1.1" ip = "192.168.1.1"
response = greynoise.sendReq(conf=conf, meta=meta, ip=ip) response = greynoise.sendReq(conf=conf, meta=meta, ip=ip)
mock.assert_called_once_with("GET", "https://myurl/v2/noise/context/192.168.1.1") mock.assert_called_once_with("GET", headers={'key': 'abcd1234'}, url="https://myurl/v2/noise/context/192.168.1.1")
self.assertIsNotNone(response) self.assertIsNotNone(response)
def test_sendReq_automate(self): def test_sendReq_automate(self):
@@ -55,7 +55,7 @@ class TestGreynoiseMethods(unittest.TestCase):
conf = {"base_url": "https://myurl/", "api_key": "abcd1234", "api_version": "automate"} conf = {"base_url": "https://myurl/", "api_key": "abcd1234", "api_version": "automate"}
ip = "192.168.1.1" ip = "192.168.1.1"
response = greynoise.sendReq(conf=conf, meta=meta, ip=ip) response = greynoise.sendReq(conf=conf, meta=meta, ip=ip)
mock.assert_called_once_with("GET", "https://myurl/v2/noise/context/192.168.1.1") mock.assert_called_once_with("GET", headers={'key': 'abcd1234'}, url="https://myurl/v2/noise/context/192.168.1.1")
self.assertIsNotNone(response) self.assertIsNotNone(response)
def test_prepareResults_invalidIP(self): def test_prepareResults_invalidIP(self):