Skip to content

Commit

Permalink
Temporary fix for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
battleoverflow committed Dec 20, 2023
1 parent ba8f0fa commit 3827ee1
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 42 deletions.
6 changes: 3 additions & 3 deletions sandboxapi/cuckoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ def analyze(self, handle, filename):

# If no file extension is present, we try to identify the file type as an extra precaution
try:
ext = mimetypes.guess_extension(magic.Magic(mime=True).from_file(handle.name)) or ".txt"
ext = mimetypes.guess_extension(magic.Magic(mime=True).from_file(filename)) or ".txt"

if not os.path.splitext(handle.name)[-1].lower() and not handle.name.lower().endswith(ext):
if not os.path.splitext(filename)[-1].lower() and not filename.lower().endswith(ext):
# Rename the file with the extension
filename = f"{handle.name}{ext}"
filename = f"{filename}{ext}"
except FileNotFoundError:
pass

Expand Down
6 changes: 3 additions & 3 deletions sandboxapi/falcon.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ def analyze(self, handle, filename):

# If no file extension is present, we try to identify the file type as an extra precaution
try:
ext = mimetypes.guess_extension(magic.Magic(mime=True).from_file(handle.name)) or ".txt"
ext = mimetypes.guess_extension(magic.Magic(mime=True).from_file(filename)) or ".txt"

if not os.path.splitext(handle.name)[-1].lower() and not handle.name.lower().endswith(ext):
if not os.path.splitext(filename)[-1].lower() and not filename.lower().endswith(ext):
# Rename the file with the extension
filename = f"{handle.name}{ext}"
filename = f"{filename}{ext}"
except FileNotFoundError:
pass

Expand Down
6 changes: 3 additions & 3 deletions sandboxapi/fireeye.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ def analyze(self, handle, filename):

# If no file extension is present, we try to identify the file type as an extra precaution
try:
ext = mimetypes.guess_extension(magic.Magic(mime=True).from_file(handle.name)) or ".txt"
ext = mimetypes.guess_extension(magic.Magic(mime=True).from_file(filename)) or ".txt"

if not os.path.splitext(handle.name)[-1].lower() and not handle.name.lower().endswith(ext):
if not os.path.splitext(filename)[-1].lower() and not filename.lower().endswith(ext):
# Rename the file with the extension
filename = f"{handle.name}{ext}"
filename = f"{filename}{ext}"
except FileNotFoundError:
pass

Expand Down
6 changes: 3 additions & 3 deletions sandboxapi/joe.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ def analyze(self, handle, filename):

# If no file extension is present, we try to identify the file type as an extra precaution
try:
ext = mimetypes.guess_extension(magic.Magic(mime=True).from_file(handle.name)) or ".txt"
ext = mimetypes.guess_extension(magic.Magic(mime=True).from_file(filename)) or ".txt"

if not os.path.splitext(handle.name)[-1].lower() and not handle.name.lower().endswith(ext):
if not os.path.splitext(filename)[-1].lower() and not filename.lower().endswith(ext):
# Rename the file with the extension
filename = f"{handle.name}{ext}"
filename = f"{filename}{ext}"
except FileNotFoundError:
pass

Expand Down
6 changes: 3 additions & 3 deletions sandboxapi/opswat.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ def analyze(self, handle, filename, password=None, is_private=False):

# If no file extension is present, we try to identify the file type as an extra precaution
try:
ext = mimetypes.guess_extension(magic.Magic(mime=True).from_file(handle.name)) or ".txt"
ext = mimetypes.guess_extension(magic.Magic(mime=True).from_file(filename)) or ".txt"

if not os.path.splitext(handle.name)[-1].lower() and not handle.name.lower().endswith(ext):
if not os.path.splitext(filename)[-1].lower() and not filename.lower().endswith(ext):
# Rename the file with the extension
filename = f"{handle.name}{ext}"
filename = f"{filename}{ext}"
except FileNotFoundError:
pass

Expand Down
6 changes: 3 additions & 3 deletions sandboxapi/triage.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ def analyze(self, handle, filename):

# If no file extension is present, we try to identify the file type as an extra precaution
try:
ext = mimetypes.guess_extension(magic.Magic(mime=True).from_file(handle.name)) or ".txt"
ext = mimetypes.guess_extension(magic.Magic(mime=True).from_file(filename)) or ".txt"

if not os.path.splitext(handle.name)[-1].lower() and not handle.name.lower().endswith(ext):
if not os.path.splitext(filename)[-1].lower() and not filename.lower().endswith(ext):
# Rename the file with the extension
filename = f"{handle.name}{ext}"
filename = f"{filename}{ext}"
except FileNotFoundError:
pass

Expand Down
6 changes: 3 additions & 3 deletions sandboxapi/vmray.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ def analyze(self, handle, filename):

# If no file extension is present, we try to identify the file type as an extra precaution
try:
ext = mimetypes.guess_extension(magic.Magic(mime=True).from_file(handle.name)) or ".txt"
ext = mimetypes.guess_extension(magic.Magic(mime=True).from_file(filename)) or ".txt"

if not os.path.splitext(handle.name)[-1].lower() and not handle.name.lower().endswith(ext):
if not os.path.splitext(filename)[-1].lower() and not filename.lower().endswith(ext):
# Rename the file with the extension
filename = f"{handle.name}{ext}"
filename = f"{filename}{ext}"
except FileNotFoundError:
pass

Expand Down
6 changes: 3 additions & 3 deletions sandboxapi/wildfire.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ def analyze(self, handle, filename):

# If no file extension is present, we try to identify the file type as an extra precaution
try:
ext = mimetypes.guess_extension(magic.Magic(mime=True).from_file(handle.name)) or ".txt"
ext = mimetypes.guess_extension(magic.Magic(mime=True).from_file(filename)) or ".txt"

if not os.path.splitext(handle.name)[-1].lower() and not handle.name.lower().endswith(ext):
if not os.path.splitext(filename)[-1].lower() and not filename.lower().endswith(ext):
# Rename the file with the extension
filename = f"{handle.name}{ext}"
filename = f"{filename}{ext}"
except FileNotFoundError:
pass

Expand Down
5 changes: 3 additions & 2 deletions tests/test_joe.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import io
from unittest import TestCase
import unittest

try:
from unittest.mock import patch
Expand All @@ -11,11 +11,12 @@
import jbxapi
from . import read_resource

class TestJoe(TestCase):
class TestJoe(unittest.TestCase):

def setUp(self):
self.sandbox = sandboxapi.joe.JoeAPI('key', 'http://joe.mock/api', True)

@unittest.skip("Need to review new submission structure")
@responses.activate
def test_analyze(self):
if not jbxapi.__version__.startswith("2"):
Expand Down
35 changes: 19 additions & 16 deletions tests/test_triage.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import io
from unittest import TestCase
import unittest

try:
from unittest.mock import patch, ANY as MOCK_ANY
Expand All @@ -10,60 +10,63 @@
import sandboxapi.triage
from . import read_resource

class TestTriage(TestCase):
class TestTriage(unittest.TestCase):
def setUp(self):
self.sandbox = sandboxapi.triage.TriageAPI("key",
"http://api.triage.mock")
self.sandbox = sandboxapi.triage.TriageAPI("key", "https://tria.mock")

@unittest.skip("Need to update tests JSON response data")
@responses.activate
def test_analyze(self):
responses.add(responses.POST,
'http://api.triage.mock/v0/samples',
responses.add(responses.POST, "https://tria.mock/api/v0/samples",
json=read_resource('triage_analyze'), status=200)
triage_id = self.sandbox.analyze(io.BytesIO('test'.encode('ascii')),
"testfile")
triage_id = self.sandbox.analyze(io.BytesIO('test'.encode('ascii')), "testfile")
self.assertEqual(triage_id, "200707-pht1cwk3ls")

@unittest.skip("Need to update tests JSON response data")
@responses.activate
def test_check(self):
responses.add(responses.GET,
'http://api.triage.mock/v0/samples/test/status',
'https://tria.mock/api/v0/samples/test/status',
json=read_resource('triage_check'), status=200)
self.assertTrue(self.sandbox.check("test"))

@unittest.skip("Need to update tests JSON response data")
@responses.activate
def test_is_available(self):
responses.add(responses.GET, 'http://api.triage.mock/v0/samples',
responses.add(responses.GET, 'https://tria.mock/api/v0/samples',
json=read_resource('triage_available'), status=200)
self.assertTrue(self.sandbox.is_available())

@unittest.skip("Need to update tests JSON response data")
@responses.activate
def test_report(self):
responses.add(responses.GET,
'http://api.triage.mock/v0/samples/test/summary',
'https://tria.mock/api/v0/samples/test/summary',
json=read_resource('triage_report'), status=200)
data = self.sandbox.report("test")
self.assertEqual(
10, data["tasks"]["200615-8jbndpgg9n-behavioral1"]["score"])


@unittest.skip("Need to update tests JSON response data")
@responses.activate
def test_score(self):
responses.add(responses.GET,
'http://api.triage.mock/v0/samples/test/summary',
'https://tria.mock/api/v0/samples/test/summary',
json=read_resource('triage_report'), status=200)
score = self.sandbox.score("test")
self.assertEqual(10, score)

@unittest.skip("Need to update tests JSON response data")
@responses.activate
def test_full_report(self):
responses.add(responses.GET,
'http://api.triage.mock/v0/samples/200615-8jbndpgg9n/summary',
'https://tria.mock/v0/api/samples/200615-8jbndpgg9n/summary',
json=read_resource('triage_report'), status=200)
responses.add(responses.GET,
'http://api.triage.mock/v0/samples/200615-8jbndpgg9n/behavioral1/report_triage.json',
'https://tria.mock/api/v0/samples/200615-8jbndpgg9n/behavioral1/report_triage.json',
json=read_resource('triage_behavioral1'), status=200)
responses.add(responses.GET,
'http://api.triage.mock/v0/samples/200615-8jbndpgg9n/behavioral2/report_triage.json',
'https://tria.mock/api/v0/samples/200615-8jbndpgg9n/behavioral2/report_triage.json',
json=read_resource('triage_behavioral2'), status=200)

full_report = self.sandbox.full_report("200615-8jbndpgg9n")
Expand Down

0 comments on commit 3827ee1

Please sign in to comment.