1 import ./make-test-python.nix ({ lib, ... }: {
3 meta.maintainers = [ lib.maintainers.tie ];
5 nodes.machine = { pkgs, ... }: {
6 environment.systemPackages = [ pkgs.pufferpanel ];
7 services.pufferpanel = {
9 extraPackages = [ pkgs.netcat ];
11 PUFFER_PANEL_REGISTRATIONENABLED = "false";
12 PUFFER_PANEL_SETTINGS_COMPANYNAME = "NixOS";
21 curl = "curl --fail-with-body --silent"
22 baseURL = "http://localhost:8080"
24 adminEmail = "admin@nixos.org"
26 adminCreds = json.dumps({
28 "password": adminPass,
30 stopCode = 9 # SIGKILL
32 serverDefinition = json.dumps({
41 "command": f"nc -l {serverPort}",
50 machine.wait_for_unit("pufferpanel.service")
51 machine.wait_for_open_port(5657) # SFTP
52 machine.wait_for_open_port(8080) # HTTP
54 # Note that PufferPanel does not initialize database unless necessary.
55 # /api/config endpoint creates database file and triggers migrations.
56 # On success, we run a command to create administrator user that we use to
57 # interact with HTTP API.
58 resp = json.loads(machine.succeed(f"{curl} {baseURL}/api/config"))
59 assert resp["branding"]["name"] == "NixOS", "Invalid company name in configuration"
60 assert resp["registrationEnabled"] == False, "Expected registration to be disabled"
62 machine.succeed(f"pufferpanel --workDir /var/lib/pufferpanel user add --admin --name {adminName} --email {adminEmail} --password {adminPass}")
64 resp = json.loads(machine.succeed(f"{curl} -d '{adminCreds}' {baseURL}/auth/login"))
65 assert "servers.admin" in resp["scopes"], "User is not administrator"
66 token = resp["session"]
67 authHeader = shlex.quote(f"Authorization: Bearer {token}")
69 resp = json.loads(machine.succeed(f"{curl} -H {authHeader} -H 'Content-Type: application/json' -d '{serverDefinition}' {baseURL}/api/servers"))
71 machine.succeed(f"{curl} -X POST -H {authHeader} {baseURL}/proxy/daemon/server/{serverID}/start")
72 machine.wait_for_open_port(serverPort)