-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from InQuest/compatibility-updates
Compatibility updates
- Loading branch information
Showing
19 changed files
with
738 additions
and
618 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: sandbox-workflow | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ["2.7", "3.8", "3.9"] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
pip install -r requirements.txt | ||
pip install pytest pytest-mock coverage requests-mock responses collective.checkdocs Pygments nose | ||
- name: Test scripts | ||
run: | | ||
coverage run -m unittest discover | ||
nosetests tests/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,6 @@ dist/ | |
_build/ | ||
/build_dist.sh | ||
.vscode/ | ||
/.virtualenv/ | ||
/.pytest_cache/ | ||
Pipfile.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
language: python | ||
python: | ||
# - "2.6" # -- responses module requires 2.7+ | ||
- "2.7" | ||
# TODO: resolve issues with older 3.x versions | ||
# - "3.3" | ||
# - "3.4" | ||
- "3.5" | ||
install: | ||
- "pip install -r requirements.txt" | ||
- "pip install nose" | ||
- "pip install responses" | ||
- "pip install coveralls" | ||
- "pip install codacy-coverage" | ||
- "pip install collective.checkdocs Pygments" | ||
script: | ||
- nosetests --with-coverage --cover-package=sandboxapi | ||
- python setup.py checkdocs | ||
after_success: | ||
- coveralls | ||
- coverage xml | ||
- bash <(curl -Ls https://coverage.codacy.com/get.sh) report -r coverage.xml | ||
jobs: | ||
include: | ||
- name: "Python 3.9" | ||
python: 3.9 | ||
install: | ||
- "pip install -r requirements.txt" | ||
- "pip install pytest pytest-mock coverage requests-mock responses collective.checkdocs Pygments" | ||
script: | ||
- coverage run -m pytest | ||
- python setup.py checkdocs | ||
after_success: | ||
- coveralls | ||
- coverage xml | ||
- if [ "$TRAVIS_BRANCH" = "master" ]; then bash <(curl -Ls https://coverage.codacy.com/get.sh) report -r coverage.xml; fi | ||
- name: "Python 2.7" | ||
python: 2.7 | ||
install: | ||
- "pip install -r requirements.txt" | ||
- "pip install nose mock requests-mock responses collective.checkdocs Pygments" | ||
script: | ||
- nosetests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[[source]] | ||
url = "https://pypi.org/simple" | ||
verify_ssl = true | ||
name = "pypi" | ||
|
||
[packages] | ||
requests = "*" | ||
jbxapi = "*" | ||
xmltodict = "*" | ||
|
||
[dev-packages] | ||
pytest = "*" | ||
coverage = "*" | ||
responses = "*" | ||
"collective.checkdocs" = "*" | ||
pygments = "*" | ||
|
||
[requires] | ||
python_version = "3.9" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
requests | ||
jbxapi==2.10.1 | ||
jbxapi | ||
xmltodict |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import os | ||
import json | ||
|
||
def read_resource(resource): | ||
with open(os.path.join('tests', 'resources', '{r}.json'.format(r=resource)), 'r') as f: | ||
return json.loads(f.read()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"data": { | ||
"submission_id": "100001" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import io | ||
from unittest import TestCase | ||
|
||
try: | ||
from unittest.mock import patch, ANY as MOCK_ANY | ||
except ImportError: | ||
from mock import patch, ANY as MOCK_ANY | ||
|
||
import responses | ||
import sandboxapi.cuckoo | ||
from . import read_resource | ||
|
||
class TestCuckoo(TestCase): | ||
|
||
def setUp(self): | ||
self.sandbox = sandboxapi.cuckoo.CuckooAPI('http://cuckoo.mock:8090/') | ||
|
||
@responses.activate | ||
def test_analyses(self): | ||
responses.add(responses.GET, 'http://cuckoo.mock:8090/tasks/list', | ||
json=read_resource('cuckoo_tasks_list')) | ||
self.assertEqual(len(self.sandbox.analyses()), 2) | ||
|
||
@responses.activate | ||
def test_analyze(self): | ||
responses.add(responses.POST, 'http://cuckoo.mock:8090/tasks/create/file', | ||
json=read_resource('cuckoo_tasks_create_file')) | ||
self.assertEqual(self.sandbox.analyze(io.BytesIO('test'.encode('ascii')), 'filename'), '1') | ||
|
||
@responses.activate | ||
def test_check(self): | ||
responses.add(responses.GET, 'http://cuckoo.mock:8090/tasks/view/1', | ||
json=read_resource('cuckoo_tasks_view')) | ||
self.assertEqual(self.sandbox.check('1'), True) | ||
|
||
@responses.activate | ||
def test_is_available(self): | ||
responses.add(responses.GET, 'http://cuckoo.mock:8090/cuckoo/status', | ||
json=read_resource('cuckoo_status')) | ||
self.assertTrue(self.sandbox.is_available()) | ||
|
||
@responses.activate | ||
def test_not_is_available(self): | ||
self.assertFalse(self.sandbox.is_available()) | ||
responses.add(responses.GET, 'http://cuckoo.mock:8090/cuckoo/status', | ||
status=500) | ||
self.assertFalse(self.sandbox.is_available()) | ||
|
||
@responses.activate | ||
def test_report(self): | ||
responses.add(responses.GET, 'http://cuckoo.mock:8090/tasks/report/8/json', | ||
json=read_resource('cuckoo_tasks_report')) | ||
self.assertEqual(self.sandbox.report(8)['info']['id'], 8) | ||
|
||
@responses.activate | ||
def test_score(self): | ||
responses.add(responses.GET, 'http://cuckoo.mock:8090/tasks/report/8/json', | ||
json=read_resource('cuckoo_tasks_report')) | ||
self.assertEqual(self.sandbox.score(self.sandbox.report(8)), 5) | ||
|
||
@patch('requests.post') | ||
@patch('requests.get') | ||
def test_proxies_is_passed_to_requests(self, m_get, m_post): | ||
|
||
m_get.return_value.status_code = 200 | ||
m_post.return_value.status_code = 200 | ||
|
||
proxies = { | ||
'http': 'http://10.10.1.10:3128', | ||
'https': 'http://10.10.1.10:1080', | ||
} | ||
|
||
api = sandboxapi.cuckoo.CuckooAPI('cuckoo.mock', | ||
proxies=proxies) | ||
api._request('/test') | ||
|
||
m_get.assert_called_once_with(api.api_url + '/test', auth=MOCK_ANY, | ||
headers=MOCK_ANY, params=MOCK_ANY, | ||
proxies=proxies, verify=MOCK_ANY) | ||
|
||
api._request('/test', method='POST') | ||
|
||
m_post.assert_called_once_with(api.api_url + '/test', auth=MOCK_ANY, | ||
headers=MOCK_ANY, data=MOCK_ANY, | ||
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.assertEqual(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.assertEqual(len(self.sandbox.analyses()), 2) |
Oops, something went wrong.