Skip to content

Commit

Permalink
Deprecate Cuckoo host/port/api_path for url
Browse files Browse the repository at this point in the history
Support for Cuckoo host/port/api_path will be removed in a future version.
  • Loading branch information
rshipp committed Jun 28, 2018
1 parent 92d810a commit 2951bc6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ the same way:
# connect to the sandbox
sandboxes = [
cuckoo.CuckooAPI('192.168.0.20'),
cuckoo.CuckooAPI('http://192.168.0.20:8090/'),
fireeye.FireEyeAPI('myusername', 'mypassword', 'https://192.168.0.21', 'winxp-sp3'),
joe.JoeAPI('mykey', 'https://jbxcloud.joesecurity.org/api', True)
]
Expand Down Expand Up @@ -136,11 +136,11 @@ Cuckoo Sandbox

Constructor signature::

CuckooAPI(host, port=8090, api_path='/', verify_ssl=False)
CuckooAPI(url, verify_ssl=False)

Example::

CuckooAPI('192.168.0.20')
CuckooAPI('http://192.168.0.20:8090/')

This library attempts to support any Cuckoo-like API, including older 1.x
installations (though those without a score won't be able to use the ``.score``
Expand Down
22 changes: 19 additions & 3 deletions sandboxapi/cuckoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,27 @@
class CuckooAPI(sandboxapi.SandboxAPI):
"""Cuckoo Sandbox API wrapper."""

def __init__(self, host, port=8090, api_path='/', verify_ssl=False, **kwargs):
"""Initialize the interface to Cuckoo Sandbox API with host and port."""
def __init__(self, url, port=8090, api_path='/', verify_ssl=False, **kwargs):
"""Initialize the interface to Cuckoo Sandbox API with host and port.
:type url: str
:param url: Cuckoo API URL. (Currently treated as host if not a fully formed URL -
this will be removed in a future version.)
:type port: int
:param port: DEPRECATED! Use fully formed url instead. Will be removed in future version.
:type api_path: str
:param api_path: DEPRECATED! Use fully formed url instead. Will be removed in future version.
"""
sandboxapi.SandboxAPI.__init__(self, **kwargs)

self.api_url = 'http://' + host + ':' + str(port) + api_path
# NOTE: host/port/api_path support is DEPRECATED!
if url.startswith('http://') or url.startswith('https://'):
# Assume new-style url param. Ignore port and api_path.
self.api_url = url
else:
# This is for backwards compatability and will be removed in a future version.
self.api_url = 'http://' + url + ':' + str(port) + api_path

self.verify_ssl = verify_ssl

# assume Cuckoo is *not* available.
Expand Down
15 changes: 14 additions & 1 deletion tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def read_resource(resource):
class TestCuckoo(unittest.TestCase):

def setUp(self):
self.sandbox = sandboxapi.cuckoo.CuckooAPI('cuckoo.mock')
self.sandbox = sandboxapi.cuckoo.CuckooAPI('http://cuckoo.mock:8090/')

@responses.activate
def test_analyses(self):
Expand Down Expand Up @@ -95,6 +95,19 @@ def test_proxies_is_passed_to_requests(self, m_get, m_post):
files=None, proxies=proxies,
verify=MOCK_ANY)

@responses.activate
def test_cuckoo_old_style_host_port_path(self):
sandbox = sandboxapi.cuckoo.CuckooAPI('cuckoo.mock')
responses.add(responses.GET, 'http://cuckoo.mock:8090/tasks/list',
json=read_resource('cuckoo_tasks_list'))
self.assertEquals(len(self.sandbox.analyses()), 2)

sandbox = sandboxapi.cuckoo.CuckooAPI('cuckoo.mock', 9090, '/test')
responses.add(responses.GET, 'http://cuckoo.mock:9090/test/tasks/list',
json=read_resource('cuckoo_tasks_list'))
self.assertEquals(len(self.sandbox.analyses()), 2)



class TestJoe(unittest.TestCase):

Expand Down

0 comments on commit 2951bc6

Please sign in to comment.