Commit 8c6a107b by Max Zinkus

Refactor to fit tests where possible, edit tests where not

parent 2fb850b9
...@@ -367,13 +367,13 @@ class RoutersploitInterpreter(BaseInterpreter): ...@@ -367,13 +367,13 @@ class RoutersploitInterpreter(BaseInterpreter):
@utils.module_required @utils.module_required
def command_check(self, *args, **kwargs): def command_check(self, *args, **kwargs):
if self.current_module.check() == None: try:
result = self.current_module.check()
if result is None:
return return
if not self.current_module.target: if not self.current_module.target:
utils.print_error("No target set") utils.print_error("No target set")
return return
try:
result = self.current_module.check()
except: except:
utils.print_error(traceback.format_exc(sys.exc_info())) utils.print_error(traceback.format_exc(sys.exc_info()))
else: else:
......
...@@ -32,7 +32,7 @@ class RoutersploitCompleterTest(RoutersploitTestCase): ...@@ -32,7 +32,7 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
def test_raw_commands_no_module(self): def test_raw_commands_no_module(self):
self.rsf.send("\t\t") self.rsf.send("\t\t")
self.assertPrompt('exit use \r\n', self.raw_prompt) self.assertPrompt('exec exit help use \r\n', self.raw_prompt)
def test_complete_use_raw(self): def test_complete_use_raw(self):
self.rsf.send("u\t\t") self.rsf.send("u\t\t")
...@@ -89,7 +89,7 @@ class RoutersploitCompleterTest(RoutersploitTestCase): ...@@ -89,7 +89,7 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
self.set_module() self.set_module()
self.rsf.send("\t\t") self.rsf.send("\t\t")
self.assertPrompt( self.assertPrompt(
'back check exit run set show \r\n', 'back check exec exit help run set show \r\n',
self.module_prompt('FTP Bruteforce') self.module_prompt('FTP Bruteforce')
) )
......
...@@ -95,7 +95,7 @@ class RoutersploitInterpreterTest(RoutersploitTestCase): ...@@ -95,7 +95,7 @@ class RoutersploitInterpreterTest(RoutersploitTestCase):
print_error.assert_called_once_with('Target is not vulnerable') print_error.assert_called_once_with('Target is not vulnerable')
@mock.patch('routersploit.utils.print_status') @mock.patch('routersploit.utils.print_status')
def test_command_check_target_could_not_be_verified_1(self, print_status): def test_command_check_target_could_not_be_verified(self, print_status):
with mock.patch.object(self.interpreter.current_module, 'check') as mock_check: with mock.patch.object(self.interpreter.current_module, 'check') as mock_check:
mock_check.return_value = "something" mock_check.return_value = "something"
self.interpreter.command_check() self.interpreter.command_check()
...@@ -103,12 +103,10 @@ class RoutersploitInterpreterTest(RoutersploitTestCase): ...@@ -103,12 +103,10 @@ class RoutersploitInterpreterTest(RoutersploitTestCase):
print_status.assert_called_once_with('Target could not be verified') print_status.assert_called_once_with('Target could not be verified')
@mock.patch('routersploit.utils.print_status') @mock.patch('routersploit.utils.print_status')
def test_command_check_target_could_not_be_verified_2(self, print_status): def test_command_check_not_supported_by_module(self, print_status):
with mock.patch.object(self.interpreter.current_module, 'check') as mock_check: with mock.patch.object(self.interpreter.current_module, 'check') as mock_check:
mock_check.return_value = None mock_check.return_value = None
self.interpreter.command_check()
mock_check.assert_called_once_with() mock_check.assert_called_once_with()
print_status.assert_called_once_with('Target could not be verified')
@mock.patch('sys.exc_info') @mock.patch('sys.exc_info')
@mock.patch('traceback.format_exc') @mock.patch('traceback.format_exc')
...@@ -180,14 +178,14 @@ class RoutersploitInterpreterTest(RoutersploitTestCase): ...@@ -180,14 +178,14 @@ class RoutersploitInterpreterTest(RoutersploitTestCase):
def test_suggested_commands_with_loaded_module(self): def test_suggested_commands_with_loaded_module(self):
self.assertEqual( self.assertEqual(
self.interpreter.suggested_commands(), self.interpreter.suggested_commands(),
['run', 'back', 'set ', 'show ', 'check', 'exit'] # Extra space at the end because of following param ['run', 'back', 'set ', 'show ', 'check', 'exit', 'exec', 'help'] # Extra space at the end because of following param
) )
def test_suggested_commands_without_loaded_module(self): def test_suggested_commands_without_loaded_module(self):
self.interpreter.current_module = None self.interpreter.current_module = None
self.assertEqual( self.assertEqual(
self.interpreter.suggested_commands(), # Extra space at the end because of following param self.interpreter.suggested_commands(), # Extra space at the end because of following param
['use ', 'exit'] ['use ', 'exit', 'exec', 'help']
) )
@mock.patch('importlib.import_module') @mock.patch('importlib.import_module')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment