2017-09-08 13:39:09 -07:00
|
|
|
/*
|
2018-02-23 09:53:12 +01:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2017-09-08 13:39:09 -07: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.
|
2017-09-08 13:39:09 -07:00
|
|
|
*/
|
|
|
|
|
2019-11-13 09:29:04 +01:00
|
|
|
#include <isc/util.h>
|
|
|
|
|
|
|
|
#if HAVE_CMOCKA && !__SANITIZE_ADDRESS__
|
2018-10-24 10:06:21 -07:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <sched.h> /* IWYU pragma: keep */
|
|
|
|
#include <setjmp.h>
|
2018-10-24 10:06:21 -07:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
2017-09-08 13:39:09 -07:00
|
|
|
#include <stdio.h>
|
2019-07-30 21:08:40 +02:00
|
|
|
#include <stdlib.h>
|
2018-10-24 10:06:21 -07:00
|
|
|
#include <string.h>
|
2017-09-08 13:39:09 -07:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2018-10-24 10:06:21 -07:00
|
|
|
#define UNIT_TESTING
|
|
|
|
#include <cmocka.h>
|
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
#include <isc/event.h>
|
|
|
|
#include <isc/print.h>
|
|
|
|
#include <isc/task.h>
|
|
|
|
|
|
|
|
#include <dns/acl.h>
|
|
|
|
#include <dns/rcode.h>
|
|
|
|
#include <dns/view.h>
|
|
|
|
|
|
|
|
#include <ns/client.h>
|
|
|
|
#include <ns/notify.h>
|
|
|
|
|
|
|
|
#include "nstest.h"
|
|
|
|
|
2019-11-14 10:00:36 +11:00
|
|
|
#if defined(USE_LIBTOOL) || LD_WRAP
|
2018-10-24 10:06:21 -07:00
|
|
|
static int
|
2020-02-12 13:59:18 +01:00
|
|
|
_setup(void **state)
|
|
|
|
{
|
2018-10-24 10:06:21 -07:00
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
UNUSED(state);
|
|
|
|
|
|
|
|
result = ns_test_begin(NULL, true);
|
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2020-02-12 13:59:18 +01:00
|
|
|
_teardown(void **state)
|
|
|
|
{
|
2018-10-24 10:06:21 -07:00
|
|
|
UNUSED(state);
|
|
|
|
|
|
|
|
ns_test_end();
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
static void
|
2020-02-12 13:59:18 +01:00
|
|
|
check_response(isc_buffer_t *buf)
|
|
|
|
{
|
|
|
|
isc_result_t result;
|
2017-09-08 13:39:09 -07:00
|
|
|
dns_message_t *message = NULL;
|
2020-02-12 13:59:18 +01:00
|
|
|
char rcodebuf[20];
|
|
|
|
isc_buffer_t b;
|
2017-09-08 13:39:09 -07:00
|
|
|
|
|
|
|
result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &message);
|
2018-10-24 10:06:21 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2017-09-08 13:39:09 -07:00
|
|
|
|
|
|
|
result = dns_message_parse(message, buf, 0);
|
2018-10-24 10:06:21 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2017-09-08 13:39:09 -07:00
|
|
|
|
|
|
|
isc_buffer_init(&b, rcodebuf, sizeof(rcodebuf));
|
|
|
|
result = dns_rcode_totext(message->rcode, &b);
|
2018-10-24 10:06:21 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2017-09-08 13:39:09 -07:00
|
|
|
|
2018-10-24 10:06:21 -07:00
|
|
|
assert_int_equal(message->rcode, dns_rcode_noerror);
|
2017-09-08 13:39:09 -07:00
|
|
|
|
|
|
|
dns_message_destroy(&message);
|
|
|
|
}
|
|
|
|
|
2018-10-24 10:06:21 -07:00
|
|
|
/* test ns_notify_start() */
|
|
|
|
static void
|
2020-02-12 13:59:18 +01:00
|
|
|
notify_start(void **state)
|
|
|
|
{
|
|
|
|
isc_result_t result;
|
|
|
|
ns_client_t * client = NULL;
|
2017-09-08 13:39:09 -07:00
|
|
|
dns_message_t *nmsg = NULL;
|
2020-02-12 13:59:18 +01:00
|
|
|
unsigned char ndata[4096];
|
|
|
|
isc_buffer_t nbuf;
|
|
|
|
size_t nsize;
|
2017-09-08 13:39:09 -07:00
|
|
|
|
2018-10-24 10:06:21 -07:00
|
|
|
UNUSED(state);
|
2017-09-08 13:39:09 -07:00
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
result = ns_test_getclient(NULL, false, &client);
|
2018-10-24 10:06:21 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2017-09-08 13:39:09 -07:00
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
result = ns_test_makeview("view", false, &client->view);
|
2018-10-24 10:06:21 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2017-10-11 15:02:50 -07:00
|
|
|
|
|
|
|
result = ns_test_serve_zone("example.com", "testdata/notify/zone1.db",
|
|
|
|
client->view);
|
2018-10-24 10:06:21 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2017-09-08 13:39:09 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a NOTIFY message by parsing a file in testdata.
|
|
|
|
* (XXX: use better message mocking method when available.)
|
|
|
|
*/
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
result = ns_test_getdata("testdata/notify/notify1.msg", ndata,
|
|
|
|
sizeof(ndata), &nsize);
|
2018-10-24 10:06:21 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_buffer_init(&nbuf, ndata, nsize);
|
|
|
|
isc_buffer_add(&nbuf, nsize);
|
|
|
|
|
|
|
|
result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &nmsg);
|
2018-10-24 10:06:21 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2017-09-08 13:39:09 -07:00
|
|
|
|
|
|
|
result = dns_message_parse(nmsg, &nbuf, 0);
|
2018-10-24 10:06:21 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2017-09-08 13:39:09 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up client object with this message and test the NOTIFY
|
|
|
|
* handler.
|
|
|
|
*/
|
2017-09-11 16:10:49 -07:00
|
|
|
if (client->message != NULL) {
|
|
|
|
dns_message_destroy(&client->message);
|
|
|
|
}
|
2017-09-08 13:39:09 -07:00
|
|
|
client->message = nmsg;
|
|
|
|
nmsg = NULL;
|
|
|
|
client->sendcb = check_response;
|
|
|
|
ns_notify_start(client);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clean up
|
|
|
|
*/
|
2017-10-11 15:02:50 -07:00
|
|
|
ns_test_cleanup_zone();
|
2019-11-05 15:34:35 -08:00
|
|
|
isc_nmhandle_unref(client->handle);
|
2018-10-24 10:06:21 -07:00
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* if defined(USE_LIBTOOL) || LD_WRAP */
|
2017-09-08 13:39:09 -07:00
|
|
|
|
2018-10-24 10:06:21 -07:00
|
|
|
int
|
2020-02-12 13:59:18 +01:00
|
|
|
main(void)
|
|
|
|
{
|
2019-11-14 10:00:36 +11:00
|
|
|
#if defined(USE_LIBTOOL) || LD_WRAP
|
2018-10-24 10:06:21 -07:00
|
|
|
const struct CMUnitTest tests[] = {
|
2020-02-12 13:59:18 +01:00
|
|
|
cmocka_unit_test_setup_teardown(notify_start, _setup,
|
|
|
|
_teardown),
|
2018-10-24 10:06:21 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
return (cmocka_run_group_tests(tests, NULL, NULL));
|
2020-02-13 21:48:23 +01:00
|
|
|
#else /* if defined(USE_LIBTOOL) || LD_WRAP */
|
2019-11-14 10:00:36 +11:00
|
|
|
print_message("1..0 # Skip notify_test requires libtool or LD_WRAP\n");
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* if defined(USE_LIBTOOL) || LD_WRAP */
|
2017-09-08 13:39:09 -07:00
|
|
|
}
|
2019-11-13 09:29:04 +01:00
|
|
|
#else /* HAVE_CMOCKA && !__SANITIZE_ADDRESS__ */
|
2018-10-24 10:06:21 -07:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
int
|
2020-02-12 13:59:18 +01:00
|
|
|
main(void)
|
|
|
|
{
|
2019-11-13 09:29:04 +01:00
|
|
|
#if __SANITIZE_ADDRESS__
|
|
|
|
/*
|
|
|
|
* We disable this test when the address sanitizer is in
|
|
|
|
* the use, as libuv will trigger errors.
|
|
|
|
*/
|
|
|
|
printf("1..0 # Skip ASAN is in use\n");
|
2020-02-12 13:59:18 +01:00
|
|
|
#else /* __SANITIZE_ADDRESS__ */
|
2019-11-05 15:34:35 -08:00
|
|
|
printf("1..0 # Skip cmocka not available\n");
|
2019-11-13 09:29:04 +01:00
|
|
|
#endif /* __SANITIZE_ADDRESS__ */
|
2018-10-24 10:06:21 -07:00
|
|
|
return (0);
|
2017-09-08 13:39:09 -07:00
|
|
|
}
|
2018-10-24 10:06:21 -07:00
|
|
|
|
2019-11-13 09:29:04 +01:00
|
|
|
#endif /* HAVE_CMOCKA && !__SANITIZE_ADDRESS__ */
|