2013-12-17 09:08:59 +11:00
|
|
|
/*
|
2018-02-23 09:53:12 +01:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2013-12-17 09:08:59 +11: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
|
2020-09-14 16:20:40 -07:00
|
|
|
* file, you can obtain one at https://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.
|
2013-12-17 09:08:59 +11:00
|
|
|
*/
|
|
|
|
|
2018-11-07 12:23:15 +07:00
|
|
|
#if HAVE_CMOCKA
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <sched.h> /* IWYU pragma: keep */
|
|
|
|
#include <setjmp.h>
|
2018-11-07 12:23:15 +07:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
2013-12-17 09:08:59 +11:00
|
|
|
#include <stdlib.h>
|
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 <unistd.h>
|
2013-12-17 09:08:59 +11:00
|
|
|
|
2018-11-07 12:23:15 +07:00
|
|
|
#define UNIT_TESTING
|
|
|
|
#include <cmocka.h>
|
|
|
|
|
2013-12-17 09:08:59 +11:00
|
|
|
#include <dns/db.h>
|
|
|
|
#include <dns/dbiterator.h>
|
|
|
|
#include <dns/journal.h>
|
2017-09-06 09:58:29 +10:00
|
|
|
#include <dns/name.h>
|
|
|
|
#include <dns/rdatalist.h>
|
2013-12-17 09:08:59 +11:00
|
|
|
|
|
|
|
#include "dnstest.h"
|
|
|
|
|
2018-11-07 12:23:15 +07:00
|
|
|
static int
|
2020-02-13 14:44:37 -08:00
|
|
|
_setup(void **state) {
|
2018-11-07 12:23:15 +07: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-13 14:44:37 -08:00
|
|
|
_teardown(void **state) {
|
2018-11-07 12:23:15 +07:00
|
|
|
UNUSED(state);
|
|
|
|
|
|
|
|
dns_test_end();
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
2013-12-17 09:08:59 +11:00
|
|
|
|
2020-02-13 14:44:37 -08:00
|
|
|
#define BUFLEN 255
|
|
|
|
#define BIGBUFLEN (64 * 1024)
|
2020-02-12 13:59:18 +01:00
|
|
|
#define TEST_ORIGIN "test"
|
2013-12-17 09:08:59 +11:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Individual unit tests
|
|
|
|
*/
|
|
|
|
|
2018-11-07 12:23:15 +07:00
|
|
|
/* test multiple calls to dns_db_getoriginnode */
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
getoriginnode_test(void **state) {
|
|
|
|
dns_db_t *db = NULL;
|
2013-12-17 09:08:59 +11:00
|
|
|
dns_dbnode_t *node = NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_mem_t *mctx = NULL;
|
|
|
|
isc_result_t result;
|
2013-12-17 09:08:59 +11:00
|
|
|
|
2018-11-07 12:23:15 +07:00
|
|
|
UNUSED(state);
|
|
|
|
|
2019-09-05 18:40:57 +02:00
|
|
|
isc_mem_create(&mctx);
|
2013-12-17 09:08:59 +11:00
|
|
|
|
2019-06-18 15:01:43 +02:00
|
|
|
result = dns_db_create(mctx, "rbt", dns_rootname, dns_dbtype_zone,
|
2017-09-06 09:58:29 +10:00
|
|
|
dns_rdataclass_in, 0, NULL, &db);
|
2018-11-07 12:23:15 +07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2013-12-17 09:08:59 +11:00
|
|
|
|
|
|
|
result = dns_db_getoriginnode(db, &node);
|
2018-11-07 12:23:15 +07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2013-12-17 09:08:59 +11:00
|
|
|
dns_db_detachnode(db, &node);
|
|
|
|
|
|
|
|
result = dns_db_getoriginnode(db, &node);
|
2018-11-07 12:23:15 +07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2013-12-17 09:08:59 +11:00
|
|
|
dns_db_detachnode(db, &node);
|
|
|
|
|
|
|
|
dns_db_detach(&db);
|
2019-06-18 15:01:43 +02:00
|
|
|
isc_mem_detach(&mctx);
|
2013-12-17 09:08:59 +11:00
|
|
|
}
|
|
|
|
|
2018-11-07 12:23:15 +07:00
|
|
|
/* test getservestalettl and setservestalettl */
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
getsetservestalettl_test(void **state) {
|
|
|
|
dns_db_t *db = NULL;
|
|
|
|
isc_mem_t *mctx = NULL;
|
2017-09-06 09:58:29 +10:00
|
|
|
isc_result_t result;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_ttl_t ttl;
|
2017-09-06 09:58:29 +10:00
|
|
|
|
2018-11-07 12:23:15 +07:00
|
|
|
UNUSED(state);
|
|
|
|
|
2019-09-05 18:40:57 +02:00
|
|
|
isc_mem_create(&mctx);
|
2017-09-06 09:58:29 +10:00
|
|
|
|
2019-06-18 15:01:43 +02:00
|
|
|
result = dns_db_create(mctx, "rbt", dns_rootname, dns_dbtype_cache,
|
2017-09-06 09:58:29 +10:00
|
|
|
dns_rdataclass_in, 0, NULL, &db);
|
2018-11-07 12:23:15 +07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2017-09-06 09:58:29 +10:00
|
|
|
|
|
|
|
ttl = 5000;
|
|
|
|
result = dns_db_getservestalettl(db, &ttl);
|
2018-11-07 12:23:15 +07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
assert_int_equal(ttl, 0);
|
2017-09-06 09:58:29 +10:00
|
|
|
|
|
|
|
ttl = 6 * 3600;
|
|
|
|
result = dns_db_setservestalettl(db, ttl);
|
2018-11-07 12:23:15 +07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2017-09-06 09:58:29 +10:00
|
|
|
|
|
|
|
ttl = 5000;
|
|
|
|
result = dns_db_getservestalettl(db, &ttl);
|
2018-11-07 12:23:15 +07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
assert_int_equal(ttl, 6 * 3600);
|
2017-09-06 09:58:29 +10:00
|
|
|
|
|
|
|
dns_db_detach(&db);
|
2019-06-18 15:01:43 +02:00
|
|
|
isc_mem_detach(&mctx);
|
2017-09-06 09:58:29 +10:00
|
|
|
}
|
|
|
|
|
2018-11-07 12:23:15 +07:00
|
|
|
/* check DNS_DBFIND_STALEOK works */
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_dbfind_staleok_test(void **state) {
|
|
|
|
dns_db_t *db = NULL;
|
|
|
|
dns_dbnode_t *node = NULL;
|
2017-09-06 09:58:29 +10:00
|
|
|
dns_fixedname_t example_fixed;
|
|
|
|
dns_fixedname_t found_fixed;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_name_t *example;
|
|
|
|
dns_name_t *found;
|
2017-09-06 09:58:29 +10:00
|
|
|
dns_rdatalist_t rdatalist;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_rdataset_t rdataset;
|
|
|
|
int count;
|
|
|
|
int pass;
|
|
|
|
isc_mem_t *mctx = NULL;
|
|
|
|
isc_result_t result;
|
|
|
|
unsigned char data[] = { 0x0a, 0x00, 0x00, 0x01 };
|
2017-09-06 09:58:29 +10:00
|
|
|
|
2018-11-07 12:23:15 +07:00
|
|
|
UNUSED(state);
|
|
|
|
|
2019-09-05 18:40:57 +02:00
|
|
|
isc_mem_create(&mctx);
|
2017-09-06 09:58:29 +10:00
|
|
|
|
2019-06-18 15:01:43 +02:00
|
|
|
result = dns_db_create(mctx, "rbt", dns_rootname, dns_dbtype_cache,
|
2017-09-06 09:58:29 +10:00
|
|
|
dns_rdataclass_in, 0, NULL, &db);
|
2018-11-07 12:23:15 +07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2017-09-06 09:58:29 +10:00
|
|
|
|
2018-03-28 14:38:09 +02:00
|
|
|
example = dns_fixedname_initname(&example_fixed);
|
|
|
|
found = dns_fixedname_initname(&found_fixed);
|
2017-09-06 09:58:29 +10:00
|
|
|
|
|
|
|
result = dns_name_fromstring(example, "example", 0, NULL);
|
2018-11-07 12:23:15 +07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2017-09-06 09:58:29 +10:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Pass 0: default; no stale processing permitted.
|
|
|
|
* Pass 1: stale processing for 1 second.
|
|
|
|
* Pass 2: stale turned off after being on.
|
|
|
|
*/
|
|
|
|
for (pass = 0; pass < 3; pass++) {
|
|
|
|
dns_rdata_t rdata = DNS_RDATA_INIT;
|
|
|
|
|
|
|
|
/* 10.0.0.1 */
|
|
|
|
rdata.data = data;
|
|
|
|
rdata.length = 4;
|
|
|
|
rdata.rdclass = dns_rdataclass_in;
|
|
|
|
rdata.type = dns_rdatatype_a;
|
|
|
|
|
|
|
|
dns_rdatalist_init(&rdatalist);
|
|
|
|
rdatalist.ttl = 2;
|
|
|
|
rdatalist.type = dns_rdatatype_a;
|
|
|
|
rdatalist.rdclass = dns_rdataclass_in;
|
|
|
|
ISC_LIST_APPEND(rdatalist.rdata, &rdata, link);
|
|
|
|
|
|
|
|
switch (pass) {
|
|
|
|
case 0:
|
|
|
|
/* default: stale processing off */
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
/* turn on stale processing */
|
|
|
|
result = dns_db_setservestalettl(db, 1);
|
2018-11-07 12:23:15 +07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2017-09-06 09:58:29 +10:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
/* turn off stale processing */
|
|
|
|
result = dns_db_setservestalettl(db, 0);
|
2018-11-07 12:23:15 +07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2017-09-06 09:58:29 +10:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
dns_rdataset_init(&rdataset);
|
|
|
|
result = dns_rdatalist_tordataset(&rdatalist, &rdataset);
|
2018-11-07 12:23:15 +07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2017-09-06 09:58:29 +10:00
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
result = dns_db_findnode(db, example, true, &node);
|
2018-11-07 12:23:15 +07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2017-09-06 09:58:29 +10:00
|
|
|
|
|
|
|
result = dns_db_addrdataset(db, node, NULL, 0, &rdataset, 0,
|
|
|
|
NULL);
|
2018-11-07 12:23:15 +07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2017-09-06 09:58:29 +10:00
|
|
|
|
|
|
|
dns_db_detachnode(db, &node);
|
|
|
|
dns_rdataset_disassociate(&rdataset);
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
result = dns_db_find(db, example, NULL, dns_rdatatype_a, 0, 0,
|
|
|
|
&node, found, &rdataset, NULL);
|
2018-11-07 12:23:15 +07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2017-09-06 09:58:29 +10:00
|
|
|
|
|
|
|
/*
|
|
|
|
* May loop for up to 2 seconds performing non stale lookups.
|
|
|
|
*/
|
|
|
|
count = 0;
|
|
|
|
do {
|
|
|
|
count++;
|
2020-05-18 13:45:10 +10:00
|
|
|
assert_in_range(count, 1, 21); /* loop sanity */
|
2018-11-07 12:23:15 +07:00
|
|
|
assert_int_equal(rdataset.attributes &
|
2020-02-12 13:59:18 +01:00
|
|
|
DNS_RDATASETATTR_STALE,
|
|
|
|
0);
|
2018-11-07 12:23:15 +07:00
|
|
|
assert_true(rdataset.ttl > 0);
|
2017-09-06 09:58:29 +10:00
|
|
|
dns_db_detachnode(db, &node);
|
|
|
|
dns_rdataset_disassociate(&rdataset);
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
usleep(100000); /* 100 ms */
|
2017-09-06 09:58:29 +10:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
result = dns_db_find(db, example, NULL, dns_rdatatype_a,
|
|
|
|
0, 0, &node, found, &rdataset,
|
|
|
|
NULL);
|
2017-09-06 09:58:29 +10:00
|
|
|
} while (result == ISC_R_SUCCESS);
|
|
|
|
|
2018-11-07 12:23:15 +07:00
|
|
|
assert_int_equal(result, ISC_R_NOTFOUND);
|
2017-09-06 09:58:29 +10:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check whether we can get stale data.
|
|
|
|
*/
|
|
|
|
result = dns_db_find(db, example, NULL, dns_rdatatype_a,
|
2020-02-12 13:59:18 +01:00
|
|
|
DNS_DBFIND_STALEOK, 0, &node, found,
|
|
|
|
&rdataset, NULL);
|
2017-09-06 09:58:29 +10:00
|
|
|
switch (pass) {
|
|
|
|
case 0:
|
2018-11-07 12:23:15 +07:00
|
|
|
assert_int_equal(result, ISC_R_NOTFOUND);
|
2017-09-06 09:58:29 +10:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
/*
|
|
|
|
* Should loop for 1 second with stale lookups then
|
|
|
|
* stop.
|
|
|
|
*/
|
|
|
|
count = 0;
|
|
|
|
do {
|
|
|
|
count++;
|
2018-11-07 12:23:15 +07:00
|
|
|
assert_in_range(count, 0, 49); /* loop sanity */
|
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
assert_int_equal(rdataset.attributes &
|
2020-02-12 13:59:18 +01:00
|
|
|
DNS_RDATASETATTR_STALE,
|
|
|
|
DNS_RDATASETATTR_STALE);
|
2017-09-06 09:58:29 +10:00
|
|
|
dns_db_detachnode(db, &node);
|
|
|
|
dns_rdataset_disassociate(&rdataset);
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
usleep(100000); /* 100 ms */
|
2017-09-06 09:58:29 +10:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
result = dns_db_find(
|
|
|
|
db, example, NULL, dns_rdatatype_a,
|
|
|
|
DNS_DBFIND_STALEOK, 0, &node, found,
|
|
|
|
&rdataset, NULL);
|
2017-09-06 09:58:29 +10:00
|
|
|
} while (result == ISC_R_SUCCESS);
|
2021-06-09 23:54:14 +10:00
|
|
|
/*
|
|
|
|
* usleep(100000) can be slightly less than 10ms so
|
|
|
|
* allow the count to reach 11.
|
|
|
|
*/
|
|
|
|
assert_in_range(count, 1, 11);
|
2018-11-07 12:23:15 +07:00
|
|
|
assert_int_equal(result, ISC_R_NOTFOUND);
|
2017-09-06 09:58:29 +10:00
|
|
|
break;
|
|
|
|
case 2:
|
2018-11-07 12:23:15 +07:00
|
|
|
assert_int_equal(result, ISC_R_NOTFOUND);
|
2017-09-06 09:58:29 +10:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dns_db_detach(&db);
|
2019-06-18 15:01:43 +02:00
|
|
|
isc_mem_detach(&mctx);
|
2017-09-06 09:58:29 +10:00
|
|
|
}
|
|
|
|
|
2018-11-07 12:23:15 +07:00
|
|
|
/* database class */
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
class_test(void **state) {
|
2018-02-28 20:18:27 -08:00
|
|
|
isc_result_t result;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_db_t *db = NULL;
|
2018-02-28 20:18:27 -08:00
|
|
|
|
2018-11-07 12:23:15 +07:00
|
|
|
UNUSED(state);
|
2018-02-28 20:18:27 -08:00
|
|
|
|
2019-06-18 15:01:43 +02:00
|
|
|
result = dns_db_create(dt_mctx, "rbt", dns_rootname, dns_dbtype_zone,
|
2018-02-28 20:18:27 -08:00
|
|
|
dns_rdataclass_in, 0, NULL, &db);
|
2018-11-07 12:23:15 +07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2018-02-28 20:18:27 -08:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
result = dns_db_load(db, "testdata/db/data.db", dns_masterformat_text,
|
|
|
|
0);
|
2018-11-07 12:23:15 +07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2018-02-28 20:18:27 -08:00
|
|
|
|
2018-11-07 12:23:15 +07:00
|
|
|
assert_int_equal(dns_db_class(db), dns_rdataclass_in);
|
2018-02-28 20:18:27 -08:00
|
|
|
|
|
|
|
dns_db_detach(&db);
|
|
|
|
}
|
|
|
|
|
2018-11-07 12:23:15 +07:00
|
|
|
/* database type */
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
dbtype_test(void **state) {
|
2018-02-28 20:18:27 -08:00
|
|
|
isc_result_t result;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_db_t *db = NULL;
|
2018-02-28 20:18:27 -08:00
|
|
|
|
2018-11-07 12:23:15 +07:00
|
|
|
UNUSED(state);
|
2018-02-28 20:18:27 -08:00
|
|
|
|
|
|
|
/* DB has zone semantics */
|
2019-06-18 15:01:43 +02:00
|
|
|
result = dns_db_create(dt_mctx, "rbt", dns_rootname, dns_dbtype_zone,
|
2018-02-28 20:18:27 -08:00
|
|
|
dns_rdataclass_in, 0, NULL, &db);
|
2018-11-07 12:23:15 +07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2020-02-12 13:59:18 +01:00
|
|
|
result = dns_db_load(db, "testdata/db/data.db", dns_masterformat_text,
|
|
|
|
0);
|
2018-11-07 12:23:15 +07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
assert_true(dns_db_iszone(db));
|
|
|
|
assert_false(dns_db_iscache(db));
|
2018-02-28 20:18:27 -08:00
|
|
|
dns_db_detach(&db);
|
|
|
|
|
|
|
|
/* DB has cache semantics */
|
2019-06-18 15:01:43 +02:00
|
|
|
result = dns_db_create(dt_mctx, "rbt", dns_rootname, dns_dbtype_cache,
|
2018-02-28 20:18:27 -08:00
|
|
|
dns_rdataclass_in, 0, NULL, &db);
|
2018-11-07 12:23:15 +07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2020-02-12 13:59:18 +01:00
|
|
|
result = dns_db_load(db, "testdata/db/data.db", dns_masterformat_text,
|
|
|
|
0);
|
2018-11-07 12:23:15 +07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
assert_true(dns_db_iscache(db));
|
|
|
|
assert_false(dns_db_iszone(db));
|
2018-02-28 20:18:27 -08:00
|
|
|
dns_db_detach(&db);
|
|
|
|
}
|
|
|
|
|
2018-11-07 12:23:15 +07:00
|
|
|
/* database versions */
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
version_test(void **state) {
|
|
|
|
isc_result_t result;
|
|
|
|
dns_fixedname_t fname, ffound;
|
|
|
|
dns_name_t *name, *foundname;
|
|
|
|
dns_db_t *db = NULL;
|
2018-02-28 20:18:27 -08:00
|
|
|
dns_dbversion_t *ver = NULL, *new = NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_dbnode_t *node = NULL;
|
|
|
|
dns_rdataset_t rdataset;
|
2018-02-28 20:18:27 -08:00
|
|
|
|
2018-11-07 12:23:15 +07:00
|
|
|
UNUSED(state);
|
2018-02-28 20:18:27 -08:00
|
|
|
|
|
|
|
result = dns_test_loaddb(&db, dns_dbtype_zone, "test.test",
|
|
|
|
"testdata/db/data.db");
|
2018-11-07 12:23:15 +07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2018-02-28 20:18:27 -08:00
|
|
|
|
|
|
|
/* Open current version for reading */
|
|
|
|
dns_db_currentversion(db, &ver);
|
|
|
|
dns_test_namefromstring("b.test.test", &fname);
|
|
|
|
name = dns_fixedname_name(&fname);
|
2018-03-28 14:38:09 +02:00
|
|
|
foundname = dns_fixedname_initname(&ffound);
|
2018-02-28 20:18:27 -08:00
|
|
|
dns_rdataset_init(&rdataset);
|
2020-02-12 13:59:18 +01:00
|
|
|
result = dns_db_find(db, name, ver, dns_rdatatype_a, 0, 0, &node,
|
2018-02-28 20:18:27 -08:00
|
|
|
foundname, &rdataset, NULL);
|
2018-11-07 12:23:15 +07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2018-02-28 20:18:27 -08:00
|
|
|
dns_rdataset_disassociate(&rdataset);
|
|
|
|
dns_db_detachnode(db, &node);
|
2018-04-17 08:29:14 -07:00
|
|
|
dns_db_closeversion(db, &ver, false);
|
2018-02-28 20:18:27 -08:00
|
|
|
|
|
|
|
/* Open new version for writing */
|
|
|
|
dns_db_currentversion(db, &ver);
|
|
|
|
dns_test_namefromstring("b.test.test", &fname);
|
|
|
|
name = dns_fixedname_name(&fname);
|
2018-03-28 14:38:09 +02:00
|
|
|
foundname = dns_fixedname_initname(&ffound);
|
2018-02-28 20:18:27 -08:00
|
|
|
dns_rdataset_init(&rdataset);
|
2020-02-12 13:59:18 +01:00
|
|
|
result = dns_db_find(db, name, ver, dns_rdatatype_a, 0, 0, &node,
|
2018-02-28 20:18:27 -08:00
|
|
|
foundname, &rdataset, NULL);
|
2018-11-07 12:23:15 +07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2018-02-28 20:18:27 -08:00
|
|
|
|
|
|
|
result = dns_db_newversion(db, &new);
|
2018-11-07 12:23:15 +07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2018-02-28 20:18:27 -08:00
|
|
|
|
2020-02-20 14:49:36 -08:00
|
|
|
/* Delete the rdataset from the new version */
|
2018-02-28 20:18:27 -08:00
|
|
|
result = dns_db_deleterdataset(db, node, new, dns_rdatatype_a, 0);
|
2018-11-07 12:23:15 +07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2018-02-28 20:18:27 -08:00
|
|
|
|
|
|
|
dns_rdataset_disassociate(&rdataset);
|
|
|
|
dns_db_detachnode(db, &node);
|
|
|
|
|
|
|
|
/* This should fail now */
|
|
|
|
result = dns_db_find(db, name, new, dns_rdatatype_a, 0, 0, &node,
|
|
|
|
foundname, &rdataset, NULL);
|
2018-11-07 12:23:15 +07:00
|
|
|
assert_int_equal(result, DNS_R_NXDOMAIN);
|
2018-02-28 20:18:27 -08:00
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
dns_db_closeversion(db, &new, true);
|
2018-02-28 20:18:27 -08:00
|
|
|
|
|
|
|
/* But this should still succeed */
|
|
|
|
result = dns_db_find(db, name, ver, dns_rdatatype_a, 0, 0, &node,
|
|
|
|
foundname, &rdataset, NULL);
|
2018-11-07 12:23:15 +07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2018-02-28 20:18:27 -08:00
|
|
|
dns_rdataset_disassociate(&rdataset);
|
|
|
|
dns_db_detachnode(db, &node);
|
2018-04-17 08:29:14 -07:00
|
|
|
dns_db_closeversion(db, &ver, false);
|
2018-02-28 20:18:27 -08:00
|
|
|
|
|
|
|
dns_db_detach(&db);
|
|
|
|
}
|
|
|
|
|
2018-11-07 12:23:15 +07:00
|
|
|
int
|
2020-02-13 14:44:37 -08:00
|
|
|
main(void) {
|
2018-11-07 12:23:15 +07:00
|
|
|
const struct CMUnitTest tests[] = {
|
|
|
|
cmocka_unit_test(getoriginnode_test),
|
|
|
|
cmocka_unit_test(getsetservestalettl_test),
|
|
|
|
cmocka_unit_test(dns_dbfind_staleok_test),
|
2020-02-12 13:59:18 +01:00
|
|
|
cmocka_unit_test_setup_teardown(class_test, _setup, _teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(dbtype_test, _setup, _teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(version_test, _setup,
|
|
|
|
_teardown),
|
2018-11-07 12:23:15 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
return (cmocka_run_group_tests(tests, NULL, NULL));
|
2013-12-17 09:08:59 +11:00
|
|
|
}
|
2018-11-07 12:23:15 +07:00
|
|
|
|
|
|
|
#else /* HAVE_CMOCKA */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
int
|
2020-02-13 14:44:37 -08:00
|
|
|
main(void) {
|
2018-11-07 12:23:15 +07:00
|
|
|
printf("1..0 # Skipped: cmocka not available\n");
|
2021-01-18 19:15:44 +01:00
|
|
|
return (SKIPPED_TEST_EXIT_CODE);
|
2018-11-07 12:23:15 +07:00
|
|
|
}
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* if HAVE_CMOCKA */
|