2011-10-12 23:09:35 +00:00
|
|
|
/*
|
2018-02-23 09:53:12 +01:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2011-10-12 23:09:35 +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-10-12 23:09:35 +00:00
|
|
|
*/
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
#if HAVE_CMOCKA
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <setjmp.h>
|
2011-10-12 23:09:35 +00:00
|
|
|
|
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 */
|
2011-10-13 07:56:32 +00:00
|
|
|
#include <stdlib.h>
|
2018-11-09 10:23:49 -08:00
|
|
|
#include <string.h>
|
2011-10-13 07:56:32 +00:00
|
|
|
#include <unistd.h>
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
#define UNIT_TESTING
|
|
|
|
#include <cmocka.h>
|
2018-03-28 14:19:37 +02:00
|
|
|
|
2011-10-12 23:09:35 +00:00
|
|
|
#include <isc/file.h>
|
|
|
|
#include <isc/result.h>
|
|
|
|
#include <isc/serial.h>
|
|
|
|
#include <isc/stdtime.h>
|
2018-11-09 10:23:49 -08:00
|
|
|
#include <isc/string.h>
|
|
|
|
#include <isc/util.h>
|
2011-10-12 23:09:35 +00:00
|
|
|
|
|
|
|
#include <dns/db.h>
|
|
|
|
#include <dns/rdatalist.h>
|
|
|
|
#include <dns/rdataset.h>
|
|
|
|
#include <dns/rdatasetiter.h>
|
|
|
|
#include <dns/nsec3.h>
|
|
|
|
|
|
|
|
#include "dnstest.h"
|
|
|
|
|
|
|
|
static char tempname[11] = "dtXXXXXXXX";
|
2018-11-09 10:23:49 -08:00
|
|
|
static dns_db_t *db1 = NULL, *db2 = NULL;
|
|
|
|
static dns_dbversion_t *v1 = NULL, *v2 = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The code below enables us to trap assertion failures for testing
|
|
|
|
* purposes. local_callback() is set as the callback function for
|
|
|
|
* isc_assertion_failed(). It calls mock_assert() so that CMOCKA
|
|
|
|
* will be able to see it, then returns to the calling functon via
|
|
|
|
* longjmp() so that the abort() call in isc_assertion_failed() will
|
|
|
|
* never be reached. Use check_assertion() to check for assertions
|
|
|
|
* instead of expect_assert_failure().
|
|
|
|
*/
|
|
|
|
jmp_buf assertion;
|
|
|
|
|
|
|
|
#define check_assertion(function_call) \
|
|
|
|
do { \
|
|
|
|
const int r = setjmp(assertion); \
|
|
|
|
if (r == 0) { \
|
|
|
|
expect_assert_failure(function_call); \
|
|
|
|
} \
|
|
|
|
} while(false);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
|
|
|
static void
|
2015-01-20 13:29:18 -08:00
|
|
|
local_callback(const char *file, int line, isc_assertiontype_t type,
|
|
|
|
const char *cond)
|
2011-10-12 23:09:35 +00:00
|
|
|
{
|
2018-11-09 10:23:49 -08:00
|
|
|
UNUSED(type);
|
|
|
|
|
|
|
|
mock_assert(1, cond, file, line);
|
|
|
|
longjmp(assertion, 1);
|
2011-10-12 23:09:35 +00:00
|
|
|
}
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
static int
|
|
|
|
_setup(void **state) {
|
|
|
|
isc_result_t res;
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
UNUSED(state);
|
|
|
|
|
|
|
|
isc_assertion_setcallback(local_callback);
|
|
|
|
|
|
|
|
res = dns_test_begin(NULL, false);
|
|
|
|
assert_int_equal(res, ISC_R_SUCCESS);
|
|
|
|
|
2019-06-18 15:01:43 +02:00
|
|
|
res = dns_db_create(dt_mctx, "rbt", dns_rootname, dns_dbtype_zone,
|
2011-10-13 22:48:24 +00:00
|
|
|
dns_rdataclass_in, 0, NULL, &db1);
|
2018-11-09 10:23:49 -08:00
|
|
|
assert_int_equal(res, ISC_R_SUCCESS);
|
2011-10-12 23:09:35 +00:00
|
|
|
dns_db_newversion(db1, &v1);
|
2018-11-09 10:23:49 -08:00
|
|
|
assert_non_null(v1);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2019-06-18 15:01:43 +02:00
|
|
|
res = dns_db_create(dt_mctx, "rbt", dns_rootname, dns_dbtype_zone,
|
2011-10-13 22:48:24 +00:00
|
|
|
dns_rdataclass_in, 0, NULL, &db2);
|
2018-11-09 10:23:49 -08:00
|
|
|
assert_int_equal(res, ISC_R_SUCCESS);
|
2011-10-12 23:09:35 +00:00
|
|
|
dns_db_newversion(db2, &v2);
|
2018-11-09 10:23:49 -08:00
|
|
|
assert_non_null(v1);
|
|
|
|
|
|
|
|
return (0);
|
2011-10-12 23:09:35 +00:00
|
|
|
}
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
static int
|
|
|
|
_teardown(void **state) {
|
|
|
|
UNUSED(state);
|
|
|
|
|
|
|
|
if (strcmp(tempname, "dtXXXXXXXX") != 0) {
|
|
|
|
unlink(tempname);
|
|
|
|
}
|
|
|
|
|
2011-10-12 23:09:35 +00:00
|
|
|
if (v1 != NULL) {
|
2018-04-17 08:29:14 -07:00
|
|
|
dns_db_closeversion(db1, &v1, false);
|
2018-11-09 10:23:49 -08:00
|
|
|
assert_null(v1);
|
2011-10-12 23:09:35 +00:00
|
|
|
}
|
|
|
|
if (db1 != NULL) {
|
|
|
|
dns_db_detach(&db1);
|
2018-11-09 10:23:49 -08:00
|
|
|
assert_null(db1);
|
2011-10-12 23:09:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (v2 != NULL) {
|
2018-04-17 08:29:14 -07:00
|
|
|
dns_db_closeversion(db2, &v2, false);
|
2018-11-09 10:23:49 -08:00
|
|
|
assert_null(v2);
|
2011-10-12 23:09:35 +00:00
|
|
|
}
|
|
|
|
if (db2 != NULL) {
|
|
|
|
dns_db_detach(&db2);
|
2018-11-09 10:23:49 -08:00
|
|
|
assert_null(db2);
|
2011-10-12 23:09:35 +00:00
|
|
|
}
|
2018-11-09 10:23:49 -08:00
|
|
|
|
|
|
|
dns_test_end();
|
|
|
|
|
|
|
|
return (0);
|
2011-10-12 23:09:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2018-11-09 10:23:49 -08:00
|
|
|
* Check dns_db_attachversion() passes with matching db and version, and
|
|
|
|
* asserts with mis-matching db and version.
|
2011-10-12 23:09:35 +00:00
|
|
|
*/
|
|
|
|
static void
|
2018-11-09 10:23:49 -08:00
|
|
|
attachversion(void **state) {
|
2011-10-12 23:09:35 +00:00
|
|
|
dns_dbversion_t *v = NULL;
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
UNUSED(state);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
dns_db_attachversion(db1, v1, &v);
|
|
|
|
assert_ptr_equal(v, v1);
|
2018-04-17 08:29:14 -07:00
|
|
|
dns_db_closeversion(db1, &v, false);
|
2018-11-09 10:23:49 -08:00
|
|
|
assert_null(v);
|
2011-10-13 22:48:24 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
check_assertion(dns_db_attachversion(db1, v2, &v));
|
2011-10-12 23:09:35 +00:00
|
|
|
}
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
/*
|
|
|
|
* Check dns_db_closeversion() passes with matching db and version, and
|
|
|
|
* asserts with mis-matching db and version.
|
|
|
|
*/
|
2011-10-12 23:09:35 +00:00
|
|
|
static void
|
2018-11-09 10:23:49 -08:00
|
|
|
closeversion(void **state) {
|
|
|
|
UNUSED(state);
|
2011-10-13 22:48:24 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
assert_non_null(v1);
|
|
|
|
dns_db_closeversion(db1, &v1, false);
|
|
|
|
assert_null(v1);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
check_assertion(dns_db_closeversion(db1, &v2, false));
|
2011-10-12 23:09:35 +00:00
|
|
|
}
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
/*
|
|
|
|
* Check dns_db_find() passes with matching db and version, and
|
|
|
|
* asserts with mis-matching db and version.
|
|
|
|
*/
|
2011-10-12 23:09:35 +00:00
|
|
|
static void
|
2018-11-09 10:23:49 -08:00
|
|
|
find(void **state) {
|
|
|
|
isc_result_t res;
|
2011-10-12 23:09:35 +00:00
|
|
|
dns_rdataset_t rdataset;
|
|
|
|
dns_fixedname_t fixed;
|
2018-11-09 10:23:49 -08:00
|
|
|
dns_name_t *name = NULL;
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
UNUSED(state);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
name = dns_fixedname_initname(&fixed);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
|
|
|
dns_rdataset_init(&rdataset);
|
2018-11-09 10:23:49 -08:00
|
|
|
res = dns_db_find(db1, dns_rootname, v1, dns_rdatatype_soa,
|
|
|
|
0, 0, NULL, name, &rdataset, NULL);
|
|
|
|
assert_int_equal(res, DNS_R_NXDOMAIN);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
if (dns_rdataset_isassociated(&rdataset)) {
|
|
|
|
dns_rdataset_disassociate(&rdataset);
|
2018-10-24 20:00:46 +02:00
|
|
|
}
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
dns_rdataset_init(&rdataset);
|
|
|
|
check_assertion(dns_db_find(db1, dns_rootname, v2,
|
|
|
|
dns_rdatatype_soa, 0, 0, NULL,
|
|
|
|
name, &rdataset, NULL));
|
2011-10-12 23:09:35 +00:00
|
|
|
}
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
/*
|
|
|
|
* Check dns_db_allrdatasets() passes with matching db and version, and
|
|
|
|
* asserts with mis-matching db and version.
|
|
|
|
*/
|
2011-10-12 23:09:35 +00:00
|
|
|
static void
|
2018-11-09 10:23:49 -08:00
|
|
|
allrdatasets(void **state) {
|
|
|
|
isc_result_t res;
|
2011-10-12 23:09:35 +00:00
|
|
|
dns_dbnode_t *node = NULL;
|
|
|
|
dns_rdatasetiter_t *iterator = NULL;
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
UNUSED(state);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
res = dns_db_findnode(db1, dns_rootname, false, &node);
|
|
|
|
assert_int_equal(res, ISC_R_SUCCESS);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
res = dns_db_allrdatasets(db1, node, v1, 0, &iterator);
|
|
|
|
assert_int_equal(res, ISC_R_SUCCESS);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
check_assertion(dns_db_allrdatasets(db1, node, v2, 0, &iterator));
|
2011-10-12 23:09:35 +00:00
|
|
|
|
|
|
|
dns_rdatasetiter_destroy(&iterator);
|
2018-11-09 10:23:49 -08:00
|
|
|
assert_null(iterator);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
|
|
|
dns_db_detachnode(db1, &node);
|
2018-11-09 10:23:49 -08:00
|
|
|
assert_null(node);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
/*
|
|
|
|
* Check dns_db_findrdataset() passes with matching db and version, and
|
|
|
|
* asserts with mis-matching db and version.
|
|
|
|
*/
|
2011-10-12 23:09:35 +00:00
|
|
|
static void
|
2018-11-09 10:23:49 -08:00
|
|
|
findrdataset(void **state) {
|
|
|
|
isc_result_t res;
|
2011-10-12 23:09:35 +00:00
|
|
|
dns_rdataset_t rdataset;
|
|
|
|
dns_dbnode_t *node = NULL;
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
UNUSED(state);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
res = dns_db_findnode(db1, dns_rootname, false, &node);
|
|
|
|
assert_int_equal(res, ISC_R_SUCCESS);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
|
|
|
dns_rdataset_init(&rdataset);
|
2018-11-09 10:23:49 -08:00
|
|
|
res = dns_db_findrdataset(db1, node, v1, dns_rdatatype_soa,
|
|
|
|
0, 0, &rdataset, NULL);
|
|
|
|
assert_int_equal(res, ISC_R_NOTFOUND);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
if (dns_rdataset_isassociated(&rdataset)) {
|
|
|
|
dns_rdataset_disassociate(&rdataset);
|
2018-10-24 20:00:46 +02:00
|
|
|
}
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
dns_rdataset_init(&rdataset);
|
|
|
|
check_assertion(dns_db_findrdataset(db1, node, v2,
|
|
|
|
dns_rdatatype_soa, 0, 0,
|
|
|
|
&rdataset, NULL));
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
dns_db_detachnode(db1, &node);
|
|
|
|
assert_null(node);
|
2011-10-12 23:09:35 +00:00
|
|
|
}
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
/*
|
|
|
|
* Check dns_db_deleterdataset() passes with matching db and version, and
|
|
|
|
* asserts with mis-matching db and version.
|
|
|
|
*/
|
2011-10-12 23:09:35 +00:00
|
|
|
static void
|
2018-11-09 10:23:49 -08:00
|
|
|
deleterdataset(void **state) {
|
|
|
|
isc_result_t res;
|
2011-10-12 23:09:35 +00:00
|
|
|
dns_dbnode_t *node = NULL;
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
UNUSED(state);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
res = dns_db_findnode(db1, dns_rootname, false, &node);
|
|
|
|
assert_int_equal(res, ISC_R_SUCCESS);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
res = dns_db_deleterdataset(db1, node, v1, dns_rdatatype_soa, 0);
|
|
|
|
assert_int_equal(res, DNS_R_UNCHANGED);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
check_assertion(dns_db_deleterdataset(db1, node, v2,
|
|
|
|
dns_rdatatype_soa, 0));
|
2011-10-12 23:09:35 +00:00
|
|
|
dns_db_detachnode(db1, &node);
|
2018-11-09 10:23:49 -08:00
|
|
|
assert_null(node);
|
2011-10-12 23:09:35 +00:00
|
|
|
}
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
/*
|
|
|
|
* Check dns_db_subtractrdataset() passes with matching db and version, and
|
|
|
|
* asserts with mis-matching db and version.
|
|
|
|
*/
|
2011-10-12 23:09:35 +00:00
|
|
|
static void
|
2018-11-09 10:23:49 -08:00
|
|
|
subtract(void **state) {
|
|
|
|
isc_result_t res;
|
2011-10-12 23:09:35 +00:00
|
|
|
dns_rdataset_t rdataset;
|
|
|
|
dns_rdatalist_t rdatalist;
|
2018-11-09 10:23:49 -08:00
|
|
|
dns_dbnode_t *node = NULL;
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
UNUSED(state);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
|
|
|
dns_rdataset_init(&rdataset);
|
|
|
|
dns_rdatalist_init(&rdatalist);
|
|
|
|
|
|
|
|
rdatalist.rdclass = dns_rdataclass_in;
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
res = dns_rdatalist_tordataset(&rdatalist, &rdataset);
|
|
|
|
assert_int_equal(res, ISC_R_SUCCESS);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
res = dns_db_findnode(db1, dns_rootname, false, &node);
|
|
|
|
assert_int_equal(res, ISC_R_SUCCESS);
|
2011-10-13 22:48:24 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
res = dns_db_subtractrdataset(db1, node, v1, &rdataset, 0, NULL);
|
|
|
|
assert_int_equal(res, DNS_R_UNCHANGED);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
if (dns_rdataset_isassociated(&rdataset)) {
|
|
|
|
dns_rdataset_disassociate(&rdataset);
|
|
|
|
}
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
dns_rdataset_init(&rdataset);
|
|
|
|
res = dns_rdatalist_tordataset(&rdatalist, &rdataset);
|
|
|
|
assert_int_equal(res, ISC_R_SUCCESS);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
check_assertion(dns_db_subtractrdataset(db1, node, v2,
|
|
|
|
&rdataset, 0, NULL));
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
dns_db_detachnode(db1, &node);
|
|
|
|
assert_null(node);
|
2011-10-12 23:09:35 +00:00
|
|
|
}
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
/*
|
|
|
|
* Check dns_db_dump() passes with matching db and version, and
|
|
|
|
* asserts with mis-matching db and version.
|
|
|
|
*/
|
2011-10-12 23:09:35 +00:00
|
|
|
static void
|
2018-11-09 10:23:49 -08:00
|
|
|
dump(void **state) {
|
|
|
|
isc_result_t res;
|
2011-10-12 23:09:35 +00:00
|
|
|
FILE *f = NULL;
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
UNUSED(state);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
res = isc_file_openunique(tempname, &f);
|
2011-10-12 23:09:35 +00:00
|
|
|
fclose(f);
|
2018-11-09 10:23:49 -08:00
|
|
|
assert_int_equal(res, ISC_R_SUCCESS);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
res = dns_db_dump(db1, v1, tempname);
|
|
|
|
assert_int_equal(res, ISC_R_SUCCESS);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
check_assertion(dns_db_dump(db1, v2, tempname));
|
2011-10-12 23:09:35 +00:00
|
|
|
}
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
/*
|
|
|
|
* Check dns_db_addrdataset() passes with matching db and version, and
|
|
|
|
* asserts with mis-matching db and version.
|
|
|
|
*/
|
2011-10-12 23:09:35 +00:00
|
|
|
static void
|
2018-11-09 10:23:49 -08:00
|
|
|
addrdataset(void **state) {
|
|
|
|
isc_result_t res;
|
2011-10-12 23:09:35 +00:00
|
|
|
dns_rdataset_t rdataset;
|
|
|
|
dns_dbnode_t *node = NULL;
|
|
|
|
dns_rdatalist_t rdatalist;
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
UNUSED(state);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
|
|
|
dns_rdataset_init(&rdataset);
|
|
|
|
dns_rdatalist_init(&rdatalist);
|
|
|
|
|
|
|
|
rdatalist.rdclass = dns_rdataclass_in;
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
res = dns_rdatalist_tordataset(&rdatalist, &rdataset);
|
|
|
|
assert_int_equal(res, ISC_R_SUCCESS);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
res = dns_db_findnode(db1, dns_rootname, false, &node);
|
|
|
|
assert_int_equal(res, ISC_R_SUCCESS);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
res = dns_db_addrdataset(db1, node, v1, 0, &rdataset, 0, NULL);
|
|
|
|
assert_int_equal(res, ISC_R_SUCCESS);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
check_assertion(dns_db_addrdataset(db1, node, v2,
|
|
|
|
0, &rdataset, 0, NULL));
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
dns_db_detachnode(db1, &node);
|
|
|
|
assert_null(node);
|
2011-10-12 23:09:35 +00:00
|
|
|
}
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
/*
|
|
|
|
* Check dns_db_getnsec3parameters() passes with matching db and version,
|
|
|
|
* and asserts with mis-matching db and version.
|
|
|
|
*/
|
2011-10-12 23:09:35 +00:00
|
|
|
static void
|
2018-11-09 10:23:49 -08:00
|
|
|
getnsec3parameters(void **state) {
|
|
|
|
isc_result_t res;
|
2011-10-12 23:09:35 +00:00
|
|
|
dns_hash_t hash;
|
2018-03-28 14:19:37 +02:00
|
|
|
uint8_t flags;
|
|
|
|
uint16_t iterations;
|
2011-10-12 23:09:35 +00:00
|
|
|
unsigned char salt[DNS_NSEC3_SALTSIZE];
|
|
|
|
size_t salt_length = sizeof(salt);
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
UNUSED(state);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
res = dns_db_getnsec3parameters(db1, v1, &hash,
|
|
|
|
&flags, &iterations, salt,
|
2011-10-12 23:09:35 +00:00
|
|
|
&salt_length);
|
2018-11-09 10:23:49 -08:00
|
|
|
assert_int_equal(res, ISC_R_NOTFOUND);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
check_assertion(dns_db_getnsec3parameters(db1, v2, &hash,
|
|
|
|
&flags, &iterations,
|
|
|
|
salt, &salt_length));
|
2011-10-12 23:09:35 +00:00
|
|
|
}
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
/*
|
|
|
|
* Check dns_db_resigned() passes with matching db and version, and
|
|
|
|
* asserts with mis-matching db and version.
|
|
|
|
*/
|
2011-10-12 23:09:35 +00:00
|
|
|
static void
|
2018-11-09 10:23:49 -08:00
|
|
|
resigned(void **state) {
|
|
|
|
isc_result_t res;
|
2011-10-12 23:09:35 +00:00
|
|
|
dns_rdataset_t rdataset, added;
|
|
|
|
dns_dbnode_t *node = NULL;
|
|
|
|
dns_rdatalist_t rdatalist;
|
|
|
|
dns_rdata_rrsig_t rrsig;
|
|
|
|
dns_rdata_t rdata = DNS_RDATA_INIT;
|
|
|
|
isc_buffer_t b;
|
|
|
|
unsigned char buf[1024];
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
UNUSED(state);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a dummy RRSIG record and set a resigning time.
|
|
|
|
*/
|
|
|
|
dns_rdataset_init(&added);
|
|
|
|
dns_rdataset_init(&rdataset);
|
|
|
|
dns_rdatalist_init(&rdatalist);
|
|
|
|
isc_buffer_init(&b, buf, sizeof(buf));
|
|
|
|
|
|
|
|
DNS_RDATACOMMON_INIT(&rrsig, dns_rdatatype_rrsig, dns_rdataclass_in);
|
|
|
|
rrsig.covered = dns_rdatatype_a;
|
|
|
|
rrsig.algorithm = 100;
|
|
|
|
rrsig.labels = 0;
|
|
|
|
rrsig.originalttl = 0;
|
|
|
|
rrsig.timeexpire = 3600;
|
|
|
|
rrsig.timesigned = 0;
|
|
|
|
rrsig.keyid = 0;
|
|
|
|
dns_name_init(&rrsig.signer, NULL);
|
|
|
|
dns_name_clone(dns_rootname, &rrsig.signer);
|
|
|
|
rrsig.siglen = 0;
|
|
|
|
rrsig.signature = NULL;
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
res = dns_rdata_fromstruct(&rdata, dns_rdataclass_in,
|
|
|
|
dns_rdatatype_rrsig, &rrsig, &b);
|
|
|
|
assert_int_equal(res, ISC_R_SUCCESS);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
|
|
|
rdatalist.rdclass = dns_rdataclass_in;
|
|
|
|
rdatalist.type = dns_rdatatype_rrsig;
|
|
|
|
ISC_LIST_APPEND(rdatalist.rdata, &rdata, link);
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
res = dns_rdatalist_tordataset(&rdatalist, &rdataset);
|
|
|
|
assert_int_equal(res, ISC_R_SUCCESS);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
|
|
|
rdataset.attributes |= DNS_RDATASETATTR_RESIGN;
|
|
|
|
rdataset.resign = 7200;
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
res = dns_db_findnode(db1, dns_rootname, false, &node);
|
|
|
|
assert_int_equal(res, ISC_R_SUCCESS);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
res = dns_db_addrdataset(db1, node, v1, 0, &rdataset, 0, &added);
|
|
|
|
assert_int_equal(res, ISC_R_SUCCESS);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
|
|
|
dns_db_detachnode(db1, &node);
|
2018-11-09 10:23:49 -08:00
|
|
|
assert_null(node);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
check_assertion(dns_db_resigned(db1, &added, v2));
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
dns_db_resigned(db1, &added, v1);
|
2011-10-12 23:09:35 +00:00
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
dns_rdataset_disassociate(&added);
|
2011-10-12 23:09:35 +00:00
|
|
|
}
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
int
|
|
|
|
main(void) {
|
|
|
|
const struct CMUnitTest tests[] = {
|
|
|
|
cmocka_unit_test_setup_teardown(dump, _setup, _teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(find, _setup, _teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(allrdatasets,
|
|
|
|
_setup, _teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(findrdataset,
|
|
|
|
_setup, _teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(deleterdataset,
|
|
|
|
_setup, _teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(subtract,
|
|
|
|
_setup, _teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(addrdataset,
|
|
|
|
_setup, _teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(getnsec3parameters,
|
|
|
|
_setup, _teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(resigned,
|
|
|
|
_setup, _teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(attachversion,
|
|
|
|
_setup, _teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(closeversion,
|
|
|
|
_setup, _teardown),
|
|
|
|
};
|
|
|
|
|
|
|
|
return (cmocka_run_group_tests(tests, NULL, NULL));
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* HAVE_CMOCKA */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void) {
|
|
|
|
printf("1..0 # Skipped: cmocka not available\n");
|
|
|
|
return (0);
|
2011-10-12 23:09:35 +00:00
|
|
|
}
|
|
|
|
|
2018-11-09 10:23:49 -08:00
|
|
|
#endif
|