57 lines
1.7 KiB
Python
57 lines
1.7 KiB
Python
"""Test get secret."""
|
|
|
|
import allure
|
|
import pytest
|
|
|
|
from .types import ClientRegistry, CommandRunner
|
|
|
|
|
|
@allure.title("Test get_secret command")
|
|
@pytest.mark.asyncio
|
|
async def test_get_secret(
|
|
ssh_command_runner: CommandRunner, client_registry: ClientRegistry
|
|
) -> None:
|
|
"""Test that we can get a secret."""
|
|
|
|
await client_registry["add_client"]("test-client", ["mysecret"])
|
|
|
|
result = await ssh_command_runner("test-client", "get_secret mysecret")
|
|
|
|
assert result.stdout is not None
|
|
assert isinstance(result.stdout, str)
|
|
assert result.stdout.rstrip() == "mocked-secret-mysecret"
|
|
|
|
@allure.title("Test with invalid secret name")
|
|
@pytest.mark.asyncio
|
|
async def test_invalid_secret_name(
|
|
ssh_command_runner: CommandRunner, client_registry: ClientRegistry
|
|
) -> None:
|
|
"""Test getting an invalid secret name."""
|
|
|
|
await client_registry["add_client"]("test-client")
|
|
|
|
result = await ssh_command_runner("test-client", "get_secret mysecret")
|
|
assert result.exit_status == 1
|
|
stderr = result.stderr
|
|
assert isinstance(stderr, str)
|
|
assert stderr.rstrip() == "Error: No secret available with the given name."
|
|
|
|
@allure.title("Test get_secret command help")
|
|
@pytest.mark.asyncio
|
|
async def test_get_secret_cmd_help(ssh_command_runner: CommandRunner, client_registry: ClientRegistry) -> None:
|
|
"""Test running get_secret --help"""
|
|
await client_registry["add_client"]("test-client", ["mysecret"])
|
|
|
|
result = await ssh_command_runner("test-client", "get_secret --help")
|
|
|
|
assert result.exit_status == 0
|
|
|
|
print(result.stdout)
|
|
assert isinstance(result.stdout, str)
|
|
|
|
lines = result.stdout.splitlines()
|
|
|
|
assert lines[0] == "get_secret SECRET"
|
|
|
|
assert len(lines) > 4
|