mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-14 04:55:07 +00:00
feat(service): add wait_for_approval and return the cache for a login with no prompt
A pair code shown in a log line never answers a prompt, so the server read that login as anonymous and kept the session cache.
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import logging
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
from unshackle.core.api.input_bridge import InputBridge
|
||||
from unshackle.core.service import Service
|
||||
|
||||
|
||||
def _service(bridge=None):
|
||||
return SimpleNamespace(log=logging.getLogger("test"), _input_bridge=bridge)
|
||||
|
||||
|
||||
def test_returns_the_first_value_check_gives():
|
||||
answers = iter([None, None, "token"])
|
||||
assert Service.wait_for_approval(_service(), "enter code", lambda: next(answers), timeout=5, interval=0) == "token"
|
||||
|
||||
|
||||
def test_times_out_when_check_never_gives_a_value():
|
||||
with pytest.raises(TimeoutError):
|
||||
Service.wait_for_approval(_service(), "enter code", lambda: None, timeout=0.05, interval=0.01)
|
||||
|
||||
|
||||
def test_stops_when_the_remote_session_is_cancelled():
|
||||
bridge = InputBridge()
|
||||
calls = []
|
||||
|
||||
def check():
|
||||
calls.append(1)
|
||||
bridge.cancel()
|
||||
|
||||
with pytest.raises(RuntimeError):
|
||||
Service.wait_for_approval(_service(bridge), "enter code", check, timeout=5, interval=0)
|
||||
assert len(calls) == 1
|
||||
Reference in New Issue
Block a user