[relay] Calls: a long-poll on the fetch route, TURN credentials for coturn, wakes every 10 s; the module passes the TURN secret by systemd credential

This commit is contained in:
2026-12-03 00:29:07 +01:00
parent 1e2eed8e5b
commit 776e4ce39b
15 changed files with 654 additions and 22 deletions
+16
View File
@@ -12,6 +12,15 @@ pkgs.testers.runNixOSTest {
enable = true;
domain = "relay.test";
maxMailboxes = 3;
# Calls (calls-relay.md): the TURN route, with a secret made at boot, never in the repository or the store.
turn.secretFile = "/run/turn-test/secret";
turn.urls = [ "turn:relay.test:3478?transport=udp" ];
};
systemd.services.turn-test-secret = {
wantedBy = [ "tabellarius.service" ];
before = [ "tabellarius.service" ];
serviceConfig.Type = "oneshot";
script = "install -d -m 0700 /run/turn-test && head -c 32 /dev/urandom | base64 > /run/turn-test/secret";
};
# No Let's Encrypt inside a VM: Caddy's own CA instead.
services.caddy.virtualHosts."relay.test".extraConfig = lib.mkBefore "tls internal";
@@ -65,6 +74,10 @@ pkgs.testers.runNixOSTest {
assert call("GET", "/v0/mailboxes/" + mid + "/blobs", token=fetch) == "200"
digest = b64(hashlib.sha256(blob.encode()).digest())
assert call("DELETE", "/v0/mailboxes/" + mid + "/blobs/" + digest, token=fetch) == "204"
# Calls: TURN credentials for the fetch token only; a long-poll with nothing arriving answers after its wait.
assert call("POST", "/v0/mailboxes/" + mid + "/turn", token=fetch) == "200"
assert call("POST", "/v0/mailboxes/" + mid + "/turn", token=post) == "404"
assert call("GET", "/v0/mailboxes/" + mid + "/blobs?wait=1", token=fetch) == "200"
# Refusals: a wrong token, a malformed id, a body that is not JSON.
assert call("GET", "/v0/mailboxes/" + mid + "/blobs", token=b64(os.urandom(32))) == "404"
assert call("GET", "/v0/mailboxes/nonsense/blobs", token=fetch) == "404"
@@ -78,5 +91,8 @@ pkgs.testers.runNixOSTest {
server.succeed("journalctl --sync")
server.fail("journalctl --no-pager -o verbose | grep -F '" + client_ip + "'")
server.fail("grep -rF '" + client_ip + "' /var/log /var/lib/private/tabellarius")
# The TURN secret reached the relay through systemd's credentials, never its database.
secret = server.succeed("cat /run/turn-test/secret").strip()
server.fail("grep -rF '" + secret + "' /var/lib/private/tabellarius /var/log")
'';
}