[client] Calls: four MLS kinds (call, callAnswer, callIce, callEnd) with the frame key in the offer; coturn in the NixOS module; Caddy's global logger mkDefault; v0.3.0
This commit is contained in:
+41
-7
@@ -1,12 +1,13 @@
|
||||
# `nix flake check` (Linux, KVM): two machines. `server` runs the module; `client` talks to it
|
||||
# through Caddy with TLS, does everything the protocol allows and some things it refuses, fills a
|
||||
# mailbox cap to its 507, and then the test fails if the client's address appears anywhere in the
|
||||
# server's journal or under /var/log, or in the relay's database (.agents/features/home-relay.md).
|
||||
# mailbox cap to its 507, relays a call's packets through coturn with credentials from the relay, and then
|
||||
# the test fails if the client's address appears anywhere in the server's journal, under /var/log, in the
|
||||
# relay's database or where coturn runs (.agents/features/home-relay.md, call-kinds.md).
|
||||
{ self, pkgs }:
|
||||
pkgs.testers.runNixOSTest {
|
||||
name = "tabellarius-relay-keeps-no-address";
|
||||
|
||||
nodes.server = { lib, ... }: {
|
||||
nodes.server = { config, lib, ... }: {
|
||||
imports = [ self.nixosModules.default ];
|
||||
services.tabellarius = {
|
||||
enable = true;
|
||||
@@ -15,10 +16,18 @@ pkgs.testers.runNixOSTest {
|
||||
# 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" ];
|
||||
# coturn with the same secret. The test network is private, so the client's range is let through here;
|
||||
# every other private range stays denied.
|
||||
turn.coturn.enable = true;
|
||||
turn.coturn.allowedPeerIps = [ "192.168.1.0-192.168.1.255" ];
|
||||
};
|
||||
# The VM's first NIC is QEMU's user network, which every node shares as 10.0.2.15: coturn listens and relays on
|
||||
# the test network only.
|
||||
services.coturn.listening-ips = [ config.networking.primaryIPAddress ];
|
||||
services.coturn.relay-ips = [ config.networking.primaryIPAddress ];
|
||||
systemd.services.turn-test-secret = {
|
||||
wantedBy = [ "tabellarius.service" ];
|
||||
before = [ "tabellarius.service" ];
|
||||
wantedBy = [ "tabellarius.service" "coturn.service" ];
|
||||
before = [ "tabellarius.service" "coturn.service" ];
|
||||
serviceConfig.Type = "oneshot";
|
||||
script = "install -d -m 0700 /run/turn-test && head -c 32 /dev/urandom | base64 > /run/turn-test/secret";
|
||||
};
|
||||
@@ -27,11 +36,14 @@ pkgs.testers.runNixOSTest {
|
||||
};
|
||||
|
||||
nodes.client = { pkgs, ... }: {
|
||||
environment.systemPackages = [ pkgs.curl pkgs.python3 ];
|
||||
# coturn for its test tools: turnutils_uclient (a TURN client) and turnutils_peer (the far end).
|
||||
environment.systemPackages = [ pkgs.curl pkgs.python3 pkgs.coturn ];
|
||||
# The peer answers the relayed packets on 3480/udp.
|
||||
networking.firewall.enable = false;
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
import base64, hashlib, json, os
|
||||
import base64, hashlib, json, os, re
|
||||
|
||||
def b64(raw):
|
||||
return base64.urlsafe_b64encode(raw).rstrip(b"=").decode()
|
||||
@@ -39,7 +51,10 @@ pkgs.testers.runNixOSTest {
|
||||
start_all()
|
||||
server.wait_for_unit("tabellarius.service")
|
||||
server.wait_for_unit("caddy.service")
|
||||
server.wait_for_unit("coturn.service")
|
||||
server.wait_for_open_port(443)
|
||||
# coturn listens on the test network only, not on localhost, which is where wait_for_open_port looks.
|
||||
server.wait_until_succeeds("ss -Hltn 'sport = :3478' | grep -q .")
|
||||
client.wait_for_unit("multi-user.target")
|
||||
|
||||
client_ip = client.succeed("ip -4 -o addr show dev eth1 | awk '{print $4}' | cut -d/ -f1").strip()
|
||||
@@ -77,6 +92,22 @@ pkgs.testers.runNixOSTest {
|
||||
# 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"
|
||||
creds = json.loads(client.succeed(
|
||||
"curl -sk --resolve relay.test:443:" + server_ip + " -X POST -H 'Authorization: Bearer " + fetch + "'"
|
||||
+ " https://relay.test/v0/mailboxes/" + mid + "/turn"))
|
||||
assert creds["urls"] == ["turn:relay.test:3478?transport=udp"], creds
|
||||
# coturn relays a call's packets for those credentials, to a peer on the client, and refuses a wrong password.
|
||||
client.succeed("turnutils_peer -L " + client_ip + " -p 3480 >/dev/null 2>&1 &")
|
||||
client.succeed("sleep 1")
|
||||
uclient = ("timeout 60 turnutils_uclient -n 10 -m 1 -l 120 -e " + client_ip + " -r 3480 -u '"
|
||||
+ creds["username"] + "' -w '{}' " + server_ip)
|
||||
out = client.succeed(uclient.format(creds["password"]) + " 2>&1")
|
||||
print(out)
|
||||
sent = re.search(r"tot_recv_msgs=(\d+)", out)
|
||||
assert sent and int(sent.group(1)) > 0, "no packet came back through coturn"
|
||||
refused = client.fail(uclient.format(b64(os.urandom(20))) + " 2>&1")
|
||||
assert "401" in refused, refused
|
||||
|
||||
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"
|
||||
@@ -91,6 +122,9 @@ 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")
|
||||
# Nor where coturn runs: its config and pid in /run, any temporary file.
|
||||
# -s: a missing directory must not turn a match into exit 2, which `fail` would accept.
|
||||
server.fail("grep -rsF '" + client_ip + "' /run/coturn /run/turnserver /tmp /var/tmp")
|
||||
# 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")
|
||||
|
||||
Reference in New Issue
Block a user