From 552ddf0ccecdb2bc99c58e2eff636a16066f93c2 Mon Sep 17 00:00:00 2001 From: Peter van Dijk Date: Mon, 20 Jan 2014 19:15:02 +0100 Subject: [PATCH] add bindparser tests --- pdns/Makefile.am | 5 +-- pdns/bindparserclasses.hh | 1 + pdns/named.conf.parsertest | 70 ++++++++++++++++++++++++++++++++++++++ pdns/test-bindparser_cc.cc | 45 ++++++++++++++++++++++++ 4 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 pdns/named.conf.parsertest create mode 100644 pdns/test-bindparser_cc.cc diff --git a/pdns/Makefile.am b/pdns/Makefile.am index cb8541f90..acea4209a 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -16,7 +16,7 @@ endif EXTRA_DIST = dnslabeltext.rl dnslabeltext.cc mtasker.cc inflighter.cc docs/pdns_control.8 \ docs/pdns_server.8 docs/zone2sql.8 docs/zone2ldap.8 docs/pdnssec.8 \ docs/dnsreplay.8 docs/dnsscope.8 docs/dnswasher.8 docs/pdnssec.8 docs/zone2ldap.8 \ - bind-dnssec.schema.sqlite3.sql bindparser.h + bind-dnssec.schema.sqlite3.sql bindparser.h named.conf.parsertest SUBDIRS= $(POLARSSL_SUBDIR) ext/yahttp @@ -267,7 +267,8 @@ testrunner_SOURCES=testrunner.cc test-misc_hh.cc test-nameserver_cc.cc test-dnsr dnswriter.cc base64.cc base32.cc dnsrecords.cc dnslabeltext.cc dnsparser.cc \ rcpgenerator.cc ednssubnet.cc nsecrecords.cc sillyrecords.cc dnssecinfra.cc \ test-base64_cc.cc test-iputils_hh.cc test-dns_random_hh.cc dns_random.cc \ - test-rcpgenerator_cc.cc responsestats.cc + test-rcpgenerator_cc.cc responsestats.cc test-bindparser_cc.cc \ + bindparser.cc bindlexer.c testrunner_LDFLAGS= @DYNLINKFLAGS@ @THREADFLAGS@ $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) testrunner_LDADD= $(POLARSSL_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS) diff --git a/pdns/bindparserclasses.hh b/pdns/bindparserclasses.hh index 92bad31a5..f554bd7e9 100644 --- a/pdns/bindparserclasses.hh +++ b/pdns/bindparserclasses.hh @@ -25,6 +25,7 @@ #include #include #include +#include #include "namespaces.hh" diff --git a/pdns/named.conf.parsertest b/pdns/named.conf.parsertest new file mode 100644 index 000000000..4d38d223f --- /dev/null +++ b/pdns/named.conf.parsertest @@ -0,0 +1,70 @@ +# this file is used by ../pdns/test-bindparser_cc.cc +# if you change it, please make check! + +options { + directory "./zones/"; + recursion no; + listen-on port 5300 { + 127.0.0.1; + }; + version "Meow!Meow!"; + minimal-responses yes; +}; +zone "example.com"{ + type master; + file "example.com"; +}; + +zone "test.com"{ + type slave; + file "test.com"; + masters { 1.2.3.4:5678; }; +}; + +zone "test.dyndns" { + type garblewarble; + file "test.dyndns"; + allow-update { + 127.0.0.0/8; + }; +}; + +zone "wtest.com"{ + type master; + file "wtest.com"; +}; + +zone "nztest.com"{ + type master; + file "nztest.com"; +}; + +zone "dnssec-parent.com"{ + type master; + file "dnssec-parent.com"; +}; + +zone "delegated.dnssec-parent.com"{ + type master; + file "delegated.dnssec-parent.com"; +}; + +zone "secure-delegated.dnssec-parent.com"{ + type master; + file "secure-delegated.dnssec-parent.com"; +}; + +zone "minimal.com"{ + type master; + file "minimal.com"; +}; + +zone "tsig.com"{ + type master; + file "tsig.com"; +}; + +zone "stest.com"{ + type master; + file "stest.com"; +}; diff --git a/pdns/test-bindparser_cc.cc b/pdns/test-bindparser_cc.cc new file mode 100644 index 000000000..647617f83 --- /dev/null +++ b/pdns/test-bindparser_cc.cc @@ -0,0 +1,45 @@ +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_NO_MAIN + +#include +#include "bindparserclasses.hh" +#include "misc.hh" +#include "pdnsexception.hh" +#include +#include + +using std::string; + +BOOST_AUTO_TEST_SUITE(bindparser_cc) + +BOOST_AUTO_TEST_CASE(test_parser) { + BindParser BP; + BOOST_CHECK_THROW( BP.parse("../regression-tests/named.confx"), PDNSException); + BP.parse("./named.conf.parsertest"); + + vector domains=BP.getDomains(); + BOOST_CHECK_EQUAL(domains.size(), 11); + +#define checkzone(i, dname, fname, ztype, nmasters) { \ + BOOST_CHECK_EQUAL(domains[i].name, #dname); \ + BOOST_CHECK_EQUAL(domains[i].filename, fname); \ + BOOST_CHECK_EQUAL(domains[i].type, #ztype); \ + BOOST_CHECK_EQUAL(domains[i].masters.size(), nmasters); \ + } + + checkzone(0, example.com, "./zones//example.com", master, 0); + checkzone(1, test.com, "./zones//test.com", slave, 1); + BOOST_CHECK_EQUAL(domains[1].masters[0], "1.2.3.4:5678"); + checkzone(2, test.dyndns, "./zones//test.dyndns", garblewarble, 0); + checkzone(3, wtest.com, "./zones//wtest.com", master, 0); + checkzone(4, nztest.com, "./zones//nztest.com", master, 0); + checkzone(5, dnssec-parent.com, "./zones//dnssec-parent.com", master, 0); + checkzone(6, delegated.dnssec-parent.com, "./zones//delegated.dnssec-parent.com", master, 0); + checkzone(7, secure-delegated.dnssec-parent.com, "./zones//secure-delegated.dnssec-parent.com", master, 0); + checkzone(8, minimal.com, "./zones//minimal.com", master, 0); + checkzone(9, tsig.com, "./zones//tsig.com", master, 0); + checkzone(10, stest.com, "./zones//stest.com", master, 0); +} + +BOOST_AUTO_TEST_SUITE_END() + -- 2.40.0