Skip to content

Commit

Permalink
Added tests for Cloner.add_schema
Browse files Browse the repository at this point in the history
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 mushorg#187
  • Loading branch information
Parth1811 committed Mar 8, 2020
1 parent 2a10f1a commit ef0c09e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion snare/cloner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 10 additions & 0 deletions snare/tests/test_cloner_add_scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit ef0c09e

Please sign in to comment.