Complete sshd package with tests
This commit is contained in:
34
packages/sshecret-sshd/tests/test_register.py
Normal file
34
packages/sshecret-sshd/tests/test_register.py
Normal file
@ -0,0 +1,34 @@
|
||||
"""Test registration."""
|
||||
import pytest
|
||||
|
||||
from .types import ClientRegistry, CommandRunner, ProcessRunner
|
||||
|
||||
@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
|
||||
l = 0
|
||||
found = False
|
||||
while l < 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"
|
||||
Reference in New Issue
Block a user