From ef0c09eb7651b9d9f4e60a27036e542b9cab71c6 Mon Sep 17 00:00:00 2001 From: parth Date: Sun, 8 Mar 2020 19:41:41 +0530 Subject: [PATCH] Added tests for `Cloner.add_schema` Handled the case when there is no proper host provided and also added tests for the cases when host provided has length less than 4 which indicates no proper domain was provided. Refs #187 --- snare/cloner.py | 2 +- snare/tests/test_cloner_add_scheme.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/snare/cloner.py b/snare/cloner.py index 457c795e..42017daa 100644 --- a/snare/cloner.py +++ b/snare/cloner.py @@ -21,7 +21,7 @@ def __init__(self, root, max_depth, css_validate): self.root, self.error_page = self.add_scheme(root) self.max_depth = max_depth self.moved_root = None - if len(self.root.host) < 4: + if (self.root.host is None) or (len(self.root.host) < 4): sys.exit('invalid target {}'.format(self.root.host)) self.target_path = '/opt/snare/pages/{}'.format(self.root.host) if not os.path.exists(self.target_path): diff --git a/snare/tests/test_cloner_add_scheme.py b/snare/tests/test_cloner_add_scheme.py index 84715ddb..1156a64b 100644 --- a/snare/tests/test_cloner_add_scheme.py +++ b/snare/tests/test_cloner_add_scheme.py @@ -38,3 +38,13 @@ def test_no_scheme(self): def tearDown(self): shutil.rmtree(self.main_page_path) + + def test_no_host(self): + self.url = 'http:/' + with self.assertRaises(SystemExit): + Cloner(self.url, self.max_depth, self.css_validate) + + def test_limited_lenght_host(self): + self.url = 'http://aaa' + with self.assertRaises(SystemExit): + Cloner(self.url, self.max_depth, self.css_validate)