Skip to content

Commit

Permalink
Tanner version (#217)
Browse files Browse the repository at this point in the history
tanner version endpoint
  • Loading branch information
afeena authored and glaslos committed Nov 28, 2017
1 parent e0d8a30 commit acc7e85
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions tanner/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = '0.4.0'
11 changes: 9 additions & 2 deletions tanner/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from tanner.reporting.log_local import Reporting as local_report
from tanner.reporting.log_mongodb import Reporting as mongo_report
from tanner.reporting.log_hpfeeds import Reporting as hpfeeds_report
from tanner import __version__ as tanner_version


asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())

Expand All @@ -36,7 +38,7 @@ def __init__(self):
@staticmethod
def _make_response(msg):
response_message = dict(
version=1,
version=tanner_version,
response=dict(message=msg)
)
return response_message
Expand Down Expand Up @@ -86,7 +88,11 @@ async def handle_event(self, request):

async def handle_dorks(self, request):
dorks = await self.dorks.choose_dorks(self.redis_client)
response_msg = dict(version=1, response=dict(dorks=dorks))
response_msg = dict(version=tanner_version, response=dict(dorks=dorks))
return web.json_response(response_msg)

async def handle_version(self, request):
response_msg = dict(version=tanner_version)
return web.json_response(response_msg)

async def on_shutdown(self, app):
Expand All @@ -97,6 +103,7 @@ def setup_routes(self, app):
app.router.add_route('*', '/', self.default_handler)
app.router.add_post('/event', self.handle_event)
app.router.add_get('/dorks', self.handle_dorks)
app.router.add_get('/version', self.handle_version)

def create_app(self, loop):
app = web.Application(loop=loop)
Expand Down
18 changes: 14 additions & 4 deletions tanner/tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from tanner import server
from tanner.config import TannerConfig

from tanner import __version__ as tanner_version

class TestServer(AioHTTPTestCase):
def setUp(self):
Expand Down Expand Up @@ -72,15 +72,15 @@ async def test_example(self):
def test_make_response(self):
msg = 'test'
content = self.serv._make_response(msg)
assert_content = dict(version=1, response=dict(message=msg))
assert_content = dict(version=tanner_version, response=dict(message=msg))
self.assertDictEqual(content, assert_content)

@unittest_run_loop
async def test_events_request(self):
async def _make_handle_coroutine(*args, **kwargs):
return {'name': 'index', 'order': 1, "payload": None}

detection_assert = {'version': 1, 'response': {
detection_assert = {'version': tanner_version, 'response': {
'message': {'detection': {'name': 'index', 'order': 1, "payload": None}, 'sess_uuid': str(self.test_uuid)}}}
self.serv.base_handler.handle = _make_handle_coroutine
request = await self.client.request("POST", "/event", data=b"{\"path\":\"/index.html\"}")
Expand All @@ -90,8 +90,18 @@ async def _make_handle_coroutine(*args, **kwargs):

@unittest_run_loop
async def test_dorks_request(self):
assert_content = dict(version=1, response=dict(dorks=[x for x in range(10)]))
assert_content = dict(version=tanner_version, response=dict(dorks=[x for x in range(10)]))
request = await self.client.request("GET", "/dorks")
assert request.status == 200
detection = await request.json()
self.assertDictEqual(detection, assert_content)

@unittest_run_loop
async def test_version(self):
assert_content = dict(version=tanner_version)
request = await self.client.request("GET", "/version")
assert request.status == 200
detection = await request.json()
self.assertDictEqual(detection, assert_content)


0 comments on commit acc7e85

Please sign in to comment.