1 # This test runs the radicle-node and radicle-httpd services on a seed host,
2 # and verifies that an alice peer can host a repository on the seed,
3 # and that a bob peer can send alice a patch via the seed.
8 # The Node ID depends on nodes.seed.services.radicle.privateKeyFile
9 seed-nid = "z6Mkg52RcwDrPKRzzHaYgBkHH3Gi5p4694fvPstVE9HTyMB6";
10 seed-ssh-keys = import ./ssh-keys.nix pkgs;
11 seed-tls-certs = import common/acme/server/snakeoil-certs.nix;
13 commonHostConfig = { nodes, config, pkgs, ... }: {
14 environment.systemPackages = [
15 config.services.radicle.package
20 environment.etc."gitconfig".text = ''
24 email = root@${config.networking.hostName}
25 name = ${config.networking.hostName}
29 ${nodes.seed.networking.primaryIPAddress} ${nodes.seed.services.radicle.httpd.nginx.serverName}
32 security.pki.certificateFiles = [
33 seed-tls-certs.ca.cert
37 radicleConfig = { nodes, ... }: alias:
38 pkgs.writeText "config.json" (builtins.toJSON {
40 "${seed-nid}@seed:${toString nodes.seed.services.radicle.node.listenPort}"
55 meta = with pkgs.lib.maintainers; {
63 seed = { pkgs, config, ... }: {
64 imports = [ commonHostConfig ];
68 privateKeyFile = seed-ssh-keys.snakeOilEd25519PrivateKey;
69 publicKey = seed-ssh-keys.snakeOilEd25519PublicKey;
76 serverName = seed-tls-certs.domain;
78 sslCertificate = seed-tls-certs.${seed-tls-certs.domain}.cert;
79 sslCertificateKey = seed-tls-certs.${seed-tls-certs.domain}.key;
98 networking.firewall.allowedTCPPorts = [ 443 ];
102 imports = [ commonHostConfig ];
106 imports = [ commonHostConfig ];
110 testScript = { nodes, ... }@args: ''
113 with subtest("seed can run radicle-node"):
114 # The threshold and/or hardening may have to be changed with new features/checks
115 print(seed.succeed("systemd-analyze security radicle-node.service --threshold=10 --no-pager"))
116 seed.wait_for_unit("radicle-node.service")
117 seed.wait_for_open_port(${toString nodes.seed.services.radicle.node.listenPort})
119 with subtest("seed can run radicle-httpd"):
120 # The threshold and/or hardening may have to be changed with new features/checks
121 print(seed.succeed("systemd-analyze security radicle-httpd.service --threshold=10 --no-pager"))
122 seed.wait_for_unit("radicle-httpd.service")
123 seed.wait_for_open_port(${toString nodes.seed.services.radicle.httpd.listenPort})
124 seed.wait_for_open_port(443)
125 assert alice.succeed("curl -sS 'https://${nodes.seed.services.radicle.httpd.nginx.serverName}/api/v1' | jq -r .nid") == "${seed-nid}\n"
126 assert bob.succeed("curl -sS 'https://${nodes.seed.services.radicle.httpd.nginx.serverName}/api/v1' | jq -r .nid") == "${seed-nid}\n"
128 with subtest("alice can create a Node ID"):
129 alice.succeed("rad auth --alias alice --stdin </dev/null")
130 alice.copy_from_host("${radicleConfig args "alice"}", "/root/.radicle/config.json")
131 with subtest("alice can run a node"):
132 alice.succeed("rad node start")
133 with subtest("alice can create a Git repository"):
136 "git -C /tmp/repo init",
137 "echo hello world > /tmp/repo/testfile",
138 "git -C /tmp/repo add .",
139 "git -C /tmp/repo commit -m init"
141 with subtest("alice can create a Repository ID"):
143 "cd /tmp/repo && rad init --name repo --description descr --default-branch main --public"
145 alice_repo_rid=alice.succeed("cd /tmp/repo && rad inspect --rid").rstrip("\n")
146 with subtest("alice can send a repository to the seed"):
147 alice.succeed(f"rad sync --seed ${seed-nid} {alice_repo_rid}")
149 with subtest(f"seed can receive the repository {alice_repo_rid}"):
150 seed.wait_until_succeeds("test 1 = \"$(rad-system stats | jq .local.repos)\"")
152 with subtest("bob can create a Node ID"):
153 bob.succeed("rad auth --alias bob --stdin </dev/null")
154 bob.copy_from_host("${radicleConfig args "bob"}", "/root/.radicle/config.json")
155 bob.succeed("rad node start")
156 with subtest("bob can clone alice's repository from the seed"):
157 bob.succeed(f"rad clone {alice_repo_rid} /tmp/repo")
158 assert bob.succeed("cat /tmp/repo/testfile") == "hello world\n"
160 with subtest("bob can clone alice's repository from the seed through the HTTP gateway"):
161 bob.succeed(f"git clone https://${nodes.seed.services.radicle.httpd.nginx.serverName}/{alice_repo_rid[4:]}.git /tmp/repo-http")
162 assert bob.succeed("cat /tmp/repo-http/testfile") == "hello world\n"
164 with subtest("alice can push the main branch to the rad remote"):
166 "echo hello bob > /tmp/repo/testfile",
167 "git -C /tmp/repo add .",
168 "git -C /tmp/repo commit -m 'hello to bob'",
169 "git -C /tmp/repo push rad main"
171 with subtest("bob can sync bob's repository from the seed"):
173 "cd /tmp/repo && rad sync --seed ${seed-nid}",
174 "cd /tmp/repo && git pull"
176 assert bob.succeed("cat /tmp/repo/testfile") == "hello bob\n"
178 with subtest("bob can push a patch"):
180 "echo hello alice > /tmp/repo/testfile",
181 "git -C /tmp/repo checkout -b for-alice",
182 "git -C /tmp/repo add .",
183 "git -C /tmp/repo commit -m 'hello to alice'",
184 "git -C /tmp/repo push -o patch.message='hello for alice' rad HEAD:refs/patches"
187 bob_repo_patch1_pid=bob.succeed("cd /tmp/repo && git branch --remotes | sed -ne 's:^ *rad/patches/::'p").rstrip("\n")
188 with subtest("alice can receive the patch"):
189 alice.wait_until_succeeds("test 1 = \"$(rad stats | jq .local.patches)\"")
191 f"cd /tmp/repo && rad patch show {bob_repo_patch1_pid} | grep 'opened by bob'",
192 f"cd /tmp/repo && rad patch checkout {bob_repo_patch1_pid}"
194 assert alice.succeed("cat /tmp/repo/testfile") == "hello alice\n"
195 with subtest("alice can comment the patch"):
197 f"cd /tmp/repo && rad patch comment {bob_repo_patch1_pid} -m thank-you"
199 with subtest("alice can merge the patch"):
201 "git -C /tmp/repo checkout main",
202 f"git -C /tmp/repo merge patch/{bob_repo_patch1_pid[:7]}",
203 "git -C /tmp/repo push rad main",
204 "cd /tmp/repo && rad patch list | grep -qxF 'Nothing to show.'"