Skip to content

Commit

Permalink
code cleanup and some additional utils tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jbremer committed Oct 4, 2016
1 parent b8ce11a commit e58569a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
13 changes: 3 additions & 10 deletions cuckoo/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def convert_char(c):
return "\\x%02x" % ord(c)

def is_printable(s):
""" Test if a string is printable."""
"""Test if a string is printable."""
for c in s:
if c not in PRINTABLE_CHARACTERS:
return False
Expand Down Expand Up @@ -152,13 +152,6 @@ def chardet_enc(s2):

return result

def cleanup_value(v):
"""Cleanup utility function, strips some unwanted parts from values."""
v = str(v)
if v.startswith("\\??\\"):
v = v[4:]
return v

def classlock(f):
"""Classlock decorator (created for database.Database).
Used to put a lock to avoid sqlite errors.
Expand Down Expand Up @@ -194,12 +187,12 @@ def guid_name(guid):
if not GUIDS:
for line in open(cwd("guids.txt", private=True)):
try:
guid, name, url = line.strip().split()
guid_, name, url = line.strip().split()
except:
log.debug("Invalid GUID entry: %s", line)
continue

GUIDS["{%s}" % guid] = name
GUIDS["{%s}" % guid_] = name

return GUIDS.get(guid)

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ testpaths = tests
norecursedirs = tests/darwin

[aliases]
test = pytest
test = pytest
8 changes: 6 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@
"psycopg2==2.6.2",
],
},
setup_requires = ["pytest-runner"],
tests_require = ["pytest"],
setup_requires=[
"pytest-runner",
],
tests_require=[
"pytest",
],
)
28 changes: 28 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import shutil
import tempfile

import cuckoo

from cuckoo.common.files import Folders, Files, Storage
from cuckoo.common import utils

Expand Down Expand Up @@ -154,3 +156,29 @@ def test_version():
from cuckoo import __version__
from cuckoo.misc import version
assert __version__ == version

def test_exception():
s = utils.exception_message()
assert "Cuckoo version: %s" % cuckoo.__version__ in s
assert "alembic:" in s
assert "django-extensions:" in s
assert "peepdf:" in s
assert "sflock:" in s

def test_guid():
assert utils.guid_name("{0002e005-0000-0000-c000-000000000046}") == "InprocServer32"
assert utils.guid_name("{13709620-c279-11ce-a49e-444553540000}") == "Shell"

def test_jsbeautify():
js = {
"if(1){a(1,2,3);}": "if (1) {\n a(1, 2, 3);\n}",
}
for k, v in js.items():
assert utils.jsbeautify(k) == v

def test_htmlprettify():
html = {
"<a href=google.com>wow</a>": '<a href="google.com">\n wow\n</a>',
}
for k, v in html.items():
assert utils.htmlprettify(k) == v

0 comments on commit e58569a

Please sign in to comment.