1 import ./make-test-python.nix (
4 inherit (import ./ssh-keys.nix pkgs) snakeOilPrivateKey snakeOilPublicKey;
12 meta.maintainers = with lib.maintainers; [ dadada ];
17 environment.systemPackages = with pkgs; [
22 environment.etc.sshKey = {
23 source = snakeOilPrivateKey;
31 services.soft-serve = {
35 ssh.listen_addr = ":${toString sshPort}";
36 git.listen_addr = ":${toString gitPort}";
37 http.listen_addr = ":${toString httpPort}";
38 stats.listen_addr = ":${toString statsPort}";
39 initial_admin_keys = [ snakeOilPublicKey ];
42 networking.firewall.allowedTCPPorts = [
53 SSH_PORT = ${toString sshPort}
54 HTTP_PORT = ${toString httpPort}
55 STATS_PORT = ${toString statsPort}
56 KEY = "${snakeOilPublicKey}"
57 SSH_KEY = "/etc/sshKey"
58 SSH_COMMAND = f"ssh -p {SSH_PORT} -i {SSH_KEY} -o StrictHostKeyChecking=no"
59 TEST_DIR = "/tmp/test"
60 GIT = f"git -C {TEST_DIR}"
62 for machine in client, server:
63 machine.wait_for_unit("network.target")
65 server.wait_for_unit("soft-serve.service")
66 server.wait_for_open_port(SSH_PORT)
68 with subtest("Get info"):
69 status, test = client.execute(f"{SSH_COMMAND} server info")
71 raise Exception("Failed to get SSH info")
72 key = " ".join(KEY.split(" ")[0:2])
74 raise Exception("Admin key must be configured correctly")
76 with subtest("Create user"):
77 client.succeed(f"{SSH_COMMAND} server user create beatrice")
78 client.succeed(f"{SSH_COMMAND} server user info beatrice")
80 with subtest("Create repo"):
81 client.succeed(f"git init {TEST_DIR}")
82 client.succeed(f"{GIT} config --global user.email you@example.com")
83 client.succeed(f"touch {TEST_DIR}/foo")
84 client.succeed(f"{GIT} add foo")
85 client.succeed(f"{GIT} commit --allow-empty -m test")
86 client.succeed(f"{GIT} remote add origin git@server:test")
87 client.succeed(f"GIT_SSH_COMMAND='{SSH_COMMAND}' {GIT} push -u origin master")
88 client.execute("rm -r /tmp/test")
90 server.wait_for_open_port(HTTP_PORT)
92 with subtest("Clone over HTTP"):
93 client.succeed(f"curl --connect-timeout 10 http://server:{HTTP_PORT}/")
94 client.succeed(f"git clone http://server:{HTTP_PORT}/test /tmp/test")
95 client.execute("rm -r /tmp/test")
97 with subtest("Clone over SSH"):
98 client.succeed(f"GIT_SSH_COMMAND='{SSH_COMMAND}' git clone git@server:test /tmp/test")
99 client.execute("rm -r /tmp/test")
101 with subtest("Get stats over HTTP"):
102 server.wait_for_open_port(STATS_PORT)
103 status, test = client.execute(f"curl --connect-timeout 10 http://server:{STATS_PORT}/metrics")
105 raise Exception("Failed to get metrics from status port")
106 if not "go_gc_duration_seconds_count" in test:
107 raise Exception("Metrics did not contain key 'go_gc_duration_seconds_count'")