2011-07-06 05:05:52 +00:00
|
|
|
/*
|
2018-02-23 09:53:12 +01:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2011-07-06 05:05:52 +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
|
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.
|
2011-07-06 05:05:52 +00:00
|
|
|
*/
|
|
|
|
|
2018-10-25 20:30:51 -07:00
|
|
|
#if HAVE_CMOCKA
|
2011-07-06 05:05:52 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <sched.h> /* IWYU pragma: keep */
|
|
|
|
#include <setjmp.h>
|
2018-10-25 20:30:51 -07:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2011-07-06 05:05:52 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2018-10-25 20:30:51 -07:00
|
|
|
#define UNIT_TESTING
|
|
|
|
#include <cmocka.h>
|
|
|
|
|
2011-07-06 05:05:52 +00:00
|
|
|
#include <isc/buffer.h>
|
|
|
|
#include <isc/task.h>
|
|
|
|
#include <isc/timer.h>
|
2018-10-25 20:30:51 -07:00
|
|
|
#include <isc/util.h>
|
2011-07-06 05:05:52 +00:00
|
|
|
|
|
|
|
#include <dns/name.h>
|
|
|
|
#include <dns/view.h>
|
|
|
|
#include <dns/zone.h>
|
|
|
|
|
|
|
|
#include "dnstest.h"
|
|
|
|
|
2018-10-25 20:30:51 -07:00
|
|
|
static int
|
2020-02-13 14:44:37 -08:00
|
|
|
_setup(void **state) {
|
2011-07-06 05:05:52 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
2018-10-25 20:30:51 -07:00
|
|
|
UNUSED(state);
|
2011-07-06 05:05:52 +00:00
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
result = dns_test_begin(NULL, true);
|
2018-10-25 20:30:51 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2011-07-06 05:05:52 +00:00
|
|
|
|
2018-10-25 20:30:51 -07:00
|
|
|
return (0);
|
|
|
|
}
|
2011-07-06 05:05:52 +00:00
|
|
|
|
2018-10-25 20:30:51 -07:00
|
|
|
static int
|
2020-02-13 14:44:37 -08:00
|
|
|
_teardown(void **state) {
|
2018-10-25 20:30:51 -07:00
|
|
|
UNUSED(state);
|
2011-07-06 05:05:52 +00:00
|
|
|
|
|
|
|
dns_test_end();
|
2018-10-25 20:30:51 -07:00
|
|
|
|
|
|
|
return (0);
|
2011-07-06 05:05:52 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 20:30:51 -07:00
|
|
|
/* create zone manager */
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
zonemgr_create(void **state) {
|
2018-10-25 20:30:51 -07:00
|
|
|
dns_zonemgr_t *myzonemgr = NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_result_t result;
|
2018-10-25 20:30:51 -07:00
|
|
|
|
|
|
|
UNUSED(state);
|
|
|
|
|
2020-09-06 00:38:50 -07:00
|
|
|
result = dns_zonemgr_create(dt_mctx, taskmgr, timermgr, socketmgr, NULL,
|
2018-10-25 20:30:51 -07:00
|
|
|
&myzonemgr);
|
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2011-07-06 05:05:52 +00:00
|
|
|
|
2018-10-25 20:30:51 -07:00
|
|
|
dns_zonemgr_shutdown(myzonemgr);
|
|
|
|
dns_zonemgr_detach(&myzonemgr);
|
|
|
|
assert_null(myzonemgr);
|
2011-07-06 05:05:52 +00:00
|
|
|
}
|
2018-10-25 20:30:51 -07:00
|
|
|
|
|
|
|
/* manage and release a zone */
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
zonemgr_managezone(void **state) {
|
2015-01-20 13:29:18 -08:00
|
|
|
dns_zonemgr_t *myzonemgr = NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_zone_t *zone = NULL;
|
|
|
|
isc_result_t result;
|
2011-07-06 05:05:52 +00:00
|
|
|
|
2018-10-25 20:30:51 -07:00
|
|
|
UNUSED(state);
|
2011-07-06 05:05:52 +00:00
|
|
|
|
2020-09-06 00:38:50 -07:00
|
|
|
result = dns_zonemgr_create(dt_mctx, taskmgr, timermgr, socketmgr, NULL,
|
2015-01-20 13:29:18 -08:00
|
|
|
&myzonemgr);
|
2018-10-25 20:30:51 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2011-07-06 05:05:52 +00:00
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
result = dns_test_makezone("foo", &zone, NULL, false);
|
2018-10-25 20:30:51 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2011-07-06 05:05:52 +00:00
|
|
|
|
|
|
|
/* This should not succeed until the dns_zonemgr_setsize() is run */
|
2015-01-20 13:29:18 -08:00
|
|
|
result = dns_zonemgr_managezone(myzonemgr, zone);
|
2018-10-25 20:30:51 -07:00
|
|
|
assert_int_equal(result, ISC_R_FAILURE);
|
2011-07-06 05:05:52 +00:00
|
|
|
|
2018-10-25 20:30:51 -07:00
|
|
|
assert_int_equal(dns_zonemgr_getcount(myzonemgr, DNS_ZONESTATE_ANY), 0);
|
2011-07-06 05:05:52 +00:00
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
result = dns_zonemgr_setsize(myzonemgr, 1);
|
2018-10-25 20:30:51 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2011-07-06 05:05:52 +00:00
|
|
|
|
|
|
|
/* Now it should succeed */
|
2015-01-20 13:29:18 -08:00
|
|
|
result = dns_zonemgr_managezone(myzonemgr, zone);
|
2018-10-25 20:30:51 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2011-07-06 05:05:52 +00:00
|
|
|
|
2018-10-25 20:30:51 -07:00
|
|
|
assert_int_equal(dns_zonemgr_getcount(myzonemgr, DNS_ZONESTATE_ANY), 1);
|
2011-07-06 05:05:52 +00:00
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
dns_zonemgr_releasezone(myzonemgr, zone);
|
2011-07-06 05:05:52 +00:00
|
|
|
dns_zone_detach(&zone);
|
|
|
|
|
2018-10-25 20:30:51 -07:00
|
|
|
assert_int_equal(dns_zonemgr_getcount(myzonemgr, DNS_ZONESTATE_ANY), 0);
|
2011-07-06 05:05:52 +00:00
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
dns_zonemgr_shutdown(myzonemgr);
|
|
|
|
dns_zonemgr_detach(&myzonemgr);
|
2018-10-25 20:30:51 -07:00
|
|
|
assert_null(myzonemgr);
|
2011-07-06 05:05:52 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 20:30:51 -07:00
|
|
|
/* create and release a zone */
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
zonemgr_createzone(void **state) {
|
2015-01-20 13:29:18 -08:00
|
|
|
dns_zonemgr_t *myzonemgr = NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_zone_t *zone = NULL;
|
|
|
|
isc_result_t result;
|
2013-02-20 21:39:05 -08:00
|
|
|
|
2018-10-25 20:30:51 -07:00
|
|
|
UNUSED(state);
|
2013-02-20 21:39:05 -08:00
|
|
|
|
2020-09-06 00:38:50 -07:00
|
|
|
result = dns_zonemgr_create(dt_mctx, taskmgr, timermgr, socketmgr, NULL,
|
2015-01-20 13:29:18 -08:00
|
|
|
&myzonemgr);
|
2018-10-25 20:30:51 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2013-02-20 21:39:05 -08:00
|
|
|
|
|
|
|
/* This should not succeed until the dns_zonemgr_setsize() is run */
|
2015-01-20 13:29:18 -08:00
|
|
|
result = dns_zonemgr_createzone(myzonemgr, &zone);
|
2018-10-25 20:30:51 -07:00
|
|
|
assert_int_equal(result, ISC_R_FAILURE);
|
2013-02-20 21:39:05 -08:00
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
result = dns_zonemgr_setsize(myzonemgr, 1);
|
2018-10-25 20:30:51 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2013-02-20 21:39:05 -08:00
|
|
|
|
|
|
|
/* Now it should succeed */
|
2015-01-20 13:29:18 -08:00
|
|
|
result = dns_zonemgr_createzone(myzonemgr, &zone);
|
2018-10-25 20:30:51 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
assert_non_null(zone);
|
2013-02-20 21:39:05 -08:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (zone != NULL) {
|
2013-02-20 21:39:05 -08:00
|
|
|
dns_zone_detach(&zone);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-02-20 21:39:05 -08:00
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
dns_zonemgr_shutdown(myzonemgr);
|
|
|
|
dns_zonemgr_detach(&myzonemgr);
|
2018-10-25 20:30:51 -07:00
|
|
|
assert_null(myzonemgr);
|
2013-02-20 21:39:05 -08:00
|
|
|
}
|
|
|
|
|
2018-10-25 20:30:51 -07:00
|
|
|
/* manage and release a zone */
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
zonemgr_unreachable(void **state) {
|
2015-01-20 13:29:18 -08:00
|
|
|
dns_zonemgr_t *myzonemgr = NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_zone_t *zone = NULL;
|
2011-11-04 05:51:02 +00:00
|
|
|
isc_sockaddr_t addr1, addr2;
|
|
|
|
struct in_addr in;
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_result_t result;
|
|
|
|
isc_time_t now;
|
2011-11-04 05:51:02 +00:00
|
|
|
|
2018-10-25 20:30:51 -07:00
|
|
|
UNUSED(state);
|
2011-11-04 05:51:02 +00:00
|
|
|
|
|
|
|
TIME_NOW(&now);
|
|
|
|
|
2020-09-06 00:38:50 -07:00
|
|
|
result = dns_zonemgr_create(dt_mctx, taskmgr, timermgr, socketmgr, NULL,
|
2015-01-20 13:29:18 -08:00
|
|
|
&myzonemgr);
|
2018-10-25 20:30:51 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2011-11-04 05:51:02 +00:00
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
result = dns_test_makezone("foo", &zone, NULL, false);
|
2018-10-25 20:30:51 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2011-11-04 05:51:02 +00:00
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
result = dns_zonemgr_setsize(myzonemgr, 1);
|
2018-10-25 20:30:51 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2011-11-04 05:51:02 +00:00
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
result = dns_zonemgr_managezone(myzonemgr, zone);
|
2018-10-25 20:30:51 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2011-11-04 05:51:02 +00:00
|
|
|
|
|
|
|
in.s_addr = inet_addr("10.53.0.1");
|
|
|
|
isc_sockaddr_fromin(&addr1, &in, 2112);
|
|
|
|
in.s_addr = inet_addr("10.53.0.2");
|
|
|
|
isc_sockaddr_fromin(&addr2, &in, 5150);
|
2018-10-25 20:30:51 -07:00
|
|
|
assert_false(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
2013-09-21 17:12:39 +10:00
|
|
|
/*
|
|
|
|
* We require multiple unreachableadd calls to mark a server as
|
|
|
|
* unreachable.
|
|
|
|
*/
|
2015-01-20 13:29:18 -08:00
|
|
|
dns_zonemgr_unreachableadd(myzonemgr, &addr1, &addr2, &now);
|
2018-10-25 20:30:51 -07:00
|
|
|
assert_false(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
2015-01-20 13:29:18 -08:00
|
|
|
dns_zonemgr_unreachableadd(myzonemgr, &addr1, &addr2, &now);
|
2018-10-25 20:30:51 -07:00
|
|
|
assert_true(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
2011-11-04 05:51:02 +00:00
|
|
|
|
|
|
|
in.s_addr = inet_addr("10.53.0.3");
|
|
|
|
isc_sockaddr_fromin(&addr2, &in, 5150);
|
2018-10-25 20:30:51 -07:00
|
|
|
assert_false(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
2013-09-21 17:12:39 +10:00
|
|
|
/*
|
|
|
|
* We require multiple unreachableadd calls to mark a server as
|
|
|
|
* unreachable.
|
|
|
|
*/
|
2015-01-20 13:29:18 -08:00
|
|
|
dns_zonemgr_unreachableadd(myzonemgr, &addr1, &addr2, &now);
|
|
|
|
dns_zonemgr_unreachableadd(myzonemgr, &addr1, &addr2, &now);
|
2018-10-25 20:30:51 -07:00
|
|
|
assert_true(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
2011-11-04 05:51:02 +00:00
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
dns_zonemgr_unreachabledel(myzonemgr, &addr1, &addr2);
|
2018-10-25 20:30:51 -07:00
|
|
|
assert_false(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
2011-11-04 05:51:02 +00:00
|
|
|
|
|
|
|
in.s_addr = inet_addr("10.53.0.2");
|
|
|
|
isc_sockaddr_fromin(&addr2, &in, 5150);
|
2018-10-25 20:30:51 -07:00
|
|
|
assert_true(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
2015-01-20 13:29:18 -08:00
|
|
|
dns_zonemgr_unreachabledel(myzonemgr, &addr1, &addr2);
|
2018-10-25 20:30:51 -07:00
|
|
|
assert_false(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
2011-11-04 05:51:02 +00:00
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
dns_zonemgr_releasezone(myzonemgr, zone);
|
2011-11-04 05:51:02 +00:00
|
|
|
dns_zone_detach(&zone);
|
2015-01-20 13:29:18 -08:00
|
|
|
dns_zonemgr_shutdown(myzonemgr);
|
|
|
|
dns_zonemgr_detach(&myzonemgr);
|
2018-10-25 20:30:51 -07:00
|
|
|
assert_null(myzonemgr);
|
2011-07-06 05:05:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX:
|
|
|
|
* dns_zonemgr API calls that are not yet part of this unit test:
|
|
|
|
*
|
|
|
|
* - dns_zonemgr_attach
|
|
|
|
* - dns_zonemgr_forcemaint
|
|
|
|
* - dns_zonemgr_resumexfrs
|
|
|
|
* - dns_zonemgr_shutdown
|
|
|
|
* - dns_zonemgr_setsize
|
|
|
|
* - dns_zonemgr_settransfersin
|
|
|
|
* - dns_zonemgr_getttransfersin
|
|
|
|
* - dns_zonemgr_settransfersperns
|
|
|
|
* - dns_zonemgr_getttransfersperns
|
|
|
|
* - dns_zonemgr_setiolimit
|
|
|
|
* - dns_zonemgr_getiolimit
|
|
|
|
* - dns_zonemgr_dbdestroyed
|
|
|
|
* - dns_zonemgr_setserialqueryrate
|
|
|
|
* - dns_zonemgr_getserialqueryrate
|
|
|
|
*/
|
2018-10-25 20:30:51 -07:00
|
|
|
|
|
|
|
int
|
2020-02-13 14:44:37 -08:00
|
|
|
main(void) {
|
2018-10-25 20:30:51 -07:00
|
|
|
const struct CMUnitTest tests[] = {
|
2020-02-12 13:59:18 +01:00
|
|
|
cmocka_unit_test_setup_teardown(zonemgr_create, _setup,
|
|
|
|
_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(zonemgr_managezone, _setup,
|
|
|
|
_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(zonemgr_createzone, _setup,
|
|
|
|
_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(zonemgr_unreachable, _setup,
|
|
|
|
_teardown),
|
2018-10-25 20:30:51 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
return (cmocka_run_group_tests(tests, NULL, NULL));
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* HAVE_CMOCKA */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
int
|
2020-02-13 14:44:37 -08:00
|
|
|
main(void) {
|
2018-10-25 20:30:51 -07:00
|
|
|
printf("1..0 # Skipped: cmocka not available\n");
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* if HAVE_CMOCKA */
|