Files
sshecret/tests/packages/sshd/test_help.py
2025-05-18 21:34:46 +02:00

46 lines
1.5 KiB
Python

"""Test the help command."""
import re
import allure
import pytest
from .types import ClientRegistry, CommandRunner
@allure.title("Test the help command.")
@pytest.mark.asyncio
async def test_help_command(ssh_command_runner: CommandRunner, client_registry: ClientRegistry) -> None:
"""Run the help command and verify the output."""
await client_registry["add_client"]("test-client", ["mysecret"])
result = await ssh_command_runner("test-client", "help")
assert result.exit_status == 0
assert isinstance(result.stdout, str)
re_cmd = re.compile(r"^\s{2}([^\s]+)\s.*", re.MULTILINE)
commands = re_cmd.findall(result.stdout)
expected = ['get_secret', 'ls', 'ping']
assert commands == expected
print(result.stdout)
@allure.title("Test the help command with registration enabled.")
@pytest.mark.enable_registration(True)
@pytest.mark.asyncio
async def test_help_registration_command(ssh_command_runner: CommandRunner, client_registry: ClientRegistry) -> None:
"""Run the help command and verify the output."""
await client_registry["add_client"]("test-client", ["mysecret"])
result = await ssh_command_runner("test-client", "help")
assert result.exit_status == 0
assert isinstance(result.stdout, str)
re_cmd = re.compile(r"^\s{2}([^\s]+)\s.*", re.MULTILINE)
commands = re_cmd.findall(result.stdout)
expected = ["get_secret", "ls", "register", "ping"]
assert sorted(commands) == sorted(expected)
print(result.stdout)