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