test(root_daemon): looping

This commit is contained in:
Houkime 2024-12-11 18:55:06 +00:00
parent 32f8a803e8
commit 76d83c41cf
3 changed files with 11 additions and 13 deletions

View file

@ -114,21 +114,18 @@ def _process_request(request: str, allowed_commands: str) -> str:
def _root_loop(socket: socket_module.socket, allowed_commands):
socket.listen(1)
# in seconds
socket.settimeout(1.0) # we do it so that we can throw exceptions into the loop
# XXX
socket.settimeout(6.0)
while True:
try:
conn, addr = socket.accept()
except TimeoutError:
raise ValueError("nooo, there was a timeout!")
continue
conn, addr = socket.accept()
pipe = conn.makefile("rw")
# We accept a single line per connection for simplicity and safety
line = pipe.readline()
request = line.strip()
answer = _process_request(request, allowed_commands)
conn.send(answer.encode("utf-8"))
pipe.close()
conn.close()

View file

@ -21,6 +21,7 @@ def _write_to_daemon_socket(cmd: List[str]) -> str:
payload = " ".join(cmd).encode("utf-8") + b"\n"
sock.send(payload)
pipe = sock.makefile("r")
line = pipe.readline()
sleep(2)
return line
answer = pipe.readline()
pipe.close()
sock.close()
return answer

View file

@ -61,7 +61,7 @@ def test_send_command():
answer = call_root_function(["blabla"])
assert answer == "not permitted"
# confirm the loop
# answer = call_root_function(["blabla"])
# assert answer == "not permitted"
answer = call_root_function(["blabla"])
assert answer == "not permitted"
proc.kill()