1{ pkgs, lib, ... }:
2
3let
4 nipapRc = pkgs.writeText "nipaprc" ''
5 [global]
6 hostname = [::1]
7 port = 1337
8 username = nixostest
9 password = nIx0st3st
10 default_vrf_rt = -
11 default_list_vrf_rt = all
12 '';
13in
14{
15 name = "lukegb";
16 meta.maintainers = [ lib.maintainers.lukegb ];
17
18 nodes.main =
19 { ... }:
20 {
21 services.nipap = {
22 enable = true;
23 };
24
25 environment.systemPackages = [
26 pkgs.nipap-cli
27 ];
28 };
29
30 testScript = ''
31 main.wait_for_unit("nipapd.service")
32 main.wait_for_unit("nipap-www.service")
33
34 # Make sure the web UI is up.
35 main.wait_for_open_port(21337)
36 main.succeed("curl -fvvv -Ls http://localhost:21337/ | grep 'NIPAP'")
37
38 # Check that none of the files we created in /var/lib/nipap are readable.
39 out = main.succeed("ls -l /var/lib/nipap")
40 bad_perms = False
41 for ln in out.split("\n"):
42 ln = ln.strip()
43 if not ln or ln.startswith('total '):
44 continue
45 if not ln.startswith('-rw------- '):
46 print(f"Bad file permissions: {ln}")
47 bad_perms = True
48 if bad_perms:
49 t.fail("One or more files were overly permissive.")
50
51 # Check we created a web-frontend user.
52 main.succeed("nipap-passwd list | grep nipap-www")
53
54 # Create a test user
55 main.succeed("nipap-passwd add -u nixostest -p nIx0st3st -n 'NixOS Test User'")
56
57 # Try to log in with it on the web frontend
58 main.succeed("curl -fvvv -Ls -b \"\" -d username=nixostest -d password=nIx0st3st http://localhost:21337/auth/login | grep 'PrefixListController'")
59
60 # Try to log in with it using the CLI
61 main.copy_from_host("${nipapRc}", "/root/.nipaprc")
62 main.succeed("chmod u=rw,go= /root/.nipaprc")
63 main.succeed("nipap address add prefix 192.0.2.0/24 type assignment description RFC1166")
64 main.succeed("nipap address add prefix 192.0.2.1/32 type host description 'test host'")
65 main.succeed("nipap address add prefix 2001:db8::/32 type reservation description RFC3849")
66 main.succeed("nipap address add prefix 2001:db8:f00f::/48 type assignment description 'eye pee vee six'")
67 main.succeed("nipap address add prefix 2001:db8:f00f:face:dead:beef:cafe:feed/128 type host description 'test host 2'")
68 '';
69}