vuls: init at 0.27.0 (#348530)
[NixPkgs.git] / nixos / tests / rathole.nix
blob56d7a0129f80364d828e8852d4f1dd43fc04451c
1 import ./make-test-python.nix (
2   { pkgs, lib, ... }:
4   let
5     successMessage = "Success 3333115147933743662";
6   in
7   {
8     name = "rathole";
9     meta.maintainers = with lib.maintainers; [ xokdvium ];
10     nodes = {
11       server = {
12         networking = {
13           useNetworkd = true;
14           useDHCP = false;
15           firewall.enable = false;
16         };
18         systemd.network.networks."01-eth1" = {
19           name = "eth1";
20           networkConfig.Address = "10.0.0.1/24";
21         };
23         services.rathole = {
24           enable = true;
25           role = "server";
26           settings = {
27             server = {
28               bind_addr = "0.0.0.0:2333";
29               services = {
30                 success-message = {
31                   bind_addr = "0.0.0.0:80";
32                   token = "hunter2";
33                 };
34               };
35             };
36           };
37         };
38       };
40       client = {
41         networking = {
42           useNetworkd = true;
43           useDHCP = false;
44         };
46         systemd.network.networks."01-eth1" = {
47           name = "eth1";
48           networkConfig.Address = "10.0.0.2/24";
49         };
51         services.nginx = {
52           enable = true;
53           virtualHosts."127.0.0.1" = {
54             root = pkgs.writeTextDir "success-message.txt" successMessage;
55           };
56         };
58         services.rathole = {
59           enable = true;
60           role = "client";
61           credentialsFile = pkgs.writeText "rathole-credentials.toml" ''
62             [client.services.success-message]
63             token = "hunter2"
64           '';
65           settings = {
66             client = {
67               remote_addr = "10.0.0.1:2333";
68               services.success-message = {
69                 local_addr = "127.0.0.1:80";
70               };
71             };
72           };
73         };
74       };
75     };
77     testScript = ''
78       start_all()
79       server.wait_for_unit("rathole.service")
80       server.wait_for_open_port(2333)
81       client.wait_for_unit("rathole.service")
82       server.wait_for_open_port(80)
83       response = server.succeed("curl http://127.0.0.1/success-message.txt")
84       assert "${successMessage}" in response, "Got invalid response"
85       response = client.succeed("curl http://10.0.0.1/success-message.txt")
86       assert "${successMessage}" in response, "Got invalid response"
87     '';
88   }