1 # This test runs PowerDNS authoritative server with the
2 # generic MySQL backend (gmysql) to connect to a
3 # MariaDB server using UNIX sockets authentication.
5 import ./make-test-python.nix ({ pkgs, lib, ... }: {
8 nodes.server = { ... }: {
9 services.powerdns.enable = true;
10 services.powerdns.extraConfig = ''
13 zone-cache-refresh-interval=0
18 package = pkgs.mariadb;
19 ensureDatabases = [ "powerdns" ];
20 ensureUsers = lib.singleton
22 ensurePermissions = { "powerdns.*" = "ALL PRIVILEGES"; };
26 environment.systemPackages = with pkgs;
27 [ dnsutils powerdns mariadb ];
33 with subtest("PowerDNS database exists"):
34 server.wait_for_unit("mysql")
35 server.succeed("echo 'SHOW DATABASES;' | sudo -u pdns mysql -u pdns >&2")
37 with subtest("Loading the MySQL schema works"):
39 "sudo -u pdns mysql -u pdns -D powerdns <"
40 "${pkgs.powerdns}/share/doc/pdns/schema.mysql.sql"
43 with subtest("PowerDNS server starts"):
44 server.wait_for_unit("pdns")
45 server.succeed("dig version.bind txt chaos @127.0.0.1 >&2")
47 with subtest("Adding an example zone works"):
48 # Extract configuration file needed by pdnsutil
49 unit = server.succeed("systemctl cat pdns")
50 match = re.search("(--config-dir=[^ ]+)", unit)
51 assert(match is not None)
53 pdnsutil = "sudo -u pdns pdnsutil " + conf
54 server.succeed(f"{pdnsutil} create-zone example.com ns1.example.com")
55 server.succeed(f"{pdnsutil} add-record example.com ns1 A 192.168.1.2")
57 with subtest("Querying the example zone works"):
58 reply = server.succeed("dig +noall +answer ns1.example.com @127.0.0.1")
60 "192.168.1.2" in reply
62 The reply does not contain the expected IP address:
64 ns1.example.com. 3600 IN A 192.168.1.2