nixpkgs/nixos/tests/turn-rs.nix

64 lines
1.5 KiB
Nix
Raw Normal View History

{ pkgs, ... }:
{
name = "turn-rs";
nodes = {
server = {
virtualisation.vlans = [ 1 ];
networking = {
useNetworkd = true;
useDHCP = false;
firewall.enable = false;
};
2024-09-11 10:51:45 +08:00
systemd.network.networks."01-eth1" = {
name = "eth1";
networkConfig.Address = "10.0.0.1/24";
};
2024-09-11 10:51:45 +08:00
services.turn-rs = {
enable = true;
secretFile = pkgs.writeText "secret" ''
USER_1_CREDS="foobar"
'';
settings = {
turn = {
realm = "localhost";
interfaces = [
{
transport = "udp";
bind = "127.0.0.1:3478";
external = "127.0.0.1:3478";
}
{
transport = "tcp";
bind = "127.0.0.1:3478";
external = "127.0.0.1:3478";
}
];
2024-09-11 10:51:45 +08:00
};
auth.static_credentials.user1 = "$USER_1_CREDS";
2024-09-11 10:51:45 +08:00
};
};
};
};
2024-09-11 10:51:45 +08:00
testScript = # python
''
import json
2024-09-11 10:51:45 +08:00
start_all()
server.wait_for_unit('turn-rs.service')
server.wait_for_open_port(3000, "127.0.0.1")
2024-09-11 10:51:45 +08:00
info = server.succeed('curl http://localhost:3000/info')
jsonInfo = json.loads(info)
assert len(jsonInfo['interfaces']) == 2, f'Interfaces doesn\'t contain two entries:\n{json.dumps(jsonInfo, indent=2)}'
2024-09-11 10:51:45 +08:00
config = server.succeed('cat /run/turn-rs/config.toml')
assert 'foobar' in config, f'Secrets are not properly injected:\n{config}'
'';
}