From 127f99e3b2a1093f718750efdf47c3c15434c7ea Mon Sep 17 00:00:00 2001 From: rjt-gupta Date: Fri, 15 Mar 2019 02:03:45 +0530 Subject: [PATCH] Increased coverage final --- snare/tests/test_parse_tanner_response.py | 78 +++++++++++++++++------ 1 file changed, 60 insertions(+), 18 deletions(-) diff --git a/snare/tests/test_parse_tanner_response.py b/snare/tests/test_parse_tanner_response.py index 74128400..81f88fd1 100755 --- a/snare/tests/test_parse_tanner_response.py +++ b/snare/tests/test_parse_tanner_response.py @@ -24,12 +24,12 @@ def setUp(self): f.write(self.page_content) with open(os.path.join(self.main_page_path, "meta.json"), 'w') as f: json.dump(meta_content, f) - args = run_args.parse_args(['--page-dir', page_dir]) - args.index_page = '/index.html' - args.no_dorks = True - args.tanner = "tanner.mushmush.org" - uuid = "test_uuid" - self.handler = TannerHandler(args, meta_content, uuid) + self.args = run_args.parse_args(['--page-dir', page_dir]) + self.args.index_page = '/index.html' + self.args.no_dorks = True + self.args.tanner = "tanner.mushmush.org" + self.uuid = "test_uuid" + self.handler = TannerHandler(self.args, meta_content, self.uuid) self.requested_name = '/' self.loop = asyncio.get_event_loop() self.handler.html_handler.handle_content = AsyncMock(return_value=self.page_content) @@ -41,6 +41,7 @@ def setUp(self): self.expected_content = None self.call_content = None self.expected_header = None + self.expected_status_code = None def test_parse_type_one(self): self.detection = {"type": 1} @@ -55,6 +56,36 @@ async def test(): expected_result = [self.page_content, self.content_type, {}, 200] self.assertCountEqual(real_result, expected_result) + def test_parse_type_one_query(self): + self.requested_name = '/?' + self.detection = {"type": 1} + self.call_content = b'' + + async def test(): + (self.res1, self.res2, + self.res3, self.res4) = await self.handler.parse_tanner_response(self.requested_name, self.detection) + + self.loop.run_until_complete(test()) + real_result = [self.res1, self.res2, self.res3, self.res4] + expected_result = [self.page_content, self.content_type, {}, 200] + self.assertCountEqual(real_result, expected_result) + + def test_parse_type_one_error(self): + self.detection = {"type": 1} + meta_content = {"/index.html": {}} + self.requested_name = 'something/' + self.handler = TannerHandler(self.args, meta_content, self.uuid) + self.expected_status_code = 404 + + async def test(): + (self.res1, self.res2, + self.res3, self.res4) = await self.handler.parse_tanner_response(self.requested_name, self.detection) + + self.loop.run_until_complete(test()) + real_result = [self.res1, self.res2, self.res3, self.res4] + expected_result = [None, None, {}, self.expected_status_code] + self.assertCountEqual(real_result, expected_result) + def test_parse_type_two(self): self.detection = { "type": 2, @@ -99,6 +130,29 @@ async def test(): expected_result = [self.expected_content, self.content_type, self.expected_header, 200] self.assertCountEqual(real_result, expected_result) + def test_parse_type_two_error(self): + + self.detection = { + "type": 2, + "payload": { + "page": "/index.html", + "value": "test" + } + } + meta_content = {"/index.html": {}} + self.handler = TannerHandler(self.args, meta_content, self.uuid) + self.expected_content = b'
test
' + self.content_type = r'text\html' + + async def test(): + (self.res1, self.res2, + self.res3, self.res4) = await self.handler.parse_tanner_response(self.requested_name, self.detection) + + self.loop.run_until_complete(test()) + real_result = [self.res1, self.res2, self.res3, self.res4] + expected_result = [self.expected_content, self.content_type, {}, 200] + self.assertCountEqual(real_result, expected_result) + def test_parse_type_three(self): self.detection = { "type": 3, @@ -131,17 +185,5 @@ async def test(): self.loop.run_until_complete(test()) self.handler.html_handler.handle_content.assert_called_with(self.call_content) - def test_parse_exception(self): - self.detection = {} - self.call_content = b'' - self.expected_content = self.page_content - - async def test(): - (self.res1, self.res2, - self.res3, self.res4) = await self.handler.parse_tanner_response(self.requested_name, self.detection) - - with self.assertRaises(KeyError): - self.loop.run_until_complete(test()) - def tearDown(self): shutil.rmtree(self.main_page_path)