about summary refs log tree commit diff
path: root/nixos/tests/sing-box.nix
blob: 43be89317642c1d8aecc896dc552a9258a1244ce (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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")
  '';

})