summary refs log tree commit diff
path: root/nixos/tests/nsd.nix
diff options
context:
space:
mode:
authoraszlig <aszlig@redmoonstudios.org>2014-09-05 02:52:05 +0200
committeraszlig <aszlig@redmoonstudios.org>2014-09-05 02:54:39 +0200
commitc9d1c0d8d160e54cac9b42a6e839066a89208147 (patch)
tree178fc8cd75f3926df82a8d42d1d320d51ad76f52 /nixos/tests/nsd.nix
parente8c4fde22d35d34219a65dd5e3e5c59c89fdcadb (diff)
downloadnixpkgs-c9d1c0d8d160e54cac9b42a6e839066a89208147.tar
nixpkgs-c9d1c0d8d160e54cac9b42a6e839066a89208147.tar.gz
nixpkgs-c9d1c0d8d160e54cac9b42a6e839066a89208147.tar.bz2
nixpkgs-c9d1c0d8d160e54cac9b42a6e839066a89208147.tar.lz
nixpkgs-c9d1c0d8d160e54cac9b42a6e839066a89208147.tar.xz
nixpkgs-c9d1c0d8d160e54cac9b42a6e839066a89208147.tar.zst
nixpkgs-c9d1c0d8d160e54cac9b42a6e839066a89208147.zip
nixos/tests: Add basic test for nsd module.
Currently only tests basic resource record lookup against IPv4 and IPv6.
Nothing special yet, but probably enough for most setups.

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
Diffstat (limited to 'nixos/tests/nsd.nix')
-rw-r--r--nixos/tests/nsd.nix83
1 files changed, 83 insertions, 0 deletions
diff --git a/nixos/tests/nsd.nix b/nixos/tests/nsd.nix
new file mode 100644
index 00000000000..c2331931cdd
--- /dev/null
+++ b/nixos/tests/nsd.nix
@@ -0,0 +1,83 @@
+let
+  common = { pkgs, ... }: {
+    networking.firewall.enable = false;
+    networking.useDHCP = false;
+    # for a host utility with IPv6 support
+    environment.systemPackages = [ pkgs.bind ];
+  };
+in import ./make-test.nix {
+  name = "nsd";
+
+  nodes = {
+    clientv4 = { lib, nodes, ... }: {
+      imports = [ common ];
+      networking.nameservers = lib.mkForce [
+        nodes.server.config.networking.interfaces.eth1.ipAddress
+      ];
+      networking.interfaces.eth1.ipAddress = "192.168.0.2";
+      networking.interfaces.eth1.prefixLength = 24;
+    };
+
+    clientv6 = { lib, nodes, ... }: {
+      imports = [ common ];
+      networking.nameservers = lib.mkForce [
+        nodes.server.config.networking.interfaces.eth1.ipv6Address
+      ];
+      networking.interfaces.eth1.ipv6Address = "dead:beef::2";
+    };
+
+    server = { lib, ... }: {
+      imports = [ common ];
+      networking.interfaces.eth1.ipAddress = "192.168.0.1";
+      networking.interfaces.eth1.prefixLength = 24;
+      networking.interfaces.eth1.ipv6Address = "dead:beef::1";
+      services.nsd.enable = true;
+      services.nsd.interfaces = lib.mkForce [];
+      services.nsd.zones."example.com.".data = ''
+        @ SOA ns.example.com noc.example.com 666 7200 3600 1209600 3600
+        ipv4 A 1.2.3.4
+        ipv6 AAAA abcd::eeff
+        deleg NS ns.example.com
+        ns A 192.168.0.1
+        ns AAAA dead:beef::1
+      '';
+      services.nsd.zones."deleg.example.com.".data = ''
+        @ SOA ns.example.com noc.example.com 666 7200 3600 1209600 3600
+        @ A 9.8.7.6
+        @ AAAA fedc::bbaa
+      '';
+    };
+  };
+
+  testScript = ''
+    startAll;
+
+    $clientv4->waitForUnit("network.target");
+    $clientv6->waitForUnit("network.target");
+    $server->waitForUnit("nsd.service");
+
+    sub assertHost {
+      my ($type, $rr, $query, $expected) = @_;
+      my $self = $type eq 4 ? $clientv4 : $clientv6;
+      my $out = $self->succeed("host -$type -t $rr $query");
+      $self->log("output: $out");
+      chomp $out;
+      die "DNS IPv$type query on $query gave '$out' instead of '$expected'"
+        if ($out !~ $expected);
+    }
+
+    foreach (4, 6) {
+      subtest "ipv$_", sub {
+        assertHost($_, "a", "example.com", qr/has no [^ ]+ record/);
+        assertHost($_, "aaaa", "example.com", qr/has no [^ ]+ record/);
+
+        assertHost($_, "soa", "example.com", qr/SOA.*?noc\.example\.com/);
+        assertHost($_, "a", "ipv4.example.com", qr/address 1.2.3.4$/);
+        assertHost($_, "aaaa", "ipv6.example.com", qr/address abcd::eeff$/);
+
+        assertHost($_, "a", "deleg.example.com", qr/address 9.8.7.6$/);
+        assertHost($_, "aaaa", "deleg.example.com", qr/address fedc::bbaa$/);
+      };
+    }
+  '';
+}