mirror of
https://github.com/markqvist/rnsh.git
synced 2025-05-02 06:16:13 -04:00
Remove service name from aspects #12; minor tweaks
- Remove service name from RNS destination aspects. Service name now selects a suffix for the identity file and should only be supplied on the listener. The initiator only needs the destination hash of the listener to connect. - Show a spinner during link establishment on tty sessions - Attempt to catch and beautify exceptions on initiator
This commit is contained in:
parent
bd12efd7cf
commit
a07ce53bf9
7 changed files with 199 additions and 110 deletions
|
@ -41,10 +41,9 @@ def test_program_initiate_no_args():
|
|||
def test_program_initiate_dash_args():
|
||||
docopt_threw = False
|
||||
try:
|
||||
args = rnsh.args.Args(shlex.split("rnsh --config ~/Projects/rnsh/testconfig -s test -vvvvvvv a5f72aefc2cb3cdba648f73f77c4e887 -- -l"))
|
||||
args = rnsh.args.Args(shlex.split("rnsh --config ~/Projects/rnsh/testconfig -vvvvvvv a5f72aefc2cb3cdba648f73f77c4e887 -- -l"))
|
||||
assert not args.listen
|
||||
assert args.config == "~/Projects/rnsh/testconfig"
|
||||
assert args.service_name == "test"
|
||||
assert args.verbose == 7
|
||||
assert args.destination == "a5f72aefc2cb3cdba648f73f77c4e887"
|
||||
assert args.command_line == ["-l"]
|
||||
|
@ -53,6 +52,21 @@ def test_program_initiate_dash_args():
|
|||
assert not docopt_threw
|
||||
|
||||
|
||||
def test_program_listen_dash_args():
|
||||
docopt_threw = False
|
||||
try:
|
||||
args = rnsh.args.Args(shlex.split("rnsh -l --config ~/Projects/rnsh/testconfig -n -C -- /bin/pwd"))
|
||||
assert args.listen
|
||||
assert args.config == "~/Projects/rnsh/testconfig"
|
||||
assert args.destination is None
|
||||
assert args.no_auth
|
||||
assert args.no_remote_cmd
|
||||
assert args.command_line == ["/bin/pwd"]
|
||||
except docopt.DocoptExit:
|
||||
docopt_threw = True
|
||||
assert not docopt_threw
|
||||
|
||||
|
||||
def test_program_listen_config_print():
|
||||
docopt_threw = False
|
||||
try:
|
||||
|
|
|
@ -56,16 +56,18 @@ async def test_rnsh_listen_start_stop():
|
|||
assert not wrapper.process.running
|
||||
|
||||
|
||||
async def get_id_and_dest(td: str) -> tuple[str, str]:
|
||||
with tests.helpers.SubprocessReader(name="getid", argv=shlex.split(f"poetry run -- rnsh -l --config \"{td}\" -p")) as wrapper:
|
||||
async def get_listener_id_and_dest(td: str) -> tuple[str, str]:
|
||||
with tests.helpers.SubprocessReader(name="getid", argv=shlex.split(f"poetry run -- rnsh -l -c \"{td}\" -p")) as wrapper:
|
||||
wrapper.start()
|
||||
await asyncio.sleep(0.1)
|
||||
assert wrapper.process.running
|
||||
# wait for process to start up
|
||||
await tests.helpers.wait_for_condition_async(lambda: not wrapper.process.running, 5)
|
||||
assert not wrapper.process.running
|
||||
await asyncio.sleep(2)
|
||||
# read the output
|
||||
text = wrapper.read().decode("utf-8").replace("\r", "").replace("\n", "")
|
||||
assert text.index("Using service name \"default\"") is not None
|
||||
assert text.index("Identity") is not None
|
||||
match = re.search(r"<([a-f0-9]{32})>[^<]+<([a-f0-9]{32})>", text)
|
||||
assert match is not None
|
||||
|
@ -77,29 +79,58 @@ async def get_id_and_dest(td: str) -> tuple[str, str]:
|
|||
return ih, dh
|
||||
|
||||
|
||||
async def get_initiator_id(td: str) -> str:
|
||||
with tests.helpers.SubprocessReader(name="getid", argv=shlex.split(f"poetry run -- rnsh -c \"{td}\" -p")) as wrapper:
|
||||
wrapper.start()
|
||||
await asyncio.sleep(0.1)
|
||||
assert wrapper.process.running
|
||||
# wait for process to start up
|
||||
await tests.helpers.wait_for_condition_async(lambda: not wrapper.process.running, 5)
|
||||
assert not wrapper.process.running
|
||||
# read the output
|
||||
text = wrapper.read().decode("utf-8").replace("\r", "").replace("\n", "")
|
||||
assert text.index("Identity") is not None
|
||||
match = re.search(r"<([a-f0-9]{32})>", text)
|
||||
assert match is not None
|
||||
ih = match.group(1)
|
||||
assert len(ih) == 32
|
||||
await asyncio.sleep(0.1)
|
||||
return ih
|
||||
|
||||
|
||||
|
||||
@pytest.mark.skip_ci
|
||||
@pytest.mark.asyncio
|
||||
async def test_rnsh_get_id_and_dest() -> [int]:
|
||||
async def test_rnsh_get_listener_id_and_dest() -> [int]:
|
||||
with tests.helpers.tempdir() as td:
|
||||
ih, dh = await get_id_and_dest(td)
|
||||
ih, dh = await get_listener_id_and_dest(td)
|
||||
assert len(ih) == 32
|
||||
assert len(dh) == 32
|
||||
|
||||
|
||||
@pytest.mark.skip_ci
|
||||
@pytest.mark.asyncio
|
||||
async def test_rnsh_get_initiator_id() -> [int]:
|
||||
with tests.helpers.tempdir() as td:
|
||||
ih = await get_initiator_id(td)
|
||||
assert len(ih) == 32
|
||||
|
||||
|
||||
async def do_connected_test(listener_args: str, initiator_args: str, test: callable):
|
||||
with tests.helpers.tempdir() as td:
|
||||
ih, dh = await get_id_and_dest(td)
|
||||
ih, dh = await get_listener_id_and_dest(td)
|
||||
iih = await get_initiator_id(td)
|
||||
assert len(ih) == 32
|
||||
assert len(dh) == 32
|
||||
with tests.helpers.SubprocessReader(name="listener", argv=shlex.split(f"poetry run -- rnsh -l --config \"{td}\" {listener_args}")) as listener, \
|
||||
tests.helpers.SubprocessReader(name="initiator", argv=shlex.split(f"poetry run -- rnsh --config \"{td}\" {dh} {initiator_args}")) as initiator:
|
||||
assert len(iih) == 32
|
||||
with tests.helpers.SubprocessReader(name="listener", argv=shlex.split(f"poetry run -- rnsh -l -c \"{td}\" {listener_args}")) as listener, \
|
||||
tests.helpers.SubprocessReader(name="initiator", argv=shlex.split(f"poetry run -- rnsh -c \"{td}\" {dh} {initiator_args}")) as initiator:
|
||||
# listener startup
|
||||
listener.start()
|
||||
await asyncio.sleep(0.1)
|
||||
assert listener.process.running
|
||||
# wait for process to start up
|
||||
await asyncio.sleep(3)
|
||||
await asyncio.sleep(5)
|
||||
# read the output
|
||||
text = listener.read().decode("utf-8")
|
||||
assert text.index(dh) is not None
|
||||
|
@ -108,7 +139,7 @@ async def do_connected_test(listener_args: str, initiator_args: str, test: calla
|
|||
initiator.start()
|
||||
assert initiator.process.running
|
||||
|
||||
await test(td, ih, dh, listener, initiator)
|
||||
await test(td, ih, dh, iih, listener, initiator)
|
||||
|
||||
# expect test to shut down initiator
|
||||
assert not initiator.process.running
|
||||
|
@ -127,13 +158,13 @@ async def do_connected_test(listener_args: str, initiator_args: str, test: calla
|
|||
async def test_rnsh_get_echo_through():
|
||||
cwd = os.getcwd()
|
||||
|
||||
async def test(td: str, ih: str, dh: str, listener: tests.helpers.SubprocessReader,
|
||||
async def test(td: str, ih: str, dh: str, iih: str, listener: tests.helpers.SubprocessReader,
|
||||
initiator: tests.helpers.SubprocessReader):
|
||||
start_time = time.time()
|
||||
while initiator.return_code is None and time.time() - start_time < 3:
|
||||
await asyncio.sleep(0.1)
|
||||
text = initiator.read().decode("utf-8").replace("\r", "").replace("\n", "")
|
||||
assert text == cwd
|
||||
assert text[len(text)-len(cwd):] == cwd
|
||||
|
||||
await do_connected_test("-n -C -- /bin/pwd", "", test)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue