vuls: init at 0.27.0
[NixPkgs.git] / nixos / tests / spacecookie.nix
bloba640657d8a6b68a1cd1e15db1094404917a01823
1 let
2   gopherRoot   = "/tmp/gopher";
3   gopherHost   = "gopherd";
4   gopherClient = "client";
5   fileContent  = "Hello Gopher!\n";
6   fileName     = "file.txt";
7 in
8   import ./make-test-python.nix ({...}: {
9     name = "spacecookie";
10     nodes = {
11       ${gopherHost} = {
12         systemd.services.spacecookie = {
13           preStart = ''
14             mkdir -p ${gopherRoot}/directory
15             printf "%s" "${fileContent}" > ${gopherRoot}/${fileName}
16           '';
17         };
19         services.spacecookie = {
20           enable = true;
21           openFirewall = true;
22           settings = {
23             root = gopherRoot;
24             hostname = gopherHost;
25           };
26         };
27       };
29       ${gopherClient} = {};
30     };
32     testScript = ''
33       start_all()
35       # with daemon type notify, the unit being started
36       # should also mean the port is open
37       ${gopherHost}.wait_for_unit("spacecookie.service")
38       ${gopherClient}.wait_for_unit("network.target")
40       fileResponse = ${gopherClient}.succeed("curl -f -s gopher://${gopherHost}/0/${fileName}")
42       # the file response should return our created file exactly
43       if not (fileResponse == "${builtins.replaceStrings [ "\n" ] [ "\\n" ] fileContent}"):
44           raise Exception("Unexpected file response")
46       # sanity check on the directory listing: we serve a directory and a file
47       # via gopher, so the directory listing should have exactly two entries,
48       # one with gopher file type 0 (file) and one with file type 1 (directory).
49       dirResponse = ${gopherClient}.succeed("curl -f -s gopher://${gopherHost}")
50       dirEntries = [l[0] for l in dirResponse.split("\n") if len(l) > 0]
51       dirEntries.sort()
53       if not (["0", "1"] == dirEntries):
54           raise Exception("Unexpected directory response")
55     '';
56   })