📄 update_test.pl
字号:
#!/usr/bin/perl## Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")# Copyright (C) 2000, 2001 Internet Software Consortium.## Permission to use, copy, modify, and distribute this software for any# purpose with or without fee is hereby granted, provided that the above# copyright notice and this permission notice appear in all copies.## THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR# PERFORMANCE OF THIS SOFTWARE.## Dynamic update test suite.## Usage:## perl update_test.pl [-s server] [-p port] zone## The server defaults to 127.0.0.1.# The port defaults to 53.## The "Special NS rules" tests will only work correctly if the# zone has no NS records to begin with, or alternatively has a# single NS record pointing at the name "ns1" (relative to# the zone name).## Installation notes:## This program uses the Net::DNS::Resolver module.# You can install it by saying## perl -MCPAN -e "install Net::DNS"## $Id: update_test.pl,v 1.7.206.1 2004/03/06 10:22:18 marka Exp $#use Getopt::Std;use Net::DNS;use Net::DNS::Update;use Net::DNS::Resolver;$opt_s = "127.0.0.1";$opt_p = 53;getopt('s:p:');$res = new Net::DNS::Resolver;$res->nameservers($opt_s);$res->port($opt_p);$res->defnames(0); # Do not append default domain.@ARGV == 1 or die "usage: perl update_test.pl [-s server] [-p port] zone\n";$zone = shift @ARGV;my $failures = 0;sub assert { my ($cond, $explanation) = @_; if (!$cond) { print "I:Test Failed: $explanation ***\n"; $failures++ }}sub test { my ($expected, @records) = @_; my $update = new Net::DNS::Update("$zone"); foreach $rec (@records) { $update->push(@$rec); } $reply = $res->send($update); # Did it work? if (defined $reply) { my $rcode = $reply->header->rcode; assert($rcode eq $expected, "expected $expected, got $rcode"); } else { print "I:Update failed: ", $res->errorstring, "\n"; }}sub section { my ($msg) = @_; print "I:$msg\n";}section("Delete any leftovers from previous tests");test("NOERROR", ["update", rr_del("a.$zone")]);test("NOERROR", ["update", rr_del("b.$zone")]);test("NOERROR", ["update", rr_del("c.$zone")]);test("NOERROR", ["update", rr_del("d.$zone")]);test("NOERROR", ["update", rr_del("e.$zone")]);test("NOERROR", ["update", rr_del("f.$zone")]);test("NOERROR", ["update", rr_del("ns.s.$zone")]);test("NOERROR", ["update", rr_del("s.$zone")]);test("NOERROR", ["update", rr_del("t.$zone")]);test("NOERROR", ["update", rr_del("*.$zone")]);test("NOERROR", ["update", rr_del("u.$zone")]);test("NOERROR", ["update", rr_del("a.u.$zone")]);test("NOERROR", ["update", rr_del("b.u.$zone")]);section("Simple prerequisites in the absence of data");# Name is in Usetest("NXDOMAIN", ["pre", yxdomain("a.$zone")]);# RRset exists (value independent)test("NXRRSET", ["pre", yxrrset("a.$zone A")]);# Name is not in usetest("NOERROR", ["pre", nxdomain("a.$zone")]);# RRset does not existtest("NOERROR", ["pre", nxrrset("a.$zone A")]);# RRset exists (value dependent)test("NXRRSET", ["pre", yxrrset("a.$zone 300 A 73.80.65.49")]);section ("Simple creation of data");test("NOERROR", ["update", rr_add("a.$zone 300 A 73.80.65.49")]);section ("Simple prerequisites in the presence of data");# Name is in usetest("NOERROR", ["pre", yxdomain("a.$zone")]);# RRset exists (value independent)test("NOERROR", ["pre", yxrrset("a.$zone A")]);# Name is not in usetest("YXDOMAIN", ["pre", nxdomain("a.$zone")]);# RRset does not existtest("YXRRSET", ["pre", nxrrset("a.$zone A")]);# RRset exists (value dependent)test("NOERROR", ["pre", yxrrset("a.$zone 300 A 73.80.65.49")]);## Merging of RRsets#test("NOERROR", ["update", rr_add("a.$zone 300 A 73.80.65.50")]);section("Detailed tests of \"RRset exists (value dependent)\" prerequisites");test("NOERROR", ["pre", yxrrset("a.$zone 300 A 73.80.65.49"), yxrrset("a.$zone 300 A 73.80.65.50")]);test("NOERROR", ["pre", yxrrset("a.$zone 300 A 73.80.65.50"), yxrrset("a.$zone 300 A 73.80.65.49")]);test("NXRRSET", ["pre", yxrrset("a.$zone 300 A 73.80.65.49")]);test("NXRRSET", ["pre", yxrrset("a.$zone 300 A 73.80.65.50")]);test("NXRRSET", ["pre", yxrrset("a.$zone 300 A 73.80.65.49"), yxrrset("a.$zone 300 A 73.80.65.50"), yxrrset("a.$zone 300 A 73.80.65.51")]);section("Torture test of \"RRset exists (value dependent)\" prerequisites.");test("NOERROR", ["update", rr_add("e.$zone 300 A 73.80.65.49"), rr_add("e.$zone 300 TXT 'one'"), rr_add("e.$zone 300 A 73.80.65.50")]);test("NOERROR", ["update", rr_add("e.$zone 300 A 73.80.65.52"), rr_add("f.$zone 300 A 73.80.65.52"), rr_add("e.$zone 300 A 73.80.65.51")]);test("NOERROR", ["update", rr_add("e.$zone 300 TXT 'three'"), rr_add("e.$zone 300 TXT 'two'")]);test("NOERROR", ["update", rr_add("e.$zone 300 MX 10 mail.$zone")]);test("NOERROR", ["pre", yxrrset("e.$zone 300 A 73.80.65.52"), yxrrset("e.$zone 300 TXT 'two'"), yxrrset("e.$zone 300 A 73.80.65.51"), yxrrset("e.$zone 300 TXT 'three'"), yxrrset("e.$zone 300 A 73.80.65.50"), yxrrset("f.$zone 300 A 73.80.65.52"), yxrrset("e.$zone 300 A 73.80.65.49"), yxrrset("e.$zone 300 TXT 'one'")]);section("Subtraction of RRsets");test("NOERROR", ["update", rr_del("a.$zone 300 A 73.80.65.49")]);test("NOERROR", ["pre", yxrrset("a.$zone 300 A 73.80.65.50")]);test("NOERROR", ["update", rr_del("a.$zone 300 A 73.80.65.50")]);test("NOERROR", ["pre", nxrrset("a.$zone 300 A")]);test("NOERROR", ["pre", nxdomain("a.$zone")]);section("Other forms of deletion");test("NOERROR", ["update", rr_add("a.$zone 300 A 73.80.65.49")]);test("NOERROR", ["update", rr_add("a.$zone 300 A 73.80.65.50")]);test("NOERROR", ["update", rr_add("a.$zone 300 MX 10 mail.$zone")]);test("NOERROR", ["update", rr_del("a.$zone 300 A")]);test("NOERROR", ["pre", nxrrset("a.$zone 300 A")]);test("NOERROR", ["update", rr_add("a.$zone 300 A 73.80.65.49")]);test("NOERROR", ["update", rr_add("a.$zone 300 A 73.80.65.50")]);test("NOERROR", ["update", rr_del("a.$zone")]);test("NOERROR", ["pre", nxdomain("a.$zone")]);section("Case insensitivity");test("NOERROR", ["update", rr_add("a.$zone 300 PTR foo.net.")]);test("NOERROR", ["pre", yxrrset("A.$zone 300 PTR fOo.NeT.")]);section("Special CNAME rules");test("NOERROR", ["update", rr_add("b.$zone 300 CNAME foo.net.")]);test("NOERROR", ["update", rr_add("b.$zone 300 A 73.80.65.49")]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -