xref: /netbsd-src/external/mpl/bind/dist/bin/tests/system/dnssec/dnssec_update_test.pl (revision f281902de12281841521aa31ef834ad944d725e2)
1#!/usr/bin/perl
2
3# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
4#
5# SPDX-License-Identifier: MPL-2.0
6#
7# This Source Code Form is subject to the terms of the Mozilla Public
8# License, v. 2.0.  If a copy of the MPL was not distributed with this
9# file, you can obtain one at https://mozilla.org/MPL/2.0/.
10#
11# See the COPYRIGHT file distributed with this work for additional
12# information regarding copyright ownership.
13
14#
15# DNSSEC Dynamic update test suite.
16#
17# Usage:
18#
19#   perl update_test.pl [-s server] [-p port] zone
20#
21# The server defaults to 127.0.0.1.
22# The port defaults to 53.
23#
24# Installation notes:
25#
26# This program uses the Net::DNS::Resolver module.
27# You can install it by saying
28#
29#    perl -MCPAN -e "install Net::DNS"
30#
31
32use Getopt::Std;
33use Net::DNS;
34use Net::DNS::Update;
35use Net::DNS::Resolver;
36
37$opt_s = "127.0.0.1";
38$opt_p = 53;
39
40getopt('s:p:');
41
42$res = new Net::DNS::Resolver;
43$res->nameservers($opt_s);
44$res->port($opt_p);
45$res->defnames(0); # Do not append default domain.
46
47@ARGV == 1 or die
48    "usage: perl update_test.pl [-s server] [-p port] zone\n";
49
50$zone = shift @ARGV;
51
52my $failures = 0;
53
54sub assert {
55    my ($cond, $explanation) = @_;
56    if (!$cond) {
57	print "Test Failed: $explanation ***\n";
58	$failures++
59    }
60}
61
62sub test {
63    my ($expected, @records) = @_;
64
65    my $update = new Net::DNS::Update("$zone");
66
67    foreach $rec (@records) {
68	$update->push(@$rec);
69    }
70
71    $reply = $res->send($update);
72
73    # Did it work?
74    if (defined $reply) {
75	my $rcode = $reply->header->rcode;
76        assert($rcode eq $expected, "expected $expected, got $rcode");
77    } else {
78	print "Update failed: ", $res->errorstring, "\n";
79    }
80}
81
82sub section {
83    my ($msg) = @_;
84    print "$msg\n";
85}
86
87section("Add a name");
88test("NOERROR", ["update", rr_add("a.$zone 300 A 73.80.65.49")]);
89
90section("Delete the name");
91test("NOERROR", ["update", rr_del("a.$zone")]);
92
93if ($failures) {
94    print "$failures update tests failed.\n";
95} else {
96    print "All update tests successful.\n";
97}
98
99exit $failures;
100