Skip to content

Commit

Permalink
#35 Initialize unit tests for cortexutils
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Apr 5, 2017
1 parent 273bdeb commit ebee2d8
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 5 deletions.
4 changes: 4 additions & 0 deletions contrib/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
dist/
build/
*.egg-info

tests/htmlcov
.coverage
coverage.xml
5 changes: 2 additions & 3 deletions contrib/cortexutils/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ def __init__(self):
self.output = sys.stdout
self.artifact = json.load(sys.stdin)
self.tlp = self.getParam('tlp', 2)
self.data_type = self.getParam(
'dataType', None, 'Missing dataType field')
self.data_type = self.getParam('dataType', None, 'Missing dataType field')
self.check_tlp = self.getParam('config.check_tlp', False)
self.max_tlp = self.getParam('config.max_tlp', 10)
self.max_tlp = self.getParam('config.max_tlp', 2)
self.http_proxy = self.getParam('config.proxy.http')
self.https_proxy = self.getParam('config.proxy.https')
if self.http_proxy is not None:
Expand Down
5 changes: 3 additions & 2 deletions contrib/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='cortexutils',
version='1.0.0',
version='1.1.0',
description='A Python library for including utility classes for Cortex analyzers',
long_description=open('README').read(),
author='TheHive-Project',
Expand All @@ -23,5 +23,6 @@
py_modules=['cortexutils.analyzer'],
install_requires=[
'ioc-parser'
]
],
test_suite='tests'
)
Empty file added contrib/tests/__init__.py
Empty file.
4 changes: 4 additions & 0 deletions contrib/tests/test-minimal-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"dataType": "ip",
"data": "8.8.8.8"
}
10 changes: 10 additions & 0 deletions contrib/tests/test-proxy-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"dataType": "ip",
"data": "1.1.1.1",
"config": {
"proxy": {
"http": "http://local.proxy:8080",
"https": "http://local.proxy:8080"
}
}
}
47 changes: 47 additions & 0 deletions contrib/tests/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import os
import sys
import unittest
import StringIO

from cortexutils.analyzer import Analyzer

class TestMinimalConfig(unittest.TestCase):

def setUp(self):
path = os.path.dirname(os.path.abspath(__file__))
with open(path + '/test-minimal-config.json', 'r') as content_file:
input = content_file.read()
sys.stdin = StringIO.StringIO(input)
self.analyzer = Analyzer()

def test_default_config(self):
self.assertEqual(self.analyzer.data_type, 'ip')
self.assertEqual(self.analyzer.tlp, 2)
self.assertEqual(self.analyzer.check_tlp, False)
self.assertEqual(self.analyzer.max_tlp, 10)
self.assertEqual(self.analyzer.http_proxy, None)
self.assertEqual(self.analyzer.https_proxy, None)

def test_artifact_data(self):
self.assertEqual(self.analyzer.getData(), "8.8.8.8")

class TestProxyConfig(unittest.TestCase):

def setUp(self):
path = os.path.dirname(os.path.abspath(__file__))
with open(path + '/test-proxy-config.json', 'r') as content_file:
input = content_file.read()
sys.stdin = StringIO.StringIO(input)
self.analyzer = Analyzer()

def test_proxy_config(self):
proxy_url = 'http://local.proxy:8080'

self.assertEqual(self.analyzer.http_proxy, proxy_url)
self.assertEqual(self.analyzer.https_proxy, proxy_url)

self.assertEqual(os.environ['http_proxy'], proxy_url)
self.assertEqual(os.environ['https_proxy'], proxy_url)

if __name__ == '__main__':
unittest.main()

0 comments on commit ebee2d8

Please sign in to comment.