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
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
#if HAVE_CMOCKA
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <setjmp.h>
|
2011-02-26 02:26:33 +00:00
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
#include <stdbool.h>
|
2012-05-14 10:06:05 -07:00
|
|
|
#include <stdio.h>
|
2018-11-14 20:18:19 +08:00
|
|
|
#include <stdlib.h>
|
2011-02-26 02:26:33 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
#define UNIT_TESTING
|
|
|
|
#include <cmocka.h>
|
|
|
|
|
|
|
|
#include <isc/util.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"
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
static int
|
|
|
|
_setup(void **state) {
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
UNUSED(state);
|
|
|
|
|
|
|
|
result = dns_test_begin(NULL, false);
|
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
_teardown(void **state) {
|
|
|
|
UNUSED(state);
|
|
|
|
|
|
|
|
dns_test_end();
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
2011-02-26 02:26:33 +00:00
|
|
|
|
|
|
|
#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;
|
2018-04-17 08:29:14 -07:00
|
|
|
static bool headerset;
|
2011-12-08 16:07:22 +00:00
|
|
|
|
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);
|
2018-04-17 08:29:14 -07:00
|
|
|
result = dns_rdataset_totext(dataset, owner, false, false,
|
2011-02-26 02:26:33 +00:00
|
|
|
&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;
|
2018-04-17 08:29:14 -07:00
|
|
|
headerset = true;
|
2011-12-08 16:07:22 +00:00
|
|
|
}
|
|
|
|
|
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);
|
2018-11-14 20:18:19 +08:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2011-02-26 02:26:33 +00:00
|
|
|
return(result);
|
2018-11-14 20:18:19 +08:00
|
|
|
}
|
2011-02-26 02:26:33 +00:00
|
|
|
|
|
|
|
dns_rdatacallbacks_init_stdio(&callbacks);
|
|
|
|
callbacks.add = add_callback;
|
2011-12-08 16:07:22 +00:00
|
|
|
callbacks.rawdata = rawdata_callback;
|
|
|
|
callbacks.zone = NULL;
|
2018-11-14 20:18:19 +08:00
|
|
|
if (warn != NULL) {
|
2013-01-04 11:23:18 +11:00
|
|
|
callbacks.warn = warn;
|
2018-11-14 20:18:19 +08:00
|
|
|
}
|
|
|
|
if (error != NULL) {
|
2013-01-04 11:23:18 +11:00
|
|
|
callbacks.error = error;
|
2018-11-14 20:18:19 +08:00
|
|
|
}
|
2018-04-17 08:29:14 -07:00
|
|
|
headerset = 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);
|
2018-11-14 20:18:19 +08:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2013-01-04 11:23:18 +11:00
|
|
|
return(result);
|
2018-11-14 20:18:19 +08:00
|
|
|
}
|
2013-01-04 11:23:18 +11:00
|
|
|
|
2018-04-03 13:09:55 +02:00
|
|
|
result = dns_master_loadfile(testfile, &dns_origin, &dns_origin,
|
2018-04-17 08:29:14 -07:00
|
|
|
dns_rdataclass_in, true, 0,
|
2018-04-03 13:09:55 +02:00
|
|
|
&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
|
|
|
/*
|
2018-11-14 20:18:19 +08:00
|
|
|
* Successful load test:
|
|
|
|
* dns_master_loadfile() loads a valid master file and returns success
|
2011-02-26 02:26:33 +00:00
|
|
|
*/
|
2018-11-14 20:18:19 +08:00
|
|
|
static void
|
|
|
|
load_test(void **state) {
|
2011-02-26 02:26:33 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
UNUSED(state);
|
2011-02-26 02:26:33 +00:00
|
|
|
|
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);
|
2018-11-14 20:18:19 +08:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2011-02-26 02:26:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
/*
|
|
|
|
* Unexpected end of file test:
|
|
|
|
* dns_master_loadfile() returns DNS_R_UNEXPECTED when file ends too soon
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
unexpected_test(void **state) {
|
2011-02-26 02:26:33 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
UNUSED(state);
|
2011-02-26 02:26:33 +00:00
|
|
|
|
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);
|
2018-11-14 20:18:19 +08:00
|
|
|
assert_int_equal(result, ISC_R_UNEXPECTEDEND);
|
2011-02-26 02:26:33 +00:00
|
|
|
}
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
/*
|
|
|
|
* No owner test:
|
|
|
|
* dns_master_loadfile() accepts broken zones with no TTL for first record
|
|
|
|
* if it is an SOA
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
noowner_test(void **state) {
|
2011-02-26 02:26:33 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
UNUSED(state);
|
2011-02-26 02:26:33 +00:00
|
|
|
|
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);
|
2018-11-14 20:18:19 +08:00
|
|
|
assert_int_equal(result, DNS_R_NOOWNER);
|
2011-02-26 02:26:33 +00:00
|
|
|
}
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
/*
|
|
|
|
* No TTL test:
|
|
|
|
* dns_master_loadfile() returns DNS_R_NOOWNER when no owner name is
|
|
|
|
* specified
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
nottl_test(void **state) {
|
2011-02-26 02:26:33 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
UNUSED(state);
|
2011-02-26 02:26:33 +00:00
|
|
|
|
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);
|
2018-11-14 20:18:19 +08:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2011-02-26 02:26:33 +00:00
|
|
|
}
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
/*
|
|
|
|
* Bad class test:
|
|
|
|
* dns_master_loadfile() returns DNS_R_BADCLASS when record class doesn't
|
|
|
|
* match zone class
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
badclass_test(void **state) {
|
2011-02-26 02:26:33 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
UNUSED(state);
|
2011-02-26 02:26:33 +00:00
|
|
|
|
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);
|
2018-11-14 20:18:19 +08:00
|
|
|
assert_int_equal(result, DNS_R_BADCLASS);
|
2011-02-26 02:26:33 +00:00
|
|
|
}
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
/*
|
|
|
|
* Too big rdata test:
|
|
|
|
* dns_master_loadfile() returns ISC_R_NOSPACE when record is too big
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
toobig_test(void **state) {
|
2012-08-16 09:42:14 +10:00
|
|
|
isc_result_t result;
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
UNUSED(state);
|
2012-08-16 09:42:14 +10:00
|
|
|
|
|
|
|
result = test_master("testdata/master/master15.data",
|
2013-01-04 11:23:18 +11:00
|
|
|
dns_masterformat_text, NULL, NULL);
|
2018-11-14 20:18:19 +08:00
|
|
|
assert_int_equal(result, ISC_R_NOSPACE);
|
2012-08-16 09:42:14 +10:00
|
|
|
}
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
/*
|
|
|
|
* Maximum rdata test:
|
|
|
|
* dns_master_loadfile() returns ISC_R_SUCCESS when record is maximum size
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
maxrdata_test(void **state) {
|
2012-08-16 09:42:14 +10:00
|
|
|
isc_result_t result;
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
UNUSED(state);
|
2012-08-16 09:42:14 +10:00
|
|
|
|
|
|
|
result = test_master("testdata/master/master16.data",
|
2013-01-04 11:23:18 +11:00
|
|
|
dns_masterformat_text, NULL, NULL);
|
2018-11-14 20:18:19 +08:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2012-08-16 09:42:14 +10:00
|
|
|
}
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
/*
|
|
|
|
* DNSKEY test:
|
|
|
|
* dns_master_loadfile() understands DNSKEY with key material
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
dnskey_test(void **state) {
|
2011-02-26 02:26:33 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
UNUSED(state);
|
2011-02-26 02:26:33 +00:00
|
|
|
|
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);
|
2018-11-14 20:18:19 +08:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2011-02-26 02:26:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
/*
|
|
|
|
* DNSKEY with no key material test:
|
|
|
|
* dns_master_loadfile() understands DNSKEY with no key material
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
dnsnokey_test(void **state) {
|
2011-02-26 02:26:33 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
UNUSED(state);
|
2011-02-26 02:26:33 +00:00
|
|
|
|
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);
|
2018-11-14 20:18:19 +08:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2011-02-26 02:26:33 +00:00
|
|
|
}
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
/*
|
|
|
|
* Include test:
|
|
|
|
* dns_master_loadfile() understands $INCLUDE
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
include_test(void **state) {
|
2011-02-26 02:26:33 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
UNUSED(state);
|
2011-02-26 02:26:33 +00:00
|
|
|
|
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);
|
2018-11-14 20:18:19 +08:00
|
|
|
assert_int_equal(result, DNS_R_SEENINCLUDE);
|
2011-02-26 02:26:33 +00:00
|
|
|
}
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
/*
|
|
|
|
* Include file list test:
|
|
|
|
* dns_master_loadfile4() returns names of included file
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
master_includelist_test(void **state) {
|
2012-01-31 03:35:41 +00:00
|
|
|
isc_result_t result;
|
|
|
|
char *filename = NULL;
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
UNUSED(state);
|
2012-01-31 03:35:41 +00:00
|
|
|
|
2013-01-04 11:23:18 +11:00
|
|
|
result = setup_master(NULL, NULL);
|
2018-11-14 20:18:19 +08:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2013-01-04 11:23:18 +11:00
|
|
|
|
2018-04-03 13:09:55 +02:00
|
|
|
result = dns_master_loadfile("testdata/master/master8.data",
|
|
|
|
&dns_origin, &dns_origin,
|
2018-04-17 08:29:14 -07:00
|
|
|
dns_rdataclass_in, 0, true,
|
2018-04-03 13:09:55 +02:00
|
|
|
&callbacks, include_callback,
|
|
|
|
&filename, mctx, dns_masterformat_text, 0);
|
2018-11-14 20:18:19 +08:00
|
|
|
assert_int_equal(result, DNS_R_SEENINCLUDE);
|
|
|
|
assert_non_null(filename);
|
2012-01-31 03:35:41 +00:00
|
|
|
if (filename != NULL) {
|
2018-11-14 20:18:19 +08:00
|
|
|
assert_string_equal(filename, "testdata/master/master7.data");
|
2012-01-31 03:35:41 +00:00
|
|
|
isc_mem_free(mctx, filename);
|
|
|
|
}
|
|
|
|
}
|
2012-01-31 23:47:33 +00:00
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
/*
|
|
|
|
* Include failure test:
|
|
|
|
* dns_master_loadfile() understands $INCLUDE failures
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
includefail_test(void **state) {
|
2011-02-26 02:26:33 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
UNUSED(state);
|
2011-02-26 02:26:33 +00:00
|
|
|
|
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);
|
2018-11-14 20:18:19 +08:00
|
|
|
assert_int_equal(result, DNS_R_BADCLASS);
|
2011-02-26 02:26:33 +00:00
|
|
|
}
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
/*
|
|
|
|
* Non-empty blank lines test:
|
|
|
|
* dns_master_loadfile() handles non-empty blank lines
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
blanklines_test(void **state) {
|
2011-02-26 02:26:33 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
UNUSED(state);
|
2011-02-26 02:26:33 +00:00
|
|
|
|
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);
|
2018-11-14 20:18:19 +08:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2011-02-26 02:26:33 +00:00
|
|
|
}
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
/*
|
|
|
|
* SOA leading zeroes test:
|
|
|
|
* dns_master_loadfile() allows leading zeroes in SOA
|
|
|
|
*/
|
2011-02-26 02:26:33 +00:00
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
static void
|
|
|
|
leadingzero_test(void **state) {
|
|
|
|
isc_result_t result;
|
2011-02-26 02:26:33 +00:00
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
UNUSED(state);
|
2011-02-26 02:26:33 +00:00
|
|
|
|
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);
|
2018-11-14 20:18:19 +08:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2011-02-26 02:26:33 +00:00
|
|
|
}
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
/* masterfile totext tests */
|
|
|
|
static void
|
|
|
|
totext_test(void **state) {
|
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];
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
UNUSED(state);
|
2011-09-07 19:11:14 +00:00
|
|
|
|
|
|
|
/* 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);
|
2018-11-14 20:18:19 +08:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2011-09-07 19:11:14 +00:00
|
|
|
|
|
|
|
isc_buffer_init(&target, buf, BIGBUFLEN);
|
|
|
|
result = dns_master_rdatasettotext(dns_rootname,
|
|
|
|
&rdataset, &dns_master_style_debug,
|
|
|
|
&target);
|
2018-11-14 20:18:19 +08:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
assert_int_equal(isc_buffer_usedlength(&target), 0);
|
2011-09-07 19:11:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX: We will also need to add tests for dumping various
|
|
|
|
* rdata types, classes, etc, and comparing the results against
|
|
|
|
* known-good output.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
/*
|
|
|
|
* Raw load test:
|
|
|
|
* dns_master_loadfile() loads a valid raw file and returns success
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
loadraw_test(void **state) {
|
2011-12-08 16:07:22 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
UNUSED(state);
|
2011-12-08 16:07:22 +00:00
|
|
|
|
|
|
|
/* Raw format version 0 */
|
|
|
|
result = test_master("testdata/master/master12.data",
|
2013-01-04 11:23:18 +11:00
|
|
|
dns_masterformat_raw, NULL, NULL);
|
2018-11-14 20:18:19 +08:00
|
|
|
assert_string_equal(isc_result_totext(result), "success");
|
|
|
|
assert_true(headerset);
|
|
|
|
assert_int_equal(header.flags, 0);
|
2011-12-08 16:07:22 +00:00
|
|
|
|
|
|
|
/* 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);
|
2018-11-14 20:18:19 +08:00
|
|
|
assert_string_equal(isc_result_totext(result), "success");
|
|
|
|
assert_true(headerset);
|
|
|
|
assert_int_equal(header.flags, 0);
|
2011-12-08 16:07:22 +00:00
|
|
|
|
|
|
|
/* 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);
|
2018-11-14 20:18:19 +08:00
|
|
|
assert_string_equal(isc_result_totext(result), "success");
|
|
|
|
assert_true(headerset);
|
|
|
|
assert_true((header.flags & DNS_MASTERRAW_SOURCESERIALSET) != 0);
|
|
|
|
assert_int_equal(header.sourceserial, 2011120101);
|
2011-12-08 16:07:22 +00:00
|
|
|
}
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
/*
|
|
|
|
* Raw dump test:
|
|
|
|
* dns_master_dump*() functions dump valid raw files
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
dumpraw_test(void **state) {
|
2011-12-08 16:07:22 +00:00
|
|
|
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;
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
UNUSED(state);
|
2011-12-08 16:07:22 +00:00
|
|
|
|
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);
|
2018-11-14 20:18:19 +08:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2011-12-08 16:07:22 +00:00
|
|
|
|
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);
|
2018-11-14 20:18:19 +08:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2011-12-08 16:07:22 +00:00
|
|
|
|
2018-04-03 13:22:09 +02:00
|
|
|
result = dns_db_load(db, "testdata/master/master1.data",
|
|
|
|
dns_masterformat_text, 0);
|
2018-11-14 20:18:19 +08:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2011-12-08 16:07:22 +00:00
|
|
|
|
|
|
|
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);
|
2018-11-14 20:18:19 +08:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2011-12-08 16:07:22 +00:00
|
|
|
|
2013-01-04 11:23:18 +11:00
|
|
|
result = test_master("test.dump", dns_masterformat_raw, NULL, NULL);
|
2018-11-14 20:18:19 +08:00
|
|
|
assert_string_equal(isc_result_totext(result), "success");
|
|
|
|
assert_true(headerset);
|
|
|
|
assert_int_equal(header.flags, 0);
|
2011-12-08 16:07:22 +00:00
|
|
|
|
|
|
|
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);
|
2018-11-14 20:18:19 +08:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2011-12-08 16:07:22 +00:00
|
|
|
|
2013-01-04 11:23:18 +11:00
|
|
|
result = test_master("test.dump", dns_masterformat_raw, NULL, NULL);
|
2018-11-14 20:18:19 +08:00
|
|
|
assert_string_equal(isc_result_totext(result), "success");
|
|
|
|
assert_true(headerset);
|
|
|
|
assert_true((header.flags & DNS_MASTERRAW_SOURCESERIALSET) != 0);
|
|
|
|
assert_int_equal(header.sourceserial, 12345);
|
2011-12-08 16:07:22 +00:00
|
|
|
|
|
|
|
unlink("test.dump");
|
2018-04-17 08:29:14 -07:00
|
|
|
dns_db_closeversion(db, &version, false);
|
2011-12-08 16:07:22 +00:00
|
|
|
dns_db_detach(&db);
|
|
|
|
}
|
|
|
|
|
2013-01-04 11:23:18 +11:00
|
|
|
static const char *warn_expect_value;
|
2018-04-17 08:29:14 -07:00
|
|
|
static bool warn_expect_result;
|
2013-01-04 11:23:18 +11:00
|
|
|
|
|
|
|
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
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
warn_expect_result = false;
|
|
|
|
|
2013-01-04 11:23:18 +11:00
|
|
|
va_start(ap, fmt);
|
|
|
|
vsnprintf(buf, sizeof(buf), fmt, ap);
|
|
|
|
va_end(ap);
|
2018-11-14 20:18:19 +08:00
|
|
|
|
|
|
|
if (warn_expect_value != NULL &&
|
|
|
|
strstr(buf, warn_expect_value) != NULL)
|
|
|
|
{
|
2018-04-17 08:29:14 -07:00
|
|
|
warn_expect_result = true;
|
2018-11-14 20:18:19 +08:00
|
|
|
}
|
2013-01-04 11:23:18 +11:00
|
|
|
}
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
/*
|
|
|
|
* Origin change test:
|
|
|
|
* dns_master_loadfile() rejects zones with inherited name following $ORIGIN
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
neworigin_test(void **state) {
|
2012-12-18 16:17:55 -08:00
|
|
|
isc_result_t result;
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
UNUSED(state);
|
2012-12-18 16:17:55 -08:00
|
|
|
|
2013-01-04 11:23:18 +11:00
|
|
|
warn_expect_value = "record with inherited owner";
|
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);
|
2018-11-14 20:18:19 +08:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
assert_true(warn_expect_result);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void) {
|
|
|
|
const struct CMUnitTest tests[] = {
|
|
|
|
cmocka_unit_test_setup_teardown(load_test,
|
|
|
|
_setup, _teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(unexpected_test,
|
|
|
|
_setup, _teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(noowner_test,
|
|
|
|
_setup, _teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(nottl_test,
|
|
|
|
_setup, _teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(badclass_test,
|
|
|
|
_setup, _teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(dnskey_test,
|
|
|
|
_setup, _teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(dnsnokey_test,
|
|
|
|
_setup, _teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(include_test,
|
|
|
|
_setup, _teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(master_includelist_test,
|
|
|
|
_setup, _teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(includefail_test,
|
|
|
|
_setup, _teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(blanklines_test,
|
|
|
|
_setup, _teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(leadingzero_test,
|
|
|
|
_setup, _teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(totext_test,
|
|
|
|
_setup, _teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(loadraw_test,
|
|
|
|
_setup, _teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(dumpraw_test,
|
|
|
|
_setup, _teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(toobig_test,
|
|
|
|
_setup, _teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(maxrdata_test,
|
|
|
|
_setup, _teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(neworigin_test,
|
|
|
|
_setup, _teardown),
|
|
|
|
};
|
|
|
|
|
|
|
|
return (cmocka_run_group_tests(tests, NULL, NULL));
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* HAVE_CMOCKA */
|
2012-12-18 16:17:55 -08:00
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
#include <stdio.h>
|
2012-12-18 16:17:55 -08:00
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
int
|
|
|
|
main(void) {
|
|
|
|
printf("1..0 # Skipped: cmocka not available\n");
|
|
|
|
return (0);
|
2011-02-26 02:26:33 +00:00
|
|
|
}
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
#endif
|