diff --git a/selfprivacy_api/root_daemon.py b/selfprivacy_api/root_daemon.py index cb3c470..7b4286e 100644 --- a/selfprivacy_api/root_daemon.py +++ b/selfprivacy_api/root_daemon.py @@ -101,14 +101,14 @@ def _process_request(request: str, allowed_commands: str) -> str: if request == command: # explicitly only calling a _hardcoded_ command # ever - # test mode made like this does not make it more dangerous too + # test mode made like this does not mae it more dangerous too raise ValueError("Oh no") if get_test_mode(): _spawn_shell(f'echo "{command}"') else: _spawn_shell(command) else: - return "-1" + return "not permitted" def _root_loop(socket: socket_module.socket, allowed_commands): @@ -120,7 +120,9 @@ def _root_loop(socket: socket_module.socket, allowed_commands): try: conn, addr = socket.accept() except TimeoutError: + raise ValueError("nooo, there was a timeout!") continue + pipe = conn.makefile("rw") # We accept a single line per connection for simplicity and safety line = pipe.readline() diff --git a/selfprivacy_api/utils/root_interface.py b/selfprivacy_api/utils/root_interface.py index 5099467..ba5626b 100644 --- a/selfprivacy_api/utils/root_interface.py +++ b/selfprivacy_api/utils/root_interface.py @@ -1,4 +1,5 @@ from typing import List +from time import sleep # from subprocess import check_output from selfprivacy_api.root_daemon import SOCKET_PATH, socket_module @@ -6,10 +7,8 @@ from tests.test_common import get_test_mode def call_root_function(cmd: List[str]) -> str: - if get_test_mode(): - return "done" - else: - return _call_root_daemon(cmd) + assert isinstance(cmd, List) + return _call_root_daemon(cmd) def _call_root_daemon(cmd: List[str]) -> str: @@ -19,7 +18,9 @@ def _call_root_daemon(cmd: List[str]) -> str: def _write_to_daemon_socket(cmd: List[str]) -> str: sock = socket_module.socket(socket_module.AF_UNIX, socket_module.SOCK_STREAM) sock.connect(SOCKET_PATH) - sock.send(" ".join(cmd).encode("utf-8") + b"\n") - pipe = sock.makefile("rw") + payload = " ".join(cmd).encode("utf-8") + b"\n" + sock.send(payload) + pipe = sock.makefile("r") line = pipe.readline() + sleep(2) return line diff --git a/tests/test_root_daemon.py b/tests/test_root_daemon.py index a493f63..167c1e7 100644 --- a/tests/test_root_daemon.py +++ b/tests/test_root_daemon.py @@ -58,10 +58,10 @@ def test_send_command(): finished = proc.poll() assert finished is None - # thread = threading.Thread(target=start_root_daemon,args=[]) - # thread.start() - answer = call_root_function("blabla") - assert answer == "done" + answer = call_root_function(["blabla"]) + assert answer == "not permitted" + # confirm the loop + # answer = call_root_function(["blabla"]) + # assert answer == "not permitted" proc.kill() - # thread.join(timeout=1.0)