Commit ecf73383 by fwkz

Fixing tests.

parent c00f4c3b
......@@ -270,7 +270,9 @@ class RoutersploitInterpreter(BaseInterpreter):
module = importlib.import_module(module_path)
self.current_module = getattr(module, 'Exploit')()
except (ImportError, AttributeError, KeyError):
utils.print_error("Error '{}'. It should be valid path to the module. Use <tab> key multiple times for completion.".format(utils.humanize_path(module_path)))
utils.print_error("Error during loading '{}' module. "
"It should be valid path to the module. "
"Use <tab> key multiple times for completion.".format(utils.humanize_path(module_path)))
@utils.stop_after(2)
def complete_use(self, text, *args, **kwargs):
......@@ -329,7 +331,7 @@ class RoutersploitInterpreter(BaseInterpreter):
if sub_command == info:
info = ["name", "description", "targets", "authors", "references"]
for i in info:
for i in info: # TODO refactor this.
if i in self.module_metadata.keys():
print("\n{}:".format(i.capitalize()))
if type(self.module_metadata[i]) is list:
......
......@@ -8,7 +8,7 @@ class RoutersploitCompleterTest(unittest.TestCase):
def __init__(self, methodName='runTest'):
super(RoutersploitCompleterTest, self).__init__(methodName)
self.cli_path = os.path.abspath(os.path.join(__file__, os.pardir, os.pardir, os.pardir, 'cli.py'))
self.cli_path = os.path.abspath(os.path.join(__file__, os.pardir, os.pardir, os.pardir, 'rsf.py'))
self.raw_prompt = "\033[4mrsf\033[0m > "
self.module_prompt = lambda x: "\033[4mrsf\033[0m (\033[91m{}\033[0m) > ".format(x)
......@@ -39,7 +39,7 @@ class RoutersploitCompleterTest(unittest.TestCase):
def test_complete_use(self):
self.rsf.send("use \t\t")
self.assertPrompt(
'creds exploits \r\n',
'creds exploits scanners \r\n',
self.raw_prompt,
'use '
)
......
......@@ -244,7 +244,7 @@ class RoutersploitInterpreterTest(unittest.TestCase):
@mock.patch('importlib.import_module')
@mock.patch('routersploit.utils.print_error')
def test_command_unknown_extension(self, mocked_print_error, mocked_import_module):
def test_command_unknown_module(self, mocked_print_error, mocked_import_module):
""" Testing command_use()
* Unknown module
......@@ -256,8 +256,10 @@ class RoutersploitInterpreterTest(unittest.TestCase):
self.interpreter.command_use(module_path)
mocked_import_module.assert_called_once_with('routersploit.modules.creds.foo.bar')
mocked_print_error.assert_called_once_with("Error during loading 'routersploit/modules/creds/foo/bar' module")
mocked_import_module.assert_called_once_with('routersploit.modules.creds.foo.bar.baz')
mocked_print_error.assert_called_once_with("Error during loading 'routersploit/modules/creds/foo/bar/baz' "
"module. It should be valid path to the module. "
"Use <tab> key multiple times for completion.")
self.assertEqual(self.interpreter.current_module, None)
@mock.patch('importlib.import_module')
......@@ -277,17 +279,19 @@ class RoutersploitInterpreterTest(unittest.TestCase):
self.interpreter.command_use(module_path)
mocked_import_module.assert_called_once_with('routersploit.modules.exploits.foo.bar')
mocked_print_error.assert_called_once_with("Error during loading 'routersploit/modules/exploits/foo/bar' module")
mocked_print_error.assert_called_once_with("Error during loading 'routersploit/modules/exploits/foo/bar' "
"module. It should be valid path to the module. "
"Use <tab> key multiple times for completion.")
self.assertEqual(self.interpreter.current_module, None)
@mock.patch('__builtin__.print')
def test_command_show_info(self, mock_print):
metadata = {
'target': 'target_desc',
'port': 'port_desc',
'foo': 'foo_desc',
'bar': 'bar_desc',
'baz': 'baz_desc'
'targets': 'target_desc',
'authors': 'authors_desc',
'references': 'references_desc',
'description': 'description_desc',
'name': 'name_desc'
}
description = "Elaborate description fo the module"
self.interpreter.current_module.__doc__ = description
......@@ -297,12 +301,16 @@ class RoutersploitInterpreterTest(unittest.TestCase):
self.assertEqual(
mock_print.mock_calls,
[
mock.call(description),
mock.call('Baz', ': ', 'baz_desc', sep=''),
mock.call('Foo', ': ', 'foo_desc', sep=''),
mock.call('Bar', ': ', 'bar_desc', sep=''),
mock.call('Target', ': ', 'target_desc', sep=''),
mock.call('Port', ': ', 'port_desc', sep=''),
mock.call('\nName:'),
mock.call('name_desc'),
mock.call('\nDescription:'),
mock.call('description_desc'),
mock.call('\nTargets:'),
mock.call('target_desc'),
mock.call('\nAuthors:'),
mock.call('authors_desc'),
mock.call('\nReferences:'),
mock.call('references_desc'),
mock.call()]
)
......@@ -317,7 +325,6 @@ class RoutersploitInterpreterTest(unittest.TestCase):
self.assertEqual(
mock_print.mock_calls,
[
mock.call(description),
mock.call()]
)
......@@ -343,18 +350,22 @@ class RoutersploitInterpreterTest(unittest.TestCase):
self.assertEqual(
mock_print.mock_calls,
[
mock.call('\nTarget options:\n'),
mock.call('\nTarget options:'),
mock.call(),
mock.call(' Name Current settings Description '),
mock.call(' ---- ---------------- ----------- '),
mock.call(' target 127.0.0.1 target_desc '),
mock.call(' port 22 port_desc '),
mock.call('\nModule options:\n'),
mock.call(),
mock.call('\nModule options:'),
mock.call(),
mock.call(' Name Current settings Description '),
mock.call(' ---- ---------------- ----------- '),
mock.call(' bar 2 bar_desc '),
mock.call(' foo 1 foo_desc '),
mock.call(' baz 3 baz_desc '),
mock.call(),
mock.call(),
]
)
......@@ -374,12 +385,14 @@ class RoutersploitInterpreterTest(unittest.TestCase):
self.assertEqual(
mock_print.mock_calls,
[
mock.call('\nTarget options:\n'),
mock.call('\nTarget options:'),
mock.call(),
mock.call(' Name Current settings Description '),
mock.call(' ---- ---------------- ----------- '),
mock.call(' target 127.0.0.1 target_desc '),
mock.call(' port 22 port_desc '),
mock.call(),
mock.call(),
]
)
......
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