2011-02-26 02:26:33 +00:00
|
|
|
/*
|
2012-01-31 23:47:33 +00:00
|
|
|
* Copyright (C) 2011, 2012 Internet Systems Consortium, Inc. ("ISC")
|
2011-02-26 02:26:33 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or 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.
|
|
|
|
*/
|
|
|
|
|
2012-03-08 00:21:15 +11:00
|
|
|
/* $Id$ */
|
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>
|
|
|
|
|
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
|
|
|
|
#define BIGBUFLEN (64 * 1024)
|
|
|
|
#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-02-26 02:26:33 +00:00
|
|
|
static isc_result_t
|
|
|
|
add_callback(void *arg, dns_name_t *owner, dns_rdataset_t *dataset);
|
|
|
|
|
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
|
|
|
|
add_callback(void *arg, dns_name_t *owner, dns_rdataset_t *dataset) {
|
|
|
|
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
|
|
|
|
setup_master() {
|
2011-02-26 02:26:33 +00:00
|
|
|
isc_result_t result;
|
|
|
|
int len;
|
|
|
|
isc_buffer_t source;
|
|
|
|
isc_buffer_t target;
|
|
|
|
|
|
|
|
strcpy(origin, TEST_ORIGIN);
|
|
|
|
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;
|
2012-01-31 03:35:41 +00:00
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
test_master(const char *testfile, dns_masterformat_t format) {
|
|
|
|
isc_result_t result;
|
2011-12-08 16:07:22 +00:00
|
|
|
headerset = ISC_FALSE;
|
|
|
|
result = dns_master_loadfile2(testfile, &dns_origin, &dns_origin,
|
|
|
|
dns_rdataclass_in, ISC_TRUE,
|
|
|
|
&callbacks, mctx, format);
|
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);
|
|
|
|
|
2012-01-31 03:35:41 +00:00
|
|
|
setup_master();
|
2011-12-08 16:07:22 +00:00
|
|
|
result = test_master("testdata/master/master1.data",
|
|
|
|
dns_masterformat_text);
|
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);
|
|
|
|
|
2012-01-31 03:35:41 +00:00
|
|
|
setup_master();
|
2011-12-08 16:07:22 +00:00
|
|
|
result = test_master("testdata/master/master2.data",
|
|
|
|
dns_masterformat_text);
|
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);
|
|
|
|
|
2012-01-31 03:35:41 +00:00
|
|
|
setup_master();
|
2011-12-08 16:07:22 +00:00
|
|
|
result = test_master("testdata/master/master3.data",
|
|
|
|
dns_masterformat_text);
|
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);
|
|
|
|
|
2012-01-31 03:35:41 +00:00
|
|
|
setup_master();
|
2011-12-08 16:07:22 +00:00
|
|
|
result = test_master("testdata/master/master4.data",
|
|
|
|
dns_masterformat_text);
|
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);
|
|
|
|
|
2012-01-31 03:35:41 +00:00
|
|
|
setup_master();
|
2011-12-08 16:07:22 +00:00
|
|
|
result = test_master("testdata/master/master5.data",
|
|
|
|
dns_masterformat_text);
|
2011-02-26 02:26:33 +00:00
|
|
|
ATF_REQUIRE_EQ(result, DNS_R_BADCLASS);
|
|
|
|
|
|
|
|
dns_test_end();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
2012-01-31 03:35:41 +00:00
|
|
|
setup_master();
|
2011-12-08 16:07:22 +00:00
|
|
|
result = test_master("testdata/master/master6.data",
|
|
|
|
dns_masterformat_text);
|
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);
|
|
|
|
|
2012-01-31 03:35:41 +00:00
|
|
|
setup_master();
|
2011-12-08 16:07:22 +00:00
|
|
|
result = test_master("testdata/master/master7.data",
|
|
|
|
dns_masterformat_text);
|
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);
|
|
|
|
|
2012-01-31 03:35:41 +00:00
|
|
|
setup_master();
|
2011-12-08 16:07:22 +00:00
|
|
|
result = test_master("testdata/master/master8.data",
|
|
|
|
dns_masterformat_text);
|
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);
|
|
|
|
|
|
|
|
setup_master();
|
|
|
|
result = dns_master_loadfile4("testdata/master/master8.data",
|
|
|
|
&dns_origin, &dns_origin,
|
|
|
|
dns_rdataclass_in, 0, ISC_TRUE,
|
|
|
|
&callbacks, include_callback,
|
|
|
|
&filename, mctx, dns_masterformat_text);
|
|
|
|
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);
|
|
|
|
|
2012-01-31 03:35:41 +00:00
|
|
|
setup_master();
|
2011-12-08 16:07:22 +00:00
|
|
|
result = test_master("testdata/master/master9.data",
|
|
|
|
dns_masterformat_text);
|
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);
|
|
|
|
|
2012-01-31 03:35:41 +00:00
|
|
|
setup_master();
|
2011-12-08 16:07:22 +00:00
|
|
|
result = test_master("testdata/master/master10.data",
|
|
|
|
dns_masterformat_text);
|
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);
|
|
|
|
|
2012-01-31 03:35:41 +00:00
|
|
|
setup_master();
|
2011-12-08 16:07:22 +00:00
|
|
|
result = test_master("testdata/master/master11.data",
|
|
|
|
dns_masterformat_text);
|
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 */
|
|
|
|
rdatalist.rdclass = dns_rdataclass_in;
|
|
|
|
rdatalist.type = dns_rdatatype_none;
|
|
|
|
rdatalist.covers = dns_rdatatype_none;
|
|
|
|
rdatalist.ttl = 0;
|
|
|
|
ISC_LIST_INIT(rdatalist.rdata);
|
|
|
|
ISC_LINK_INIT(&rdatalist, link);
|
|
|
|
|
|
|
|
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 */
|
2012-01-31 03:35:41 +00:00
|
|
|
setup_master();
|
2011-12-08 16:07:22 +00:00
|
|
|
result = test_master("testdata/master/master12.data",
|
|
|
|
dns_masterformat_raw);
|
|
|
|
ATF_CHECK_STREQ(isc_result_totext(result), "success");
|
|
|
|
ATF_CHECK(headerset);
|
|
|
|
ATF_CHECK_EQ(header.flags, 0);
|
|
|
|
|
|
|
|
/* Raw format version 1, no source serial */
|
2012-01-31 03:35:41 +00:00
|
|
|
setup_master();
|
2011-12-08 16:07:22 +00:00
|
|
|
result = test_master("testdata/master/master13.data",
|
|
|
|
dns_masterformat_raw);
|
|
|
|
ATF_CHECK_STREQ(isc_result_totext(result), "success");
|
|
|
|
ATF_CHECK(headerset);
|
|
|
|
ATF_CHECK_EQ(header.flags, 0);
|
|
|
|
|
|
|
|
/* Raw format version 1, source serial == 2011120101 */
|
2012-01-31 03:35:41 +00:00
|
|
|
setup_master();
|
2011-12-08 16:07:22 +00:00
|
|
|
result = test_master("testdata/master/master14.data",
|
|
|
|
dns_masterformat_raw);
|
|
|
|
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;
|
|
|
|
char origin[sizeof(TEST_ORIGIN)];
|
|
|
|
dns_name_t dns_origin;
|
|
|
|
isc_buffer_t source, target;
|
|
|
|
unsigned char name_buf[BUFLEN];
|
|
|
|
int len;
|
|
|
|
|
|
|
|
UNUSED(tc);
|
|
|
|
|
|
|
|
strcpy(origin, TEST_ORIGIN);
|
|
|
|
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);
|
|
|
|
result = dns_name_fromtext(&dns_origin, &source, dns_rootname,
|
|
|
|
0, &target);
|
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
result = dns_test_begin(NULL, ISC_FALSE);
|
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
result = dns_db_create(mctx, "rbt", &dns_origin, dns_dbtype_zone,
|
|
|
|
dns_rdataclass_in, 0, NULL, &db);
|
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
result = dns_db_load(db, "testdata/master/master1.data");
|
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
dns_db_currentversion(db, &version);
|
|
|
|
|
|
|
|
result = dns_master_dump2(mctx, db, version,
|
|
|
|
&dns_master_style_default, "test.dump",
|
|
|
|
dns_masterformat_raw);
|
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
2012-01-31 03:35:41 +00:00
|
|
|
setup_master();
|
2011-12-08 16:07:22 +00:00
|
|
|
result = test_master("test.dump", dns_masterformat_raw);
|
|
|
|
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");
|
|
|
|
result = dns_master_dump3(mctx, db, version,
|
|
|
|
&dns_master_style_default, "test.dump",
|
|
|
|
dns_masterformat_raw, &header);
|
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
2012-01-31 03:35:41 +00:00
|
|
|
setup_master();
|
2011-12-08 16:07:22 +00:00
|
|
|
result = test_master("test.dump", dns_masterformat_raw);
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
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);
|
2011-02-26 02:26:33 +00:00
|
|
|
|
|
|
|
return (atf_no_error());
|
|
|
|
}
|
|
|
|
|