2 { system ? builtins.currentSystem
4 , pkgs ? import ../.. { inherit system config; }
7 with import ../lib/testing-python.nix { inherit system pkgs; };
11 BIND_ADDRESS = '127.0.0.1'
13 CAPTCHA_ENABLE = False
16 makeAppTest = name: configs: makeTest {
17 name = "powerdns-admin-${name}";
18 meta = with pkgs.lib.maintainers; {
19 maintainers = [ Flakebi zhaofengli ];
22 nodes.server = { pkgs, config, ... }: mkMerge ([
24 services.powerdns-admin = {
26 secretKeyFile = "/etc/powerdns-admin/secret";
27 saltFile = "/etc/powerdns-admin/salt";
29 # It's insecure to have secrets in the world-readable nix store, but this is just a test
30 environment.etc."powerdns-admin/secret".text = "secret key";
31 environment.etc."powerdns-admin/salt".text = "salt";
32 environment.systemPackages = [
33 (pkgs.writeShellScriptBin "run-test" config.system.build.testScript)
39 server.wait_for_unit("powerdns-admin.service")
40 server.wait_until_succeeds("run-test", timeout=10)
47 services.powerdns-admin = {
50 SQLALCHEMY_DATABASE_URI = 'mysql://powerdnsadmin@/powerdnsadmin?unix_socket=/run/mysqld/mysqld.sock'
53 systemd.services.powerdns-admin = {
54 after = [ "mysql.service" ];
55 serviceConfig.BindPaths = "/run/mysqld";
60 package = pkgs.mariadb;
61 ensureDatabases = [ "powerdnsadmin" ];
64 name = "powerdnsadmin";
66 "powerdnsadmin.*" = "ALL PRIVILEGES";
73 services.powerdns-admin = {
76 SQLALCHEMY_DATABASE_URI = 'postgresql://powerdnsadmin@/powerdnsadmin?host=/run/postgresql'
79 systemd.services.powerdns-admin = {
80 after = [ "postgresql.service" ];
81 serviceConfig.BindPaths = "/run/postgresql";
84 services.postgresql = {
86 ensureDatabases = [ "powerdnsadmin" ];
89 name = "powerdnsadmin";
90 ensureDBOwnership = true;
98 services.powerdns-admin.extraArgs = [ "-b" "127.0.0.1:8000" ];
99 system.build.testScript = ''
101 curl -sSf http://127.0.0.1:8000/
103 # Create account to check that the database migrations ran
104 csrf_token="$(curl -sSfc session http://127.0.0.1:8000/register | grep _csrf_token | cut -d\" -f6)"
105 # Outputs 'Redirecting' if successful
106 curl -sSfb session http://127.0.0.1:8000/register \
107 -F "_csrf_token=$csrf_token" \
108 -F "firstname=first" \
110 -F "email=a@example.com" \
112 -F "password=password" \
113 -F "rpassword=password" | grep Redirecting
116 # Outputs 'Redirecting' if successful
117 curl -sSfb session http://127.0.0.1:8000/login \
118 -F "_csrf_token=$csrf_token" \
120 -F "password=password" | grep Redirecting
122 # Check that we are logged in, this redirects to /admin/setting/pdns if we are
123 curl -sSfb session http://127.0.0.1:8000/dashboard/ | grep /admin/setting
127 services.powerdns-admin.extraArgs = [ "-b" "unix:/run/powerdns-admin/http.sock" ];
128 system.build.testScript = ''
129 curl -sSf --unix-socket /run/powerdns-admin/http.sock http://somehost/
136 postgresql = makeAppTest "postgresql" [ backend.postgresql listen.tcp ];
137 mysql = makeAppTest "mysql" [ backend.mysql listen.tcp ];
138 unix-listener = makeAppTest "unix-listener" [ backend.postgresql listen.unix ];