python312Packages.dissect-extfs: 3.11 -> 3.12
[NixPkgs.git] / nixos / tests / mihomo.nix
bloba456facb4367c07493592723cbbcfc46fcf0e2af
1 import ./make-test-python.nix ({ pkgs, ... }: {
2   name = "mihomo";
3   meta.maintainers = with pkgs.lib.maintainers; [ Guanran928 ];
5   nodes.machine = {
6     environment.systemPackages = [ pkgs.curl ];
8     services.nginx = {
9       enable = true;
10       statusPage = true;
11     };
13     services.mihomo = {
14       enable = true;
15       configFile = pkgs.writeTextFile {
16         name = "config.yaml";
17         text = ''
18           mixed-port: 7890
19           external-controller: 127.0.0.1:9090
20           authentication:
21           - "user:supersecret"
22         '';
23       };
24     };
25   };
27   testScript = ''
28     # Wait until it starts
29     machine.wait_for_unit("nginx.service")
30     machine.wait_for_unit("mihomo.service")
31     machine.wait_for_open_port(80)
32     machine.wait_for_open_port(7890)
33     machine.wait_for_open_port(9090)
35     # Proxy
36     machine.succeed("curl --fail --max-time 10 --proxy http://user:supersecret@localhost:7890 http://localhost")
37     machine.succeed("curl --fail --max-time 10 --proxy socks5://user:supersecret@localhost:7890 http://localhost")
38     machine.fail("curl --fail --max-time 10 --proxy http://user:supervillain@localhost:7890 http://localhost")
39     machine.fail("curl --fail --max-time 10 --proxy socks5://user:supervillain@localhost:7890 http://localhost")
41     # Web UI
42     result = machine.succeed("curl --fail http://localhost:9090")
43     target = '{"hello":"mihomo"}\n'
44     assert result == target, f"{result!r} != {target!r}"
45   '';