|
Packit Service |
ae04f2 |
/*
|
|
Packit Service |
ae04f2 |
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
|
Packit Service |
ae04f2 |
*
|
|
Packit Service |
ae04f2 |
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
Packit Service |
ae04f2 |
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
Packit Service |
ae04f2 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
Packit Service |
ae04f2 |
*
|
|
Packit Service |
ae04f2 |
* See the COPYRIGHT file distributed with this work for additional
|
|
Packit Service |
ae04f2 |
* information regarding copyright ownership.
|
|
Packit Service |
ae04f2 |
*/
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
#include <config.h>
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
#if HAVE_CMOCKA
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
#include <stdarg.h>
|
|
Packit Service |
ae04f2 |
#include <stddef.h>
|
|
Packit Service |
ae04f2 |
#include <setjmp.h>
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
#include <sched.h> /* IWYU pragma: keep */
|
|
Packit Service |
ae04f2 |
#include <stdlib.h>
|
|
Packit Service |
ae04f2 |
#include <string.h>
|
|
Packit Service |
ae04f2 |
#include <unistd.h>
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
#define UNIT_TESTING
|
|
Packit Service |
ae04f2 |
#include <cmocka.h>
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
#include <isc/buffer.h>
|
|
Packit Service |
ae04f2 |
#include <isc/print.h>
|
|
Packit Service |
ae04f2 |
#include <isc/task.h>
|
|
Packit Service |
ae04f2 |
#include <isc/timer.h>
|
|
Packit Service |
ae04f2 |
#include <isc/util.h>
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
#include <dns/name.h>
|
|
Packit Service |
ae04f2 |
#include <dns/view.h>
|
|
Packit Service |
ae04f2 |
#include <dns/zone.h>
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
#include "dnstest.h"
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
static int
|
|
Packit Service |
ae04f2 |
_setup(void **state) {
|
|
Packit Service |
ae04f2 |
isc_result_t result;
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
UNUSED(state);
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
result = dns_test_begin(NULL, true);
|
|
Packit Service |
ae04f2 |
assert_int_equal(result, ISC_R_SUCCESS);
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
return (0);
|
|
Packit Service |
ae04f2 |
}
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
static int
|
|
Packit Service |
ae04f2 |
_teardown(void **state) {
|
|
Packit Service |
ae04f2 |
UNUSED(state);
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
dns_test_end();
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
return (0);
|
|
Packit Service |
ae04f2 |
}
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
/* create zone manager */
|
|
Packit Service |
ae04f2 |
static void
|
|
Packit Service |
ae04f2 |
zonemgr_create(void **state) {
|
|
Packit Service |
ae04f2 |
dns_zonemgr_t *myzonemgr = NULL;
|
|
Packit Service |
ae04f2 |
isc_result_t result;
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
UNUSED(state);
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
result = dns_zonemgr_create(mctx, taskmgr, timermgr, socketmgr,
|
|
Packit Service |
ae04f2 |
&myzonemgr);
|
|
Packit Service |
ae04f2 |
assert_int_equal(result, ISC_R_SUCCESS);
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
dns_zonemgr_shutdown(myzonemgr);
|
|
Packit Service |
ae04f2 |
dns_zonemgr_detach(&myzonemgr);
|
|
Packit Service |
ae04f2 |
assert_null(myzonemgr);
|
|
Packit Service |
ae04f2 |
}
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
/* manage and release a zone */
|
|
Packit Service |
ae04f2 |
static void
|
|
Packit Service |
ae04f2 |
zonemgr_managezone(void **state) {
|
|
Packit Service |
ae04f2 |
dns_zonemgr_t *myzonemgr = NULL;
|
|
Packit Service |
ae04f2 |
dns_zone_t *zone = NULL;
|
|
Packit Service |
ae04f2 |
isc_result_t result;
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
UNUSED(state);
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
result = dns_zonemgr_create(mctx, taskmgr, timermgr, socketmgr,
|
|
Packit Service |
ae04f2 |
&myzonemgr);
|
|
Packit Service |
ae04f2 |
assert_int_equal(result, ISC_R_SUCCESS);
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
result = dns_test_makezone("foo", &zone, NULL, false);
|
|
Packit Service |
ae04f2 |
assert_int_equal(result, ISC_R_SUCCESS);
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
/* This should not succeed until the dns_zonemgr_setsize() is run */
|
|
Packit Service |
ae04f2 |
result = dns_zonemgr_managezone(myzonemgr, zone);
|
|
Packit Service |
ae04f2 |
assert_int_equal(result, ISC_R_FAILURE);
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
assert_int_equal(dns_zonemgr_getcount(myzonemgr, DNS_ZONESTATE_ANY), 0);
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
result = dns_zonemgr_setsize(myzonemgr, 1);
|
|
Packit Service |
ae04f2 |
assert_int_equal(result, ISC_R_SUCCESS);
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
/* Now it should succeed */
|
|
Packit Service |
ae04f2 |
result = dns_zonemgr_managezone(myzonemgr, zone);
|
|
Packit Service |
ae04f2 |
assert_int_equal(result, ISC_R_SUCCESS);
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
assert_int_equal(dns_zonemgr_getcount(myzonemgr, DNS_ZONESTATE_ANY), 1);
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
dns_zonemgr_releasezone(myzonemgr, zone);
|
|
Packit Service |
ae04f2 |
dns_zone_detach(&zone);
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
assert_int_equal(dns_zonemgr_getcount(myzonemgr, DNS_ZONESTATE_ANY), 0);
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
dns_zonemgr_shutdown(myzonemgr);
|
|
Packit Service |
ae04f2 |
dns_zonemgr_detach(&myzonemgr);
|
|
Packit Service |
ae04f2 |
assert_null(myzonemgr);
|
|
Packit Service |
ae04f2 |
}
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
/* create and release a zone */
|
|
Packit Service |
ae04f2 |
static void
|
|
Packit Service |
ae04f2 |
zonemgr_createzone(void **state) {
|
|
Packit Service |
ae04f2 |
dns_zonemgr_t *myzonemgr = NULL;
|
|
Packit Service |
ae04f2 |
dns_zone_t *zone = NULL;
|
|
Packit Service |
ae04f2 |
isc_result_t result;
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
UNUSED(state);
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
result = dns_zonemgr_create(mctx, taskmgr, timermgr, socketmgr,
|
|
Packit Service |
ae04f2 |
&myzonemgr);
|
|
Packit Service |
ae04f2 |
assert_int_equal(result, ISC_R_SUCCESS);
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
/* This should not succeed until the dns_zonemgr_setsize() is run */
|
|
Packit Service |
ae04f2 |
result = dns_zonemgr_createzone(myzonemgr, &zone);
|
|
Packit Service |
ae04f2 |
assert_int_equal(result, ISC_R_FAILURE);
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
result = dns_zonemgr_setsize(myzonemgr, 1);
|
|
Packit Service |
ae04f2 |
assert_int_equal(result, ISC_R_SUCCESS);
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
/* Now it should succeed */
|
|
Packit Service |
ae04f2 |
result = dns_zonemgr_createzone(myzonemgr, &zone);
|
|
Packit Service |
ae04f2 |
assert_int_equal(result, ISC_R_SUCCESS);
|
|
Packit Service |
ae04f2 |
assert_non_null(zone);
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
if (zone != NULL)
|
|
Packit Service |
ae04f2 |
dns_zone_detach(&zone);
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
dns_zonemgr_shutdown(myzonemgr);
|
|
Packit Service |
ae04f2 |
dns_zonemgr_detach(&myzonemgr);
|
|
Packit Service |
ae04f2 |
assert_null(myzonemgr);
|
|
Packit Service |
ae04f2 |
}
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
/* manage and release a zone */
|
|
Packit Service |
ae04f2 |
static void
|
|
Packit Service |
ae04f2 |
zonemgr_unreachable(void **state) {
|
|
Packit Service |
ae04f2 |
dns_zonemgr_t *myzonemgr = NULL;
|
|
Packit Service |
ae04f2 |
dns_zone_t *zone = NULL;
|
|
Packit Service |
ae04f2 |
isc_sockaddr_t addr1, addr2;
|
|
Packit Service |
ae04f2 |
struct in_addr in;
|
|
Packit Service |
ae04f2 |
isc_result_t result;
|
|
Packit Service |
ae04f2 |
isc_time_t now;
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
UNUSED(state);
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
TIME_NOW(&now;;
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
result = dns_zonemgr_create(mctx, taskmgr, timermgr, socketmgr,
|
|
Packit Service |
ae04f2 |
&myzonemgr);
|
|
Packit Service |
ae04f2 |
assert_int_equal(result, ISC_R_SUCCESS);
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
result = dns_test_makezone("foo", &zone, NULL, false);
|
|
Packit Service |
ae04f2 |
assert_int_equal(result, ISC_R_SUCCESS);
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
result = dns_zonemgr_setsize(myzonemgr, 1);
|
|
Packit Service |
ae04f2 |
assert_int_equal(result, ISC_R_SUCCESS);
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
result = dns_zonemgr_managezone(myzonemgr, zone);
|
|
Packit Service |
ae04f2 |
assert_int_equal(result, ISC_R_SUCCESS);
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
in.s_addr = inet_addr("10.53.0.1");
|
|
Packit Service |
ae04f2 |
isc_sockaddr_fromin(&addr1, &in, 2112);
|
|
Packit Service |
ae04f2 |
in.s_addr = inet_addr("10.53.0.2");
|
|
Packit Service |
ae04f2 |
isc_sockaddr_fromin(&addr2, &in, 5150);
|
|
Packit Service |
ae04f2 |
assert_false(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
|
Packit Service |
ae04f2 |
/*
|
|
Packit Service |
ae04f2 |
* We require multiple unreachableadd calls to mark a server as
|
|
Packit Service |
ae04f2 |
* unreachable.
|
|
Packit Service |
ae04f2 |
*/
|
|
Packit Service |
ae04f2 |
dns_zonemgr_unreachableadd(myzonemgr, &addr1, &addr2, &now;;
|
|
Packit Service |
ae04f2 |
assert_false(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
|
Packit Service |
ae04f2 |
dns_zonemgr_unreachableadd(myzonemgr, &addr1, &addr2, &now;;
|
|
Packit Service |
ae04f2 |
assert_true(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
in.s_addr = inet_addr("10.53.0.3");
|
|
Packit Service |
ae04f2 |
isc_sockaddr_fromin(&addr2, &in, 5150);
|
|
Packit Service |
ae04f2 |
assert_false(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
|
Packit Service |
ae04f2 |
/*
|
|
Packit Service |
ae04f2 |
* We require multiple unreachableadd calls to mark a server as
|
|
Packit Service |
ae04f2 |
* unreachable.
|
|
Packit Service |
ae04f2 |
*/
|
|
Packit Service |
ae04f2 |
dns_zonemgr_unreachableadd(myzonemgr, &addr1, &addr2, &now;;
|
|
Packit Service |
ae04f2 |
dns_zonemgr_unreachableadd(myzonemgr, &addr1, &addr2, &now;;
|
|
Packit Service |
ae04f2 |
assert_true(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
dns_zonemgr_unreachabledel(myzonemgr, &addr1, &addr2);
|
|
Packit Service |
ae04f2 |
assert_false(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
in.s_addr = inet_addr("10.53.0.2");
|
|
Packit Service |
ae04f2 |
isc_sockaddr_fromin(&addr2, &in, 5150);
|
|
Packit Service |
ae04f2 |
assert_true(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
|
Packit Service |
ae04f2 |
dns_zonemgr_unreachabledel(myzonemgr, &addr1, &addr2);
|
|
Packit Service |
ae04f2 |
assert_false(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
dns_zonemgr_releasezone(myzonemgr, zone);
|
|
Packit Service |
ae04f2 |
dns_zone_detach(&zone);
|
|
Packit Service |
ae04f2 |
dns_zonemgr_shutdown(myzonemgr);
|
|
Packit Service |
ae04f2 |
dns_zonemgr_detach(&myzonemgr);
|
|
Packit Service |
ae04f2 |
assert_null(myzonemgr);
|
|
Packit Service |
ae04f2 |
}
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
/*
|
|
Packit Service |
ae04f2 |
* XXX:
|
|
Packit Service |
ae04f2 |
* dns_zonemgr API calls that are not yet part of this unit test:
|
|
Packit Service |
ae04f2 |
*
|
|
Packit Service |
ae04f2 |
* - dns_zonemgr_attach
|
|
Packit Service |
ae04f2 |
* - dns_zonemgr_forcemaint
|
|
Packit Service |
ae04f2 |
* - dns_zonemgr_resumexfrs
|
|
Packit Service |
ae04f2 |
* - dns_zonemgr_shutdown
|
|
Packit Service |
ae04f2 |
* - dns_zonemgr_setsize
|
|
Packit Service |
ae04f2 |
* - dns_zonemgr_settransfersin
|
|
Packit Service |
ae04f2 |
* - dns_zonemgr_getttransfersin
|
|
Packit Service |
ae04f2 |
* - dns_zonemgr_settransfersperns
|
|
Packit Service |
ae04f2 |
* - dns_zonemgr_getttransfersperns
|
|
Packit Service |
ae04f2 |
* - dns_zonemgr_setiolimit
|
|
Packit Service |
ae04f2 |
* - dns_zonemgr_getiolimit
|
|
Packit Service |
ae04f2 |
* - dns_zonemgr_dbdestroyed
|
|
Packit Service |
ae04f2 |
* - dns_zonemgr_setserialqueryrate
|
|
Packit Service |
ae04f2 |
* - dns_zonemgr_getserialqueryrate
|
|
Packit Service |
ae04f2 |
*/
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
int
|
|
Packit Service |
ae04f2 |
main(void) {
|
|
Packit Service |
ae04f2 |
const struct CMUnitTest tests[] = {
|
|
Packit Service |
ae04f2 |
cmocka_unit_test_setup_teardown(zonemgr_create,
|
|
Packit Service |
ae04f2 |
_setup, _teardown),
|
|
Packit Service |
ae04f2 |
cmocka_unit_test_setup_teardown(zonemgr_managezone,
|
|
Packit Service |
ae04f2 |
_setup, _teardown),
|
|
Packit Service |
ae04f2 |
cmocka_unit_test_setup_teardown(zonemgr_createzone,
|
|
Packit Service |
ae04f2 |
_setup, _teardown),
|
|
Packit Service |
ae04f2 |
cmocka_unit_test_setup_teardown(zonemgr_unreachable,
|
|
Packit Service |
ae04f2 |
_setup, _teardown),
|
|
Packit Service |
ae04f2 |
};
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
return (cmocka_run_group_tests(tests, dns_test_init, dns_test_final));
|
|
Packit Service |
ae04f2 |
}
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
#else /* HAVE_CMOCKA */
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
#include <stdio.h>
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
int
|
|
Packit Service |
ae04f2 |
main(void) {
|
|
Packit Service |
ae04f2 |
printf("1..0 # Skipped: cmocka not available\n");
|
|
Packit Service |
ae04f2 |
return (0);
|
|
Packit Service |
ae04f2 |
}
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
#endif
|