42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
"""Test registration."""
|
|
|
|
import pytest
|
|
|
|
from .types import ClientRegistry, CommandRunner, ProcessRunner
|
|
|
|
|
|
@pytest.mark.enable_registration(True)
|
|
@pytest.mark.asyncio
|
|
async def test_register_client(
|
|
ssh_session: ProcessRunner,
|
|
ssh_command_runner: CommandRunner,
|
|
client_registry: ClientRegistry,
|
|
) -> None:
|
|
"""Test client registration."""
|
|
await client_registry["add_client"]("template", ["testsecret"])
|
|
|
|
public_key = client_registry["clients"]["template"].public_key.rstrip() + "\n"
|
|
|
|
async with ssh_session("newclient", "register", "template") as session:
|
|
maxlines = 10
|
|
linenum = 0
|
|
found = False
|
|
while linenum < maxlines:
|
|
line = await session.stdout.readline()
|
|
if "Enter public key" in line:
|
|
found = True
|
|
break
|
|
|
|
assert found is True
|
|
session.stdin.write(public_key)
|
|
result = await session.stdout.readline()
|
|
assert "OK" in result
|
|
|
|
# Test that we can connect
|
|
|
|
result = await ssh_command_runner("newclient", "get_secret testsecret")
|
|
|
|
assert result.stdout is not None
|
|
assert isinstance(result.stdout, str)
|
|
assert result.stdout.rstrip() == "mocked-secret-testsecret"
|