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.
4
5import ./make-test-python.nix (
6 { pkgs, lib, ... }:
7 {
8 name = "powerdns";
9
10 nodes.server =
11 { ... }:
12 {
13 services.powerdns.enable = true;
14 services.powerdns.extraConfig = ''
15 launch=gmysql
16 gmysql-user=pdns
17 zone-cache-refresh-interval=0
18 '';
19
20 services.mysql = {
21 enable = true;
22 package = pkgs.mariadb;
23 ensureDatabases = [ "powerdns" ];
24 ensureUsers = lib.singleton {
25 name = "pdns";
26 ensurePermissions = {
27 "powerdns.*" = "ALL PRIVILEGES";
28 };
29 };
30 };
31
32 environment.systemPackages = with pkgs; [
33 dnsutils
34 powerdns
35 mariadb
36 ];
37 };
38
39 testScript = ''
40 with subtest("PowerDNS database exists"):
41 server.wait_for_unit("mysql")
42 server.succeed("echo 'SHOW DATABASES;' | sudo -u pdns mysql -u pdns >&2")
43
44 with subtest("Loading the MySQL schema works"):
45 server.succeed(
46 "sudo -u pdns mysql -u pdns -D powerdns <"
47 "${pkgs.powerdns}/share/doc/pdns/schema.mysql.sql"
48 )
49
50 with subtest("PowerDNS server starts"):
51 server.wait_for_unit("pdns")
52 server.succeed("dig version.bind txt chaos @127.0.0.1 >&2")
53
54 with subtest("Adding an example zone works"):
55 # Extract configuration file needed by pdnsutil
56 pdnsutil = "sudo -u pdns pdnsutil "
57 server.succeed(f"{pdnsutil} create-zone example.com ns1.example.com")
58 server.succeed(f"{pdnsutil} add-record example.com ns1 A 192.168.1.2")
59
60 with subtest("Querying the example zone works"):
61 reply = server.succeed("dig +noall +answer ns1.example.com @127.0.0.1")
62 assert (
63 "192.168.1.2" in reply
64 ), f""""
65 The reply does not contain the expected IP address:
66 Expected:
67 ns1.example.com. 3600 IN A 192.168.1.2
68 Reply:
69 {reply}"""
70 '';
71 }
72)