1import ./make-test-python.nix ({ pkgs, ...}:
2let
3 port = 8000;
4 baseUrl = "http://server:${toString port}";
5in
6{
7 name = "pinnwand";
8 meta = with pkgs.lib.maintainers; {
9 maintainers =[ hexa ];
10 };
11
12 nodes = {
13 server = { config, ... }:
14 {
15 networking.firewall.allowedTCPPorts = [
16 port
17 ];
18
19 services.pinnwand = {
20 enable = true;
21 port = port;
22 };
23 };
24
25 client = { pkgs, ... }:
26 {
27 environment.systemPackages = [
28 pkgs.steck
29
30 (pkgs.writers.writePython3Bin "setup-steck.py" {
31 libraries = with pkgs.python3.pkgs; [ appdirs toml ];
32 flakeIgnore = [
33 "E501"
34 ];
35 }
36 ''
37 import appdirs
38 import toml
39 import os
40
41 CONFIG = {
42 "base": "${baseUrl}/",
43 "confirm": False,
44 "magic": True,
45 "ignore": True
46 }
47
48 os.makedirs(appdirs.user_config_dir('steck'))
49 with open(os.path.join(appdirs.user_config_dir('steck'), 'steck.toml'), "w") as fd:
50 toml.dump(CONFIG, fd)
51 '')
52 ];
53 };
54 };
55
56 testScript = ''
57 start_all()
58
59 server.wait_for_unit("pinnwand.service")
60 client.wait_for_unit("network.target")
61
62 # create steck.toml config file
63 client.succeed("setup-steck.py")
64
65 # wait until the server running pinnwand is reachable
66 client.wait_until_succeeds("ping -c1 server")
67
68 # make sure pinnwand is listening
69 server.wait_for_open_port(${toString port})
70
71 # send the contents of /etc/machine-id
72 response = client.succeed("steck paste /etc/machine-id")
73
74 # parse the steck response
75 raw_url = None
76 removal_link = None
77 for line in response.split("\n"):
78 if line.startswith("View link:"):
79 raw_url = f"${baseUrl}/raw/{line.split('/')[-1]}"
80 if line.startswith("Removal link:"):
81 removal_link = line.split(":", 1)[1]
82
83 # check whether paste matches what we sent
84 client.succeed(f"curl {raw_url} > /tmp/machine-id")
85 client.succeed("diff /tmp/machine-id /etc/machine-id")
86
87 # remove paste and check that it's not available any more
88 client.succeed(f"curl {removal_link}")
89 client.fail(f"curl --fail {raw_url}")
90
91 server.log(server.execute("systemd-analyze security pinnwand | grep '✗'")[1])
92 '';
93})