diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 58bbf8c80a78..90e53e45500e 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -1594,6 +1594,7 @@ in tzupdate = runTest ./tzupdate.nix; ucarp = runTest ./ucarp.nix; udisks2 = runTest ./udisks2.nix; + udp-over-tcp = runTest ./udp-over-tcp.nix; ulogd = runTest ./ulogd/ulogd.nix; umami = runTest ./web-apps/umami.nix; umurmur = runTest ./umurmur.nix; diff --git a/nixos/tests/udp-over-tcp.nix b/nixos/tests/udp-over-tcp.nix new file mode 100644 index 000000000000..2f53cffeae86 --- /dev/null +++ b/nixos/tests/udp-over-tcp.nix @@ -0,0 +1,61 @@ +{ lib, ... }: +{ + name = "udp-over-tcp"; + meta.maintainers = [ lib.maintainers.timschumi ]; + + nodes.sender = + { nodes, ... }: + { + services.udp-over-tcp = { + udp2tcp = { + "0.0.0.0:51821" = { + forward = "${nodes.receiver.networking.primaryIPAddress}:444"; + openFirewall = true; + + # Remaining options are not tested for behavior, but to cover options passing. + recvBufferSize = 16384; + sendBufferSize = 16384; + recvTimeout = 10; + fwmark = 1337; + nodelay = true; + }; + }; + }; + }; + + nodes.receiver = + { nodes, ... }: + { + services.udp-over-tcp = { + tcp2udp = { + "0.0.0.0:444" = { + forward = "127.0.0.1:51821"; + openFirewall = true; + + # Remaining options are not tested for behavior, but to cover options passing. + threads = 2; + bind = "127.0.0.1"; + recvBufferSize = 16384; + sendBufferSize = 16384; + recvTimeout = 10; + fwmark = 1337; + nodelay = true; + }; + }; + }; + }; + + testScript = '' + start_all() + + # TODO: Replace unit wait with waiting on an UDP port. + sender.wait_for_unit("udp2tcp-0.0.0.0:51821.service") + receiver.wait_for_open_port(444, "0.0.0.0") + + receiver.succeed("nc -w 10 -u -l 127.0.0.1 51821 > transfer.txt &") + # We need to delay a short time here because detaching exits the shell before the socket is ready. + receiver.execute("sleep 1") + sender.succeed("echo 'Hello World!' | nc -w 1 -u 127.0.0.1 51821") + receiver.succeed("grep 'Hello World!' transfer.txt") + ''; +} diff --git a/pkgs/by-name/ud/udp-over-tcp/package.nix b/pkgs/by-name/ud/udp-over-tcp/package.nix index ce713befb818..3f16a146ae84 100644 --- a/pkgs/by-name/ud/udp-over-tcp/package.nix +++ b/pkgs/by-name/ud/udp-over-tcp/package.nix @@ -1,6 +1,7 @@ { fetchFromGitHub, lib, + nixosTests, rustPlatform, }: rustPlatform.buildRustPackage (finalAttrs: { @@ -21,6 +22,10 @@ rustPlatform.buildRustPackage (finalAttrs: { "clap" ]; + passthru.tests = { + inherit (nixosTests) udp-over-tcp; + }; + meta = { homepage = "https://github.com/mullvad/udp-over-tcp"; description = "Proxy UDP traffic over a TCP stream";