diff --git a/secator/cli.py b/secator/cli.py index 0fe96680..377896b2 100644 --- a/secator/cli.py +++ b/secator/cli.py @@ -871,7 +871,12 @@ def health(json, debug, strict): table = get_health_table() with Live(table, console=console): for tool in tools: - info = get_version_info(tool.cmd.split(' ')[0], tool.version_flag, tool.install_github_handle, tool.install_cmd) + info = get_version_info( + tool.cmd.split(' ')[0], + tool.version_flag or f'{tool.opt_prefix}version', + tool.install_github_handle, + tool.install_cmd + ) row = fmt_health_table_row(info, 'tools') table.add_row(*row) status['tools'][tool.__name__] = info diff --git a/secator/installer.py b/secator/installer.py index 4dc7b95a..d9f5e1d7 100644 --- a/secator/installer.py +++ b/secator/installer.py @@ -295,7 +295,7 @@ def parse_version(ver): return None -def get_version_info(name, version_flag, install_github_handle=None, install_cmd=None, version=None, opt_prefix='--'): +def get_version_info(name, version_flag=None, install_github_handle=None, install_cmd=None, version=None): """Get version info for a command. Args: @@ -304,7 +304,6 @@ def get_version_info(name, version_flag, install_github_handle=None, install_cmd install_github_handle (str): Github handle. install_cmd (str): Install command. version (str): Existing version. - opt_prefix (str, default: '--'): Option prefix. Return: dict: Version info. @@ -353,7 +352,7 @@ def get_version_info(name, version_flag, install_github_handle=None, install_cmd # Get current version version_ret = 1 - version_flag = None if version_flag == OPT_NOT_SUPPORTED else version_flag or f'{opt_prefix}version' + version_flag = None if version_flag == OPT_NOT_SUPPORTED else version_flag if version_flag: version_cmd = f'{name} {version_flag}' version, version_ret = get_version(version_cmd) diff --git a/tests/unit/test_cli.py b/tests/unit/test_cli.py new file mode 100644 index 00000000..e7f6c78c --- /dev/null +++ b/tests/unit/test_cli.py @@ -0,0 +1,94 @@ +from click.testing import CliRunner + +from secator.cli import cli + +import unittest + + +class TestCli(unittest.TestCase): + + def setUp(self): + self.runner = CliRunner() + + def test_cli_version(self): + result = self.runner.invoke(cli, ['--version']) + assert not result.exception + assert result.exit_code == 0 + assert 'Current version' in result.output + + def test_task_command(self): + result = self.runner.invoke(cli, ['task']) + assert not result.exception + assert result.exit_code == 0 + assert 'Run a task.' in result.output + + def test_workflow_command(self): + result = self.runner.invoke(cli, ['workflow']) + assert not result.exception + assert result.exit_code == 0 + assert 'Run a workflow.' in result.output + + def test_scan_command(self): + result = self.runner.invoke(cli, ['scan']) + assert not result.exception + assert result.exit_code == 0 + assert 'Run a scan.' in result.output + + # def test_worker_command(self): + # result = self.runner.invoke(cli, ['worker', '--check']) + # assert not result.exception + # assert result.exit_code == 0 + # # Add more assertions based on expected output + + def test_util_proxy_command(self): + result = self.runner.invoke(cli, ['util', 'proxy', '--timeout', '0.5', '--number', '2']) + assert not result.exception + assert result.exit_code == 0 + # Add more assertions based on expected output + + def test_util_revshell_command(self): + result = self.runner.invoke(cli, ['util', 'revshell', '--host', '127.0.0.1', '--port', '9001']) + assert not result.exception + assert result.exit_code == 0 + # Add more assertions based on expected output + + # def test_util_serve_command(self): + # result = self.runner.invoke(cli, ['util', 'serve', '--directory', '.', '--port', '8000']) + # assert not result.exception + # assert result.exit_code == 0 + # # Add more assertions based on expected output + + def test_config_get_command(self): + result = self.runner.invoke(cli, ['config', 'get']) + assert not result.exception + assert result.exit_code == 0 + # Add more assertions based on expected output + + def test_config_set_command(self): + result = self.runner.invoke(cli, ['config', 'set', 'key', 'value']) + assert not result.exception + assert result.exit_code == 0 + # Add more assertions based on expected output + + def test_report_show_command(self): + result = self.runner.invoke(cli, ['report', 'show']) + assert not result.exception + assert result.exit_code == 0 + # Add more assertions based on expected output + + def test_install_addons_worker_command(self): + result = self.runner.invoke(cli, ['install', 'addons', 'worker']) + assert not result.exception + assert result.exit_code == 0 + # Add more assertions based on expected output + + def test_health_command(self): + result = self.runner.invoke(cli, ['health']) + assert not result.exception + assert result.exit_code == 0 + # Add more assertions based on expected output + + # Add more tests for other commands as needed + +if __name__ == '__main__': + unittest.main()