nixpkgs/nixos/tests/pufferpanel.nix
Silvan Mosberger 4f0dadbf38 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build a08b3a4d19.tar.gz \
      --argstr baseRev b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:26:33 +01:00

80 lines
2.6 KiB
Nix

import ./make-test-python.nix (
{ lib, ... }:
{
name = "pufferpanel";
meta.maintainers = [ lib.maintainers.tie ];
nodes.machine =
{ pkgs, ... }:
{
environment.systemPackages = [ pkgs.pufferpanel ];
services.pufferpanel = {
enable = true;
extraPackages = [ pkgs.netcat ];
environment = {
PUFFER_PANEL_REGISTRATIONENABLED = "false";
PUFFER_PANEL_SETTINGS_COMPANYNAME = "NixOS";
};
};
};
testScript = ''
import shlex
import json
curl = "curl --fail-with-body --silent"
baseURL = "http://localhost:8080"
adminName = "admin"
adminEmail = "admin@nixos.org"
adminPass = "admin"
adminCreds = json.dumps({
"email": adminEmail,
"password": adminPass,
})
stopCode = 9 # SIGKILL
serverPort = 1337
serverDefinition = json.dumps({
"name": "netcat",
"node": 0,
"users": [
adminName,
],
"type": "netcat",
"run": {
"stopCode": stopCode,
"command": f"nc -l {serverPort}",
},
"environment": {
"type": "standard",
},
})
start_all()
machine.wait_for_unit("pufferpanel.service")
machine.wait_for_open_port(5657) # SFTP
machine.wait_for_open_port(8080) # HTTP
# Note that PufferPanel does not initialize database unless necessary.
# /api/config endpoint creates database file and triggers migrations.
# On success, we run a command to create administrator user that we use to
# interact with HTTP API.
resp = json.loads(machine.succeed(f"{curl} {baseURL}/api/config"))
assert resp["branding"]["name"] == "NixOS", "Invalid company name in configuration"
assert resp["registrationEnabled"] == False, "Expected registration to be disabled"
machine.succeed(f"pufferpanel --workDir /var/lib/pufferpanel user add --admin --name {adminName} --email {adminEmail} --password {adminPass}")
resp = json.loads(machine.succeed(f"{curl} -d '{adminCreds}' {baseURL}/auth/login"))
assert "servers.admin" in resp["scopes"], "User is not administrator"
token = resp["session"]
authHeader = shlex.quote(f"Authorization: Bearer {token}")
resp = json.loads(machine.succeed(f"{curl} -H {authHeader} -H 'Content-Type: application/json' -d '{serverDefinition}' {baseURL}/api/servers"))
serverID = resp["id"]
machine.succeed(f"{curl} -X POST -H {authHeader} {baseURL}/proxy/daemon/server/{serverID}/start")
machine.wait_for_open_port(serverPort)
'';
}
)