2011-02-26 02:26:33 +00:00
|
|
|
/*
|
2018-02-23 09:53:12 +01:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2011-02-26 02:26:33 +00:00
|
|
|
*
|
2016-06-27 14:56:38 +10:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2018-02-23 09:53:12 +01:00
|
|
|
*
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
2011-02-26 02:26:33 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*! \file */
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <atf-c.h>
|
|
|
|
|
2012-05-14 10:06:05 -07:00
|
|
|
#include <stdio.h>
|
2011-02-26 02:26:33 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2013-01-03 18:22:52 -08:00
|
|
|
#include <isc/print.h>
|
2017-09-13 23:43:43 +10:00
|
|
|
#include <isc/string.h>
|
2012-05-14 10:06:05 -07:00
|
|
|
#include <isc/xml.h>
|
|
|
|
|
2011-02-26 02:26:33 +00:00
|
|
|
#include <dns/cache.h>
|
|
|
|
#include <dns/callbacks.h>
|
2011-12-08 16:07:22 +00:00
|
|
|
#include <dns/db.h>
|
2011-02-26 02:26:33 +00:00
|
|
|
#include <dns/master.h>
|
2011-09-07 19:11:14 +00:00
|
|
|
#include <dns/masterdump.h>
|
2011-02-26 02:26:33 +00:00
|
|
|
#include <dns/name.h>
|
|
|
|
#include <dns/rdata.h>
|
2011-09-07 19:11:14 +00:00
|
|
|
#include <dns/rdatalist.h>
|
2011-02-26 02:26:33 +00:00
|
|
|
#include <dns/rdataset.h>
|
|
|
|
|
|
|
|
#include "dnstest.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define BUFLEN 255
|
2012-08-16 09:42:14 +10:00
|
|
|
#define BIGBUFLEN (70 * 1024)
|
2011-02-26 02:26:33 +00:00
|
|
|
#define TEST_ORIGIN "test"
|
|
|
|
|
2011-12-08 16:07:22 +00:00
|
|
|
static dns_masterrawheader_t header;
|
|
|
|
static isc_boolean_t headerset;
|
|
|
|
|
2012-01-31 03:35:41 +00:00
|
|
|
dns_name_t dns_origin;
|
2012-02-01 00:20:09 +00:00
|
|
|
char origin[sizeof(TEST_ORIGIN)];
|
|
|
|
unsigned char name_buf[BUFLEN];
|
2012-01-31 03:35:41 +00:00
|
|
|
dns_rdatacallbacks_t callbacks;
|
|
|
|
char *include_file = NULL;
|
|
|
|
|
2011-12-08 16:07:22 +00:00
|
|
|
static void
|
|
|
|
rawdata_callback(dns_zone_t *zone, dns_masterrawheader_t *header);
|
|
|
|
|
2011-02-26 02:26:33 +00:00
|
|
|
static isc_result_t
|
2016-12-30 15:45:08 +11:00
|
|
|
add_callback(void *arg, const dns_name_t *owner, dns_rdataset_t *dataset) {
|
2011-02-26 02:26:33 +00:00
|
|
|
char buf[BIGBUFLEN];
|
|
|
|
isc_buffer_t target;
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
UNUSED(arg);
|
|
|
|
|
|
|
|
isc_buffer_init(&target, buf, BIGBUFLEN);
|
|
|
|
result = dns_rdataset_totext(dataset, owner, ISC_FALSE, ISC_FALSE,
|
|
|
|
&target);
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2011-12-08 16:07:22 +00:00
|
|
|
static void
|
|
|
|
rawdata_callback(dns_zone_t *zone, dns_masterrawheader_t *h) {
|
|
|
|
UNUSED(zone);
|
|
|
|
header = *h;
|
|
|
|
headerset = ISC_TRUE;
|
|
|
|
}
|
|
|
|
|
2012-01-31 03:35:41 +00:00
|
|
|
static isc_result_t
|
2013-01-04 11:23:18 +11:00
|
|
|
setup_master(void (*warn)(struct dns_rdatacallbacks *, const char *, ...),
|
2013-01-04 23:45:53 +00:00
|
|
|
void (*error)(struct dns_rdatacallbacks *, const char *, ...))
|
2013-01-04 11:23:18 +11:00
|
|
|
{
|
2011-02-26 02:26:33 +00:00
|
|
|
isc_result_t result;
|
|
|
|
int len;
|
|
|
|
isc_buffer_t source;
|
|
|
|
isc_buffer_t target;
|
|
|
|
|
2017-09-13 00:14:37 -07:00
|
|
|
strlcpy(origin, TEST_ORIGIN, sizeof(origin));
|
2011-02-26 02:26:33 +00:00
|
|
|
len = strlen(origin);
|
|
|
|
isc_buffer_init(&source, origin, len);
|
|
|
|
isc_buffer_add(&source, len);
|
|
|
|
isc_buffer_setactive(&source, len);
|
|
|
|
isc_buffer_init(&target, name_buf, BUFLEN);
|
|
|
|
dns_name_init(&dns_origin, NULL);
|
2011-12-08 16:07:22 +00:00
|
|
|
dns_master_initrawheader(&header);
|
2011-02-26 02:26:33 +00:00
|
|
|
|
|
|
|
result = dns_name_fromtext(&dns_origin, &source, dns_rootname,
|
|
|
|
0, &target);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return(result);
|
|
|
|
|
|
|
|
dns_rdatacallbacks_init_stdio(&callbacks);
|
|
|
|
callbacks.add = add_callback;
|
2011-12-08 16:07:22 +00:00
|
|
|
callbacks.rawdata = rawdata_callback;
|
|
|
|
callbacks.zone = NULL;
|
2013-01-04 11:23:18 +11:00
|
|
|
if (warn != NULL)
|
|
|
|
callbacks.warn = warn;
|
|
|
|
if (error != NULL)
|
|
|
|
callbacks.error = error;
|
|
|
|
headerset = ISC_FALSE;
|
2012-01-31 03:35:41 +00:00
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
2013-01-04 11:23:18 +11:00
|
|
|
test_master(const char *testfile, dns_masterformat_t format,
|
|
|
|
void (*warn)(struct dns_rdatacallbacks *, const char *, ...),
|
|
|
|
void (*error)(struct dns_rdatacallbacks *, const char *, ...))
|
|
|
|
{
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
result = setup_master(warn, error);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return(result);
|
|
|
|
|
2018-04-03 13:09:55 +02:00
|
|
|
result = dns_master_loadfile(testfile, &dns_origin, &dns_origin,
|
|
|
|
dns_rdataclass_in, ISC_TRUE, 0,
|
|
|
|
&callbacks, NULL, NULL, mctx, format, 0);
|
2011-02-26 02:26:33 +00:00
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
2012-01-31 03:35:41 +00:00
|
|
|
static void
|
|
|
|
include_callback(const char *filename, void *arg) {
|
|
|
|
char **argp = (char **) arg;
|
|
|
|
*argp = isc_mem_strdup(mctx, filename);
|
|
|
|
}
|
|
|
|
|
2011-02-26 02:26:33 +00:00
|
|
|
/*
|
|
|
|
* Individual unit tests
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Successful load test */
|
2011-12-08 16:07:22 +00:00
|
|
|
ATF_TC(load);
|
|
|
|
ATF_TC_HEAD(load, tc) {
|
2011-02-26 02:26:33 +00:00
|
|
|
atf_tc_set_md_var(tc, "descr", "dns_master_loadfile() loads a "
|
2011-03-01 23:48:07 +00:00
|
|
|
"valid master file and returns success");
|
2011-02-26 02:26:33 +00:00
|
|
|
}
|
2011-12-08 16:07:22 +00:00
|
|
|
ATF_TC_BODY(load, tc) {
|
2011-02-26 02:26:33 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
UNUSED(tc);
|
|
|
|
|
2011-07-06 01:36:32 +00:00
|
|
|
result = dns_test_begin(NULL, ISC_FALSE);
|
2011-02-26 02:26:33 +00:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
2011-12-08 16:07:22 +00:00
|
|
|
result = test_master("testdata/master/master1.data",
|
2013-01-04 11:23:18 +11:00
|
|
|
dns_masterformat_text, NULL, NULL);
|
2011-02-26 02:26:33 +00:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
dns_test_end();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Unepxected end of file test */
|
2011-12-08 16:07:22 +00:00
|
|
|
ATF_TC(unexpected);
|
|
|
|
ATF_TC_HEAD(unexpected, tc) {
|
2011-02-26 02:26:33 +00:00
|
|
|
atf_tc_set_md_var(tc, "descr", "dns_master_loadfile() returns "
|
2011-03-01 23:48:07 +00:00
|
|
|
"DNS_R_UNEXPECTED when file ends "
|
2011-02-26 02:26:33 +00:00
|
|
|
"too soon");
|
|
|
|
}
|
2011-12-08 16:07:22 +00:00
|
|
|
ATF_TC_BODY(unexpected, tc) {
|
2011-02-26 02:26:33 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
UNUSED(tc);
|
|
|
|
|
2011-07-06 01:36:32 +00:00
|
|
|
result = dns_test_begin(NULL, ISC_FALSE);
|
2011-02-26 02:26:33 +00:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
2011-12-08 16:07:22 +00:00
|
|
|
result = test_master("testdata/master/master2.data",
|
2013-01-04 11:23:18 +11:00
|
|
|
dns_masterformat_text, NULL, NULL);
|
2011-02-26 02:26:33 +00:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_UNEXPECTEDEND);
|
|
|
|
|
|
|
|
dns_test_end();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* No owner test */
|
2011-12-08 16:07:22 +00:00
|
|
|
ATF_TC(noowner);
|
|
|
|
ATF_TC_HEAD(noowner, tc) {
|
2011-02-26 02:26:33 +00:00
|
|
|
atf_tc_set_md_var(tc, "descr", "dns_master_loadfile() accepts broken "
|
2011-03-01 23:48:07 +00:00
|
|
|
"zones with no TTL for first record "
|
2011-02-26 02:26:33 +00:00
|
|
|
"if it is an SOA");
|
|
|
|
}
|
2011-12-08 16:07:22 +00:00
|
|
|
ATF_TC_BODY(noowner, tc) {
|
2011-02-26 02:26:33 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
UNUSED(tc);
|
|
|
|
|
2011-07-06 01:36:32 +00:00
|
|
|
result = dns_test_begin(NULL, ISC_FALSE);
|
2011-02-26 02:26:33 +00:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
2011-12-08 16:07:22 +00:00
|
|
|
result = test_master("testdata/master/master3.data",
|
2013-01-04 11:23:18 +11:00
|
|
|
dns_masterformat_text, NULL, NULL);
|
2011-02-26 02:26:33 +00:00
|
|
|
ATF_REQUIRE_EQ(result, DNS_R_NOOWNER);
|
|
|
|
|
|
|
|
dns_test_end();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* No TTL test */
|
2011-12-08 16:07:22 +00:00
|
|
|
ATF_TC(nottl);
|
|
|
|
ATF_TC_HEAD(nottl, tc) {
|
2011-02-26 02:26:33 +00:00
|
|
|
atf_tc_set_md_var(tc, "descr", "dns_master_loadfile() returns "
|
2011-03-01 23:48:07 +00:00
|
|
|
"DNS_R_NOOWNER when no owner name "
|
2011-02-26 02:26:33 +00:00
|
|
|
"is specified");
|
|
|
|
}
|
|
|
|
|
2011-12-08 16:07:22 +00:00
|
|
|
ATF_TC_BODY(nottl, tc) {
|
2011-02-26 02:26:33 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
UNUSED(tc);
|
|
|
|
|
2011-07-06 01:36:32 +00:00
|
|
|
result = dns_test_begin(NULL, ISC_FALSE);
|
2011-02-26 02:26:33 +00:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
2011-12-08 16:07:22 +00:00
|
|
|
result = test_master("testdata/master/master4.data",
|
2013-01-04 11:23:18 +11:00
|
|
|
dns_masterformat_text, NULL, NULL);
|
2011-02-26 02:26:33 +00:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
dns_test_end();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Bad class test */
|
2011-12-08 16:07:22 +00:00
|
|
|
ATF_TC(badclass);
|
|
|
|
ATF_TC_HEAD(badclass, tc) {
|
2011-02-26 02:26:33 +00:00
|
|
|
atf_tc_set_md_var(tc, "descr", "dns_master_loadfile() returns "
|
2011-03-01 23:48:07 +00:00
|
|
|
"DNS_R_BADCLASS when record class "
|
2011-02-26 02:26:33 +00:00
|
|
|
"doesn't match zone class");
|
|
|
|
}
|
2011-12-08 16:07:22 +00:00
|
|
|
ATF_TC_BODY(badclass, tc) {
|
2011-02-26 02:26:33 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
UNUSED(tc);
|
|
|
|
|
2011-07-06 01:36:32 +00:00
|
|
|
result = dns_test_begin(NULL, ISC_FALSE);
|
2011-02-26 02:26:33 +00:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
2011-12-08 16:07:22 +00:00
|
|
|
result = test_master("testdata/master/master5.data",
|
2013-01-04 11:23:18 +11:00
|
|
|
dns_masterformat_text, NULL, NULL);
|
2011-02-26 02:26:33 +00:00
|
|
|
ATF_REQUIRE_EQ(result, DNS_R_BADCLASS);
|
|
|
|
|
|
|
|
dns_test_end();
|
|
|
|
}
|
|
|
|
|
2012-08-16 09:42:14 +10:00
|
|
|
/* Too big rdata test */
|
|
|
|
ATF_TC(toobig);
|
|
|
|
ATF_TC_HEAD(toobig, tc) {
|
|
|
|
atf_tc_set_md_var(tc, "descr", "dns_master_loadfile() returns "
|
|
|
|
"ISC_R_NOSPACE when record is too big");
|
|
|
|
}
|
|
|
|
ATF_TC_BODY(toobig, tc) {
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
UNUSED(tc);
|
|
|
|
|
|
|
|
result = dns_test_begin(NULL, ISC_FALSE);
|
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
result = test_master("testdata/master/master15.data",
|
2013-01-04 11:23:18 +11:00
|
|
|
dns_masterformat_text, NULL, NULL);
|
2012-08-16 09:42:14 +10:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_NOSPACE);
|
|
|
|
|
|
|
|
dns_test_end();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Maximum rdata test */
|
|
|
|
ATF_TC(maxrdata);
|
|
|
|
ATF_TC_HEAD(maxrdata, tc) {
|
|
|
|
atf_tc_set_md_var(tc, "descr", "dns_master_loadfile() returns "
|
|
|
|
"ISC_R_SUCCESS when record is maximum "
|
|
|
|
"size");
|
|
|
|
}
|
|
|
|
ATF_TC_BODY(maxrdata, tc) {
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
UNUSED(tc);
|
|
|
|
|
|
|
|
result = dns_test_begin(NULL, ISC_FALSE);
|
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
result = test_master("testdata/master/master16.data",
|
2013-01-04 11:23:18 +11:00
|
|
|
dns_masterformat_text, NULL, NULL);
|
2012-08-16 09:42:14 +10:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
dns_test_end();
|
|
|
|
}
|
|
|
|
|
2011-02-26 02:26:33 +00:00
|
|
|
/* DNSKEY test */
|
2011-12-08 16:07:22 +00:00
|
|
|
ATF_TC(dnskey);
|
|
|
|
ATF_TC_HEAD(dnskey, tc) {
|
2011-02-26 02:26:33 +00:00
|
|
|
atf_tc_set_md_var(tc, "descr", "dns_master_loadfile() understands "
|
2011-03-01 23:48:07 +00:00
|
|
|
"DNSKEY with key material");
|
2011-02-26 02:26:33 +00:00
|
|
|
}
|
2011-12-08 16:07:22 +00:00
|
|
|
ATF_TC_BODY(dnskey, tc) {
|
2011-02-26 02:26:33 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
UNUSED(tc);
|
|
|
|
|
2011-07-06 01:36:32 +00:00
|
|
|
result = dns_test_begin(NULL, ISC_FALSE);
|
2011-02-26 02:26:33 +00:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
2011-12-08 16:07:22 +00:00
|
|
|
result = test_master("testdata/master/master6.data",
|
2013-01-04 11:23:18 +11:00
|
|
|
dns_masterformat_text, NULL, NULL);
|
2011-02-26 02:26:33 +00:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
dns_test_end();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* DNSKEY with no key material test */
|
2011-12-08 16:07:22 +00:00
|
|
|
ATF_TC(dnsnokey);
|
|
|
|
ATF_TC_HEAD(dnsnokey, tc) {
|
2011-02-26 02:26:33 +00:00
|
|
|
atf_tc_set_md_var(tc, "descr", "dns_master_loadfile() understands "
|
2011-03-01 23:48:07 +00:00
|
|
|
"DNSKEY with no key material");
|
2011-02-26 02:26:33 +00:00
|
|
|
}
|
2011-12-08 16:07:22 +00:00
|
|
|
ATF_TC_BODY(dnsnokey, tc) {
|
2011-02-26 02:26:33 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
UNUSED(tc);
|
|
|
|
|
2011-07-06 01:36:32 +00:00
|
|
|
result = dns_test_begin(NULL, ISC_FALSE);
|
2011-02-26 02:26:33 +00:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
2011-12-08 16:07:22 +00:00
|
|
|
result = test_master("testdata/master/master7.data",
|
2013-01-04 11:23:18 +11:00
|
|
|
dns_masterformat_text, NULL, NULL);
|
2011-02-26 02:26:33 +00:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
dns_test_end();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Include test */
|
2011-12-08 16:07:22 +00:00
|
|
|
ATF_TC(include);
|
|
|
|
ATF_TC_HEAD(include, tc) {
|
2011-02-26 02:26:33 +00:00
|
|
|
atf_tc_set_md_var(tc, "descr", "dns_master_loadfile() understands "
|
2011-03-01 23:48:07 +00:00
|
|
|
"$INCLUDE");
|
2011-02-26 02:26:33 +00:00
|
|
|
}
|
2011-12-08 16:07:22 +00:00
|
|
|
ATF_TC_BODY(include, tc) {
|
2011-02-26 02:26:33 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
UNUSED(tc);
|
|
|
|
|
2011-07-06 01:36:32 +00:00
|
|
|
result = dns_test_begin(NULL, ISC_FALSE);
|
2011-02-26 02:26:33 +00:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
2011-12-08 16:07:22 +00:00
|
|
|
result = test_master("testdata/master/master8.data",
|
2013-01-04 11:23:18 +11:00
|
|
|
dns_masterformat_text, NULL, NULL);
|
2011-02-26 02:26:33 +00:00
|
|
|
ATF_REQUIRE_EQ(result, DNS_R_SEENINCLUDE);
|
|
|
|
|
|
|
|
dns_test_end();
|
|
|
|
}
|
|
|
|
|
2012-01-31 03:35:41 +00:00
|
|
|
/* Include file list test */
|
|
|
|
ATF_TC(master_includelist);
|
|
|
|
ATF_TC_HEAD(master_includelist, tc) {
|
|
|
|
atf_tc_set_md_var(tc, "descr", "dns_master_loadfile4() returns "
|
|
|
|
"names of included file");
|
|
|
|
}
|
|
|
|
ATF_TC_BODY(master_includelist, tc) {
|
|
|
|
isc_result_t result;
|
|
|
|
char *filename = NULL;
|
|
|
|
|
|
|
|
UNUSED(tc);
|
|
|
|
|
|
|
|
result = dns_test_begin(NULL, ISC_FALSE);
|
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
2013-01-04 11:23:18 +11:00
|
|
|
result = setup_master(NULL, NULL);
|
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
2018-04-03 13:09:55 +02:00
|
|
|
result = dns_master_loadfile("testdata/master/master8.data",
|
|
|
|
&dns_origin, &dns_origin,
|
|
|
|
dns_rdataclass_in, 0, ISC_TRUE,
|
|
|
|
&callbacks, include_callback,
|
|
|
|
&filename, mctx, dns_masterformat_text, 0);
|
2012-01-31 03:35:41 +00:00
|
|
|
ATF_CHECK_EQ(result, DNS_R_SEENINCLUDE);
|
|
|
|
ATF_CHECK(filename != NULL);
|
|
|
|
if (filename != NULL) {
|
|
|
|
ATF_CHECK_STREQ(filename, "testdata/master/master7.data");
|
|
|
|
isc_mem_free(mctx, filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
dns_test_end();
|
|
|
|
}
|
2012-01-31 23:47:33 +00:00
|
|
|
|
2011-02-26 02:26:33 +00:00
|
|
|
/* Include failure test */
|
2011-12-08 16:07:22 +00:00
|
|
|
ATF_TC(includefail);
|
|
|
|
ATF_TC_HEAD(includefail, tc) {
|
2011-02-26 02:26:33 +00:00
|
|
|
atf_tc_set_md_var(tc, "descr", "dns_master_loadfile() understands "
|
2011-03-01 23:48:07 +00:00
|
|
|
"$INCLUDE failures");
|
2011-02-26 02:26:33 +00:00
|
|
|
}
|
2011-12-08 16:07:22 +00:00
|
|
|
ATF_TC_BODY(includefail, tc) {
|
2011-02-26 02:26:33 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
UNUSED(tc);
|
|
|
|
|
2011-07-06 01:36:32 +00:00
|
|
|
result = dns_test_begin(NULL, ISC_FALSE);
|
2011-02-26 02:26:33 +00:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
2011-12-08 16:07:22 +00:00
|
|
|
result = test_master("testdata/master/master9.data",
|
2013-01-04 11:23:18 +11:00
|
|
|
dns_masterformat_text, NULL, NULL);
|
2011-02-26 02:26:33 +00:00
|
|
|
ATF_REQUIRE_EQ(result, DNS_R_BADCLASS);
|
|
|
|
|
|
|
|
dns_test_end();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Non-empty blank lines test */
|
2011-12-08 16:07:22 +00:00
|
|
|
ATF_TC(blanklines);
|
|
|
|
ATF_TC_HEAD(blanklines, tc) {
|
2011-02-26 02:26:33 +00:00
|
|
|
atf_tc_set_md_var(tc, "descr", "dns_master_loadfile() handles "
|
2011-03-01 23:48:07 +00:00
|
|
|
"non-empty blank lines");
|
2011-02-26 02:26:33 +00:00
|
|
|
}
|
2011-12-08 16:07:22 +00:00
|
|
|
ATF_TC_BODY(blanklines, tc) {
|
2011-02-26 02:26:33 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
UNUSED(tc);
|
|
|
|
|
2011-07-06 01:36:32 +00:00
|
|
|
result = dns_test_begin(NULL, ISC_FALSE);
|
2011-02-26 02:26:33 +00:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
2011-12-08 16:07:22 +00:00
|
|
|
result = test_master("testdata/master/master10.data",
|
2013-01-04 11:23:18 +11:00
|
|
|
dns_masterformat_text, NULL, NULL);
|
2011-02-26 02:26:33 +00:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
dns_test_end();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* SOA leading zeroes test */
|
2011-12-08 16:07:22 +00:00
|
|
|
ATF_TC(leadingzero);
|
|
|
|
ATF_TC_HEAD(leadingzero, tc) {
|
2011-02-26 02:26:33 +00:00
|
|
|
atf_tc_set_md_var(tc, "descr", "dns_master_loadfile() allows "
|
2011-03-01 23:48:07 +00:00
|
|
|
"leading zeroes in SOA");
|
2011-02-26 02:26:33 +00:00
|
|
|
}
|
2011-12-08 16:07:22 +00:00
|
|
|
ATF_TC_BODY(leadingzero, tc) {
|
2011-02-26 02:26:33 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
UNUSED(tc);
|
|
|
|
|
2011-07-06 01:36:32 +00:00
|
|
|
result = dns_test_begin(NULL, ISC_FALSE);
|
2011-02-26 02:26:33 +00:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
2011-12-08 16:07:22 +00:00
|
|
|
result = test_master("testdata/master/master11.data",
|
2013-01-04 11:23:18 +11:00
|
|
|
dns_masterformat_text, NULL, NULL);
|
2011-02-26 02:26:33 +00:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
dns_test_end();
|
|
|
|
}
|
|
|
|
|
2011-12-08 16:07:22 +00:00
|
|
|
ATF_TC(totext);
|
|
|
|
ATF_TC_HEAD(totext, tc) {
|
2011-09-07 19:11:14 +00:00
|
|
|
atf_tc_set_md_var(tc, "descr", "masterfile totext tests");
|
|
|
|
}
|
2011-12-08 16:07:22 +00:00
|
|
|
ATF_TC_BODY(totext, tc) {
|
2011-09-07 19:11:14 +00:00
|
|
|
isc_result_t result;
|
|
|
|
dns_rdataset_t rdataset;
|
|
|
|
dns_rdatalist_t rdatalist;
|
|
|
|
isc_buffer_t target;
|
|
|
|
unsigned char buf[BIGBUFLEN];
|
|
|
|
|
|
|
|
UNUSED(tc);
|
|
|
|
|
|
|
|
result = dns_test_begin(NULL, ISC_FALSE);
|
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
/* First, test with an empty rdataset */
|
2015-03-03 16:43:42 +11:00
|
|
|
dns_rdatalist_init(&rdatalist);
|
2011-09-07 19:11:14 +00:00
|
|
|
rdatalist.rdclass = dns_rdataclass_in;
|
|
|
|
rdatalist.type = dns_rdatatype_none;
|
|
|
|
rdatalist.covers = dns_rdatatype_none;
|
|
|
|
|
|
|
|
dns_rdataset_init(&rdataset);
|
|
|
|
result = dns_rdatalist_tordataset(&rdatalist, &rdataset);
|
|
|
|
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
isc_buffer_init(&target, buf, BIGBUFLEN);
|
|
|
|
result = dns_master_rdatasettotext(dns_rootname,
|
|
|
|
&rdataset, &dns_master_style_debug,
|
|
|
|
&target);
|
|
|
|
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
|
|
|
ATF_CHECK_EQ(isc_buffer_usedlength(&target), 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX: We will also need to add tests for dumping various
|
|
|
|
* rdata types, classes, etc, and comparing the results against
|
|
|
|
* known-good output.
|
|
|
|
*/
|
|
|
|
|
|
|
|
dns_test_end();
|
|
|
|
}
|
|
|
|
|
2011-12-08 16:07:22 +00:00
|
|
|
/* Raw load */
|
|
|
|
ATF_TC(loadraw);
|
|
|
|
ATF_TC_HEAD(loadraw, tc) {
|
|
|
|
atf_tc_set_md_var(tc, "descr", "dns_master_loadfile() loads a "
|
|
|
|
"valid raw file and returns success");
|
|
|
|
}
|
|
|
|
ATF_TC_BODY(loadraw, tc) {
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
UNUSED(tc);
|
|
|
|
|
|
|
|
result = dns_test_begin(NULL, ISC_FALSE);
|
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
/* Raw format version 0 */
|
|
|
|
result = test_master("testdata/master/master12.data",
|
2013-01-04 11:23:18 +11:00
|
|
|
dns_masterformat_raw, NULL, NULL);
|
2011-12-08 16:07:22 +00:00
|
|
|
ATF_CHECK_STREQ(isc_result_totext(result), "success");
|
|
|
|
ATF_CHECK(headerset);
|
|
|
|
ATF_CHECK_EQ(header.flags, 0);
|
|
|
|
|
|
|
|
/* Raw format version 1, no source serial */
|
|
|
|
result = test_master("testdata/master/master13.data",
|
2013-01-04 11:23:18 +11:00
|
|
|
dns_masterformat_raw, NULL, NULL);
|
2011-12-08 16:07:22 +00:00
|
|
|
ATF_CHECK_STREQ(isc_result_totext(result), "success");
|
|
|
|
ATF_CHECK(headerset);
|
|
|
|
ATF_CHECK_EQ(header.flags, 0);
|
|
|
|
|
|
|
|
/* Raw format version 1, source serial == 2011120101 */
|
|
|
|
result = test_master("testdata/master/master14.data",
|
2013-01-04 11:23:18 +11:00
|
|
|
dns_masterformat_raw, NULL, NULL);
|
2011-12-08 16:07:22 +00:00
|
|
|
ATF_CHECK_STREQ(isc_result_totext(result), "success");
|
|
|
|
ATF_CHECK(headerset);
|
|
|
|
ATF_CHECK((header.flags & DNS_MASTERRAW_SOURCESERIALSET) != 0);
|
|
|
|
ATF_CHECK_EQ(header.sourceserial, 2011120101);
|
|
|
|
|
|
|
|
dns_test_end();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Raw dump*/
|
|
|
|
ATF_TC(dumpraw);
|
|
|
|
ATF_TC_HEAD(dumpraw, tc) {
|
|
|
|
atf_tc_set_md_var(tc, "descr", "dns_master_dump*() functions "
|
|
|
|
"dump valid raw files");
|
|
|
|
}
|
|
|
|
ATF_TC_BODY(dumpraw, tc) {
|
|
|
|
isc_result_t result;
|
|
|
|
dns_db_t *db = NULL;
|
|
|
|
dns_dbversion_t *version = NULL;
|
2015-01-20 13:29:18 -08:00
|
|
|
char myorigin[sizeof(TEST_ORIGIN)];
|
|
|
|
dns_name_t dnsorigin;
|
2011-12-08 16:07:22 +00:00
|
|
|
isc_buffer_t source, target;
|
2015-01-20 13:29:18 -08:00
|
|
|
unsigned char namebuf[BUFLEN];
|
2011-12-08 16:07:22 +00:00
|
|
|
int len;
|
|
|
|
|
|
|
|
UNUSED(tc);
|
|
|
|
|
2017-09-13 00:14:37 -07:00
|
|
|
strlcpy(myorigin, TEST_ORIGIN, sizeof(myorigin));
|
2015-01-20 13:29:18 -08:00
|
|
|
len = strlen(myorigin);
|
|
|
|
isc_buffer_init(&source, myorigin, len);
|
2011-12-08 16:07:22 +00:00
|
|
|
isc_buffer_add(&source, len);
|
|
|
|
isc_buffer_setactive(&source, len);
|
2015-01-20 13:29:18 -08:00
|
|
|
isc_buffer_init(&target, namebuf, BUFLEN);
|
|
|
|
dns_name_init(&dnsorigin, NULL);
|
|
|
|
result = dns_name_fromtext(&dnsorigin, &source, dns_rootname,
|
2011-12-08 16:07:22 +00:00
|
|
|
0, &target);
|
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
result = dns_test_begin(NULL, ISC_FALSE);
|
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
result = dns_db_create(mctx, "rbt", &dnsorigin, dns_dbtype_zone,
|
2011-12-08 16:07:22 +00:00
|
|
|
dns_rdataclass_in, 0, NULL, &db);
|
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
2018-04-03 13:22:09 +02:00
|
|
|
result = dns_db_load(db, "testdata/master/master1.data",
|
|
|
|
dns_masterformat_text, 0);
|
2011-12-08 16:07:22 +00:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
dns_db_currentversion(db, &version);
|
|
|
|
|
2018-04-03 13:09:55 +02:00
|
|
|
result = dns_master_dump(mctx, db, version,
|
|
|
|
&dns_master_style_default, "test.dump",
|
|
|
|
dns_masterformat_raw, NULL);
|
2011-12-08 16:07:22 +00:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
2013-01-04 11:23:18 +11:00
|
|
|
result = test_master("test.dump", dns_masterformat_raw, NULL, NULL);
|
2011-12-08 16:07:22 +00:00
|
|
|
ATF_CHECK_STREQ(isc_result_totext(result), "success");
|
|
|
|
ATF_CHECK(headerset);
|
|
|
|
ATF_CHECK_EQ(header.flags, 0);
|
|
|
|
|
|
|
|
dns_master_initrawheader(&header);
|
|
|
|
header.sourceserial = 12345;
|
|
|
|
header.flags |= DNS_MASTERRAW_SOURCESERIALSET;
|
|
|
|
|
|
|
|
unlink("test.dump");
|
2018-04-03 13:09:55 +02:00
|
|
|
result = dns_master_dump(mctx, db, version,
|
|
|
|
&dns_master_style_default, "test.dump",
|
|
|
|
dns_masterformat_raw, &header);
|
2011-12-08 16:07:22 +00:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
2013-01-04 11:23:18 +11:00
|
|
|
result = test_master("test.dump", dns_masterformat_raw, NULL, NULL);
|
2011-12-08 16:07:22 +00:00
|
|
|
ATF_CHECK_STREQ(isc_result_totext(result), "success");
|
|
|
|
ATF_CHECK(headerset);
|
|
|
|
ATF_CHECK((header.flags & DNS_MASTERRAW_SOURCESERIALSET) != 0);
|
|
|
|
ATF_CHECK_EQ(header.sourceserial, 12345);
|
|
|
|
|
|
|
|
unlink("test.dump");
|
|
|
|
dns_db_closeversion(db, &version, ISC_FALSE);
|
|
|
|
dns_db_detach(&db);
|
|
|
|
dns_test_end();
|
|
|
|
}
|
|
|
|
|
2013-01-04 11:23:18 +11:00
|
|
|
static const char *warn_expect_value;
|
|
|
|
static isc_boolean_t warn_expect_result;
|
|
|
|
|
|
|
|
static void
|
2015-01-20 13:29:18 -08:00
|
|
|
warn_expect(struct dns_rdatacallbacks *mycallbacks, const char *fmt, ...) {
|
2013-01-04 11:23:18 +11:00
|
|
|
char buf[4096];
|
|
|
|
va_list ap;
|
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
UNUSED(mycallbacks);
|
2013-01-04 11:23:18 +11:00
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vsnprintf(buf, sizeof(buf), fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
if (warn_expect_value != NULL && strstr(buf, warn_expect_value) != NULL)
|
|
|
|
warn_expect_result = ISC_TRUE;
|
|
|
|
}
|
|
|
|
|
2012-12-18 16:17:55 -08:00
|
|
|
/* Origin change test */
|
|
|
|
ATF_TC(neworigin);
|
|
|
|
ATF_TC_HEAD(neworigin, tc) {
|
|
|
|
atf_tc_set_md_var(tc, "descr", "dns_master_loadfile() rejects "
|
|
|
|
"zones with inherited name following "
|
|
|
|
"$ORIGIN");
|
|
|
|
}
|
|
|
|
ATF_TC_BODY(neworigin, tc) {
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
UNUSED(tc);
|
|
|
|
|
|
|
|
result = dns_test_begin(NULL, ISC_FALSE);
|
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
2013-01-04 11:23:18 +11:00
|
|
|
warn_expect_value = "record with inherited owner";
|
|
|
|
warn_expect_result = ISC_FALSE;
|
2012-12-18 16:17:55 -08:00
|
|
|
result = test_master("testdata/master/master17.data",
|
2013-01-04 11:23:18 +11:00
|
|
|
dns_masterformat_text, warn_expect, NULL);
|
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
ATF_CHECK_MSG(warn_expect_result, "'%s' warning not emitted",
|
|
|
|
warn_expect_value);
|
2012-12-18 16:17:55 -08:00
|
|
|
|
|
|
|
dns_test_end();
|
|
|
|
}
|
|
|
|
|
2011-02-26 02:26:33 +00:00
|
|
|
/*
|
|
|
|
* Main
|
|
|
|
*/
|
|
|
|
ATF_TP_ADD_TCS(tp) {
|
2011-12-08 16:07:22 +00:00
|
|
|
ATF_TP_ADD_TC(tp, load);
|
|
|
|
ATF_TP_ADD_TC(tp, unexpected);
|
|
|
|
ATF_TP_ADD_TC(tp, noowner);
|
|
|
|
ATF_TP_ADD_TC(tp, nottl);
|
|
|
|
ATF_TP_ADD_TC(tp, badclass);
|
|
|
|
ATF_TP_ADD_TC(tp, dnskey);
|
|
|
|
ATF_TP_ADD_TC(tp, dnsnokey);
|
|
|
|
ATF_TP_ADD_TC(tp, include);
|
2012-01-31 03:35:41 +00:00
|
|
|
ATF_TP_ADD_TC(tp, master_includelist);
|
2011-12-08 16:07:22 +00:00
|
|
|
ATF_TP_ADD_TC(tp, includefail);
|
|
|
|
ATF_TP_ADD_TC(tp, blanklines);
|
|
|
|
ATF_TP_ADD_TC(tp, leadingzero);
|
|
|
|
ATF_TP_ADD_TC(tp, totext);
|
|
|
|
ATF_TP_ADD_TC(tp, loadraw);
|
|
|
|
ATF_TP_ADD_TC(tp, dumpraw);
|
2012-08-16 09:42:14 +10:00
|
|
|
ATF_TP_ADD_TC(tp, toobig);
|
|
|
|
ATF_TP_ADD_TC(tp, maxrdata);
|
2012-12-18 16:17:55 -08:00
|
|
|
ATF_TP_ADD_TC(tp, neworigin);
|
2011-02-26 02:26:33 +00:00
|
|
|
|
|
|
|
return (atf_no_error());
|
|
|
|
}
|
|
|
|
|