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
|
|
|
*/
|
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
#if HAVE_CMOCKA
|
|
|
|
|
Include <sched.h> where necessary for musl libc
All unit tests define the UNIT_TESTING macro, which causes <cmocka.h> to
replace malloc(), calloc(), realloc(), and free() with its own functions
tracking memory allocations. In order for this not to break
compilation, the system header declaring the prototypes for these
standard functions must be included before <cmocka.h>.
Normally, these prototypes are only present in <stdlib.h>, so we make
sure it is included before <cmocka.h>. However, musl libc also defines
the prototypes for calloc() and free() in <sched.h>, which is included
by <pthread.h>, which is included e.g. by <isc/mutex.h>. Thus, unit
tests including "dnstest.h" (which includes <isc/mem.h>, which includes
<isc/mutex.h>) after <cmocka.h> will not compile with musl libc as for
these programs, <sched.h> will be included after <cmocka.h>.
Always including <cmocka.h> after all other header files is not a
feasible solution as that causes the mock assertion macros defined in
<isc/util.h> to mangle the contents of <cmocka.h>, thus breaking
compilation. We cannot really use the __noreturn__ or analyzer_noreturn
attributes with cmocka assertion functions because they do return if the
tested condition is true. The problem is that what BIND unit tests do
is incompatible with Clang Static Analyzer's assumptions: since we use
cmocka, our custom assertion handlers are present in a shared library
(i.e. it is the cmocka library that checks the assertion condition, not
a macro in unit test code). Redefining cmocka's assertion macros in
<isc/util.h> is an ugly hack to overcome that problem - unfortunately,
this is the only way we can think of to make Clang Static Analyzer
properly process unit test code. Giving up on Clang Static Analyzer
being able to properly process unit test code is not a satisfactory
solution.
Undefining _GNU_SOURCE for unit test code could work around the problem
(musl libc's <sched.h> only defines the prototypes for calloc() and
free() when _GNU_SOURCE is defined), but doing that could introduce
discrepancies for unit tests including entire *.c files, so it is also
not a good solution.
All in all, including <sched.h> before <cmocka.h> for all affected unit
tests seems to be the most benign way of working around this musl libc
quirk. While quite an ugly solution, it achieves our goals here, which
are to keep the benefit of proper static analysis of unit test code and
to fix compilation against musl libc.
2019-07-30 21:08:40 +02:00
|
|
|
#include <sched.h> /* IWYU pragma: keep */
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <setjmp.h>
|
|
|
|
#include <stdarg.h>
|
2018-04-17 08:29:14 -07:00
|
|
|
#include <stdbool.h>
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <stddef.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>
|
|
|
|
|
2013-01-03 18:22:52 -08:00
|
|
|
#include <isc/print.h>
|
2017-09-13 23:43:43 +10:00
|
|
|
#include <isc/string.h>
|
2019-07-30 21:08:40 +02:00
|
|
|
#include <isc/util.h>
|
2012-05-14 10:06:05 -07:00
|
|
|
|
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
|
2020-02-12 13:59:18 +01:00
|
|
|
_setup(void **state)
|
|
|
|
{
|
2018-11-14 20:18:19 +08:00
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
UNUSED(state);
|
|
|
|
|
|
|
|
result = dns_test_begin(NULL, false);
|
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2020-02-12 13:59:18 +01:00
|
|
|
_teardown(void **state)
|
|
|
|
{
|
2018-11-14 20:18:19 +08:00
|
|
|
UNUSED(state);
|
|
|
|
|
|
|
|
dns_test_end();
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
2011-02-26 02:26:33 +00:00
|
|
|
|
2018-11-16 08:19:06 +00:00
|
|
|
static void
|
2020-02-12 13:59:18 +01:00
|
|
|
nullmsg(dns_rdatacallbacks_t *cb, const char *fmt, ...)
|
|
|
|
{
|
2018-11-16 08:19:06 +00:00
|
|
|
UNUSED(cb);
|
|
|
|
UNUSED(fmt);
|
|
|
|
}
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
#define BUFLEN 255
|
|
|
|
#define BIGBUFLEN (70 * 1024)
|
|
|
|
#define TEST_ORIGIN "test"
|
2011-02-26 02:26:33 +00:00
|
|
|
|
2011-12-08 16:07:22 +00:00
|
|
|
static dns_masterrawheader_t header;
|
2020-02-12 13:59:18 +01:00
|
|
|
static bool headerset;
|
2011-12-08 16:07:22 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_name_t dns_origin;
|
|
|
|
char origin[sizeof(TEST_ORIGIN)];
|
|
|
|
unsigned char name_buf[BUFLEN];
|
2012-01-31 03:35:41 +00:00
|
|
|
dns_rdatacallbacks_t callbacks;
|
2020-02-12 13:59:18 +01:00
|
|
|
char * include_file = NULL;
|
2012-01-31 03:35:41 +00:00
|
|
|
|
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
|
2020-02-12 13:59:18 +01:00
|
|
|
add_callback(void *arg, const dns_name_t *owner, dns_rdataset_t *dataset)
|
|
|
|
{
|
|
|
|
char buf[BIGBUFLEN];
|
2011-02-26 02:26:33 +00:00
|
|
|
isc_buffer_t target;
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
UNUSED(arg);
|
|
|
|
|
|
|
|
isc_buffer_init(&target, buf, BIGBUFLEN);
|
2020-02-12 13:59:18 +01:00
|
|
|
result = dns_rdataset_totext(dataset, owner, false, false, &target);
|
|
|
|
return (result);
|
2011-02-26 02:26:33 +00:00
|
|
|
}
|
|
|
|
|
2011-12-08 16:07:22 +00:00
|
|
|
static void
|
2020-02-12 13:59:18 +01:00
|
|
|
rawdata_callback(dns_zone_t *zone, dns_masterrawheader_t *h)
|
|
|
|
{
|
2011-12-08 16:07:22 +00:00
|
|
|
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
|
|
|
{
|
2020-02-12 13:59:18 +01:00
|
|
|
isc_result_t result;
|
|
|
|
int len;
|
|
|
|
isc_buffer_t source;
|
|
|
|
isc_buffer_t target;
|
2011-02-26 02:26:33 +00:00
|
|
|
|
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
|
|
|
|
2020-02-12 13:59:18 +01: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) {
|
2020-02-12 13:59:18 +01: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 *, ...))
|
|
|
|
{
|
2020-02-12 13:59:18 +01:00
|
|
|
isc_result_t result;
|
2013-01-04 11:23:18 +11:00
|
|
|
|
|
|
|
result = setup_master(warn, error);
|
2018-11-14 20:18:19 +08:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2020-02-12 13:59:18 +01:00
|
|
|
return (result);
|
2018-11-14 20:18:19 +08:00
|
|
|
}
|
2013-01-04 11:23:18 +11:00
|
|
|
|
2018-11-16 08:19:06 +00:00
|
|
|
dns_rdatacallbacks_init_stdio(&callbacks);
|
|
|
|
callbacks.add = add_callback;
|
|
|
|
callbacks.rawdata = rawdata_callback;
|
|
|
|
callbacks.zone = NULL;
|
|
|
|
if (warn != NULL) {
|
|
|
|
callbacks.warn = warn;
|
|
|
|
}
|
|
|
|
if (error != NULL) {
|
|
|
|
callbacks.error = error;
|
|
|
|
}
|
|
|
|
|
2018-04-03 13:09:55 +02:00
|
|
|
result = dns_master_loadfile(testfile, &dns_origin, &dns_origin,
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_rdataclass_in, true, 0, &callbacks,
|
|
|
|
NULL, NULL, dt_mctx, format, 0);
|
2011-02-26 02:26:33 +00:00
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
2012-01-31 03:35:41 +00:00
|
|
|
static void
|
2020-02-12 13:59:18 +01:00
|
|
|
include_callback(const char *filename, void *arg)
|
|
|
|
{
|
|
|
|
char **argp = (char **)arg;
|
2019-06-18 15:01:43 +02:00
|
|
|
*argp = isc_mem_strdup(dt_mctx, filename);
|
2012-01-31 03:35:41 +00:00
|
|
|
}
|
|
|
|
|
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
|
2020-02-12 13:59:18 +01:00
|
|
|
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",
|
2018-11-16 08:19:06 +00:00
|
|
|
dns_masterformat_text, nullmsg, nullmsg);
|
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
|
2020-02-12 13:59:18 +01:00
|
|
|
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",
|
2018-11-16 08:19:06 +00:00
|
|
|
dns_masterformat_text, nullmsg, nullmsg);
|
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
|
2020-02-12 13:59:18 +01:00
|
|
|
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",
|
2018-11-16 08:19:06 +00:00
|
|
|
dns_masterformat_text, nullmsg, nullmsg);
|
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
|
2020-02-12 13:59:18 +01:00
|
|
|
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",
|
2018-11-16 08:19:06 +00:00
|
|
|
dns_masterformat_text, nullmsg, nullmsg);
|
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
|
2020-02-12 13:59:18 +01:00
|
|
|
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",
|
2018-11-16 08:19:06 +00:00
|
|
|
dns_masterformat_text, nullmsg, nullmsg);
|
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
|
2020-02-12 13:59:18 +01:00
|
|
|
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",
|
2018-11-16 08:19:06 +00:00
|
|
|
dns_masterformat_text, nullmsg, nullmsg);
|
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
|
2020-02-12 13:59:18 +01:00
|
|
|
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",
|
2018-11-16 08:19:06 +00:00
|
|
|
dns_masterformat_text, nullmsg, nullmsg);
|
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
|
2020-02-12 13:59:18 +01:00
|
|
|
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",
|
2018-11-16 08:19:06 +00:00
|
|
|
dns_masterformat_text, nullmsg, nullmsg);
|
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
|
2019-02-27 10:35:53 +11:00
|
|
|
*
|
|
|
|
* RFC 4034 removed the ability to signal NOKEY, so empty key material should
|
|
|
|
* be rejected.
|
2018-11-14 20:18:19 +08:00
|
|
|
*/
|
|
|
|
static void
|
2020-02-12 13:59:18 +01:00
|
|
|
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",
|
2018-11-16 08:19:06 +00:00
|
|
|
dns_masterformat_text, nullmsg, nullmsg);
|
2019-02-27 10:35:53 +11:00
|
|
|
assert_int_equal(result, ISC_R_UNEXPECTEDEND);
|
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
|
2020-02-12 13:59:18 +01:00
|
|
|
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",
|
2018-11-16 08:19:06 +00:00
|
|
|
dns_masterformat_text, nullmsg, nullmsg);
|
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
|
2020-02-12 13:59:18 +01:00
|
|
|
master_includelist_test(void **state)
|
|
|
|
{
|
2012-01-31 03:35:41 +00:00
|
|
|
isc_result_t result;
|
2020-02-12 13:59:18 +01:00
|
|
|
char * filename = NULL;
|
2012-01-31 03:35:41 +00:00
|
|
|
|
2018-11-14 20:18:19 +08:00
|
|
|
UNUSED(state);
|
2012-01-31 03:35:41 +00:00
|
|
|
|
2018-11-16 08:19:06 +00:00
|
|
|
result = setup_master(nullmsg, nullmsg);
|
2018-11-14 20:18:19 +08:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2013-01-04 11:23:18 +11:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
result = dns_master_loadfile(
|
|
|
|
"testdata/master/master8.data", &dns_origin, &dns_origin,
|
|
|
|
dns_rdataclass_in, 0, true, &callbacks, include_callback,
|
|
|
|
&filename, dt_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) {
|
2019-02-27 10:35:53 +11:00
|
|
|
assert_string_equal(filename, "testdata/master/master6.data");
|
2019-06-18 15:01:43 +02:00
|
|
|
isc_mem_free(dt_mctx, filename);
|
2012-01-31 03:35:41 +00:00
|
|
|
}
|
|
|
|
}
|
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
|
2020-02-12 13:59:18 +01:00
|
|
|
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",
|
2018-11-16 08:19:06 +00:00
|
|
|
dns_masterformat_text, nullmsg, nullmsg);
|
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
|
2020-02-12 13:59:18 +01:00
|
|
|
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",
|
2018-11-16 08:19:06 +00:00
|
|
|
dns_masterformat_text, nullmsg, nullmsg);
|
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
|
2020-02-12 13:59:18 +01:00
|
|
|
leadingzero_test(void **state)
|
|
|
|
{
|
2018-11-14 20:18:19 +08:00
|
|
|
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",
|
2018-11-16 08:19:06 +00:00
|
|
|
dns_masterformat_text, nullmsg, nullmsg);
|
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
|
2020-02-12 13:59:18 +01:00
|
|
|
totext_test(void **state)
|
|
|
|
{
|
|
|
|
isc_result_t result;
|
|
|
|
dns_rdataset_t rdataset;
|
2011-09-07 19:11:14 +00:00
|
|
|
dns_rdatalist_t rdatalist;
|
2020-02-12 13:59:18 +01:00
|
|
|
isc_buffer_t target;
|
|
|
|
unsigned char buf[BIGBUFLEN];
|
2011-09-07 19:11:14 +00:00
|
|
|
|
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);
|
2019-11-18 20:46:58 +11:00
|
|
|
result = dns_master_rdatasettotext(dns_rootname, &rdataset,
|
|
|
|
&dns_master_style_debug, NULL,
|
2011-09-07 19:11:14 +00:00
|
|
|
&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
|
2020-02-12 13:59:18 +01:00
|
|
|
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",
|
2018-11-16 08:19:06 +00:00
|
|
|
dns_masterformat_raw, nullmsg, nullmsg);
|
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",
|
2018-11-16 08:19:06 +00:00
|
|
|
dns_masterformat_raw, nullmsg, nullmsg);
|
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",
|
2018-11-16 08:19:06 +00:00
|
|
|
dns_masterformat_raw, nullmsg, nullmsg);
|
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
|
2020-02-12 13:59:18 +01:00
|
|
|
dumpraw_test(void **state)
|
|
|
|
{
|
|
|
|
isc_result_t result;
|
|
|
|
dns_db_t * db = NULL;
|
2011-12-08 16:07:22 +00:00
|
|
|
dns_dbversion_t *version = NULL;
|
2020-02-12 13:59:18 +01:00
|
|
|
char myorigin[sizeof(TEST_ORIGIN)];
|
|
|
|
dns_name_t dnsorigin;
|
|
|
|
isc_buffer_t source, target;
|
|
|
|
unsigned char namebuf[BUFLEN];
|
|
|
|
int len;
|
2011-12-08 16:07:22 +00:00
|
|
|
|
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);
|
2020-02-12 13:59:18 +01:00
|
|
|
result = dns_name_fromtext(&dnsorigin, &source, dns_rootname, 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
|
|
|
|
2019-06-18 15:01:43 +02:00
|
|
|
result = dns_db_create(dt_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);
|
|
|
|
|
2019-06-18 15:01:43 +02:00
|
|
|
result = dns_master_dump(dt_mctx, db, version,
|
2018-04-03 13:09:55 +02:00
|
|
|
&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
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
result = test_master("test.dump", dns_masterformat_raw, nullmsg,
|
|
|
|
nullmsg);
|
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");
|
2019-06-18 15:01:43 +02:00
|
|
|
result = dns_master_dump(dt_mctx, db, version,
|
2018-04-03 13:09:55 +02:00
|
|
|
&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
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
result = test_master("test.dump", dns_masterformat_raw, nullmsg,
|
|
|
|
nullmsg);
|
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;
|
2020-02-12 13:59:18 +01:00
|
|
|
static bool warn_expect_result;
|
2013-01-04 11:23:18 +11:00
|
|
|
|
|
|
|
static void
|
2020-02-12 13:59:18 +01:00
|
|
|
warn_expect(struct dns_rdatacallbacks *mycallbacks, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
char buf[4096];
|
2013-01-04 11:23:18 +11:00
|
|
|
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 &&
|
2020-02-12 13:59:18 +01:00
|
|
|
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
|
2020-02-12 13:59:18 +01:00
|
|
|
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",
|
2018-11-16 08:19:06 +00:00
|
|
|
dns_masterformat_text, warn_expect, nullmsg);
|
2018-11-14 20:18:19 +08:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
assert_true(warn_expect_result);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-02-12 13:59:18 +01:00
|
|
|
main(void)
|
|
|
|
{
|
2018-11-14 20:18:19 +08:00
|
|
|
const struct CMUnitTest tests[] = {
|
2020-02-12 13:59:18 +01:00
|
|
|
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),
|
2018-11-14 20:18:19 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
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
|
2020-02-12 13:59:18 +01:00
|
|
|
main(void)
|
|
|
|
{
|
2018-11-14 20:18:19 +08:00
|
|
|
printf("1..0 # Skipped: cmocka not available\n");
|
|
|
|
return (0);
|
2011-02-26 02:26:33 +00:00
|
|
|
}
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* if HAVE_CMOCKA */
|