diff options
author | Nick Cao <nickcao@nichi.co> | 2023-06-27 12:58:10 +0800 |
---|---|---|
committer | Nick Cao <nickcao@nichi.co> | 2023-06-27 13:58:02 +0800 |
commit | e3d52286b139b7ba041fbb057fbc0a729377ed68 (patch) | |
tree | 1aee5c53aa91ea8db1ba9bafa753f614857ebea9 /nixos/tests/sing-box.nix | |
parent | d2483a8cc75f007d76e9eec97e75df677c53a433 (diff) |
nixos/sing-box: add basic test
Diffstat (limited to 'nixos/tests/sing-box.nix')
-rw-r--r-- | nixos/tests/sing-box.nix | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/nixos/tests/sing-box.nix b/nixos/tests/sing-box.nix new file mode 100644 index 0000000000000..43be89317642c --- /dev/null +++ b/nixos/tests/sing-box.nix @@ -0,0 +1,45 @@ +import ./make-test-python.nix ({ lib, pkgs, ... }: { + + name = "sing-box"; + + meta = { + maintainers = with lib.maintainers; [ nickcao ]; + }; + + nodes.machine = { pkgs, ... }: { + environment.systemPackages = [ pkgs.curl ]; + services.nginx.enable = true; + services.sing-box = { + enable = true; + settings = { + inbounds = [{ + type = "mixed"; + tag = "inbound"; + listen = "127.0.0.1"; + listen_port = 1080; + users = [{ + username = "user"; + password = { _secret = pkgs.writeText "password" "supersecret"; }; + }]; + }]; + outbounds = [{ + type = "direct"; + tag = "outbound"; + }]; + }; + }; + }; + + testScript = '' + machine.wait_for_unit("nginx.service") + machine.wait_for_unit("sing-box.service") + + machine.wait_for_open_port(80) + machine.wait_for_open_port(1080) + + machine.succeed("curl --fail --max-time 10 --proxy http://user:supersecret@localhost:1080 http://localhost") + machine.fail("curl --fail --max-time 10 --proxy http://user:supervillain@localhost:1080 http://localhost") + machine.succeed("curl --fail --max-time 10 --proxy socks5://user:supersecret@localhost:1080 http://localhost") + ''; + +}) |