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
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2018-10-24 10:06:21 -07:00
|
|
|
#if HAVE_CMOCKA
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <setjmp.h>
|
2017-09-08 13:39:09 -07:00
|
|
|
|
2018-10-24 10:06:21 -07:00
|
|
|
#include <stdlib.h>
|
2017-09-08 13:39:09 -07:00
|
|
|
#include <stdio.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>
|
2018-10-24 10:06:21 -07:00
|
|
|
#include <isc/util.h>
|
2017-09-08 13:39:09 -07:00
|
|
|
|
|
|
|
#include <dns/acl.h>
|
|
|
|
#include <dns/rcode.h>
|
|
|
|
#include <dns/view.h>
|
|
|
|
|
|
|
|
#include <ns/client.h>
|
|
|
|
#include <ns/notify.h>
|
|
|
|
|
|
|
|
#include "nstest.h"
|
|
|
|
|
2018-10-24 10:06:21 -07:00
|
|
|
static int
|
|
|
|
_setup(void **state) {
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
UNUSED(state);
|
|
|
|
|
|
|
|
result = ns_test_begin(NULL, true);
|
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
_teardown(void **state) {
|
|
|
|
UNUSED(state);
|
|
|
|
|
|
|
|
ns_test_end();
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
static void
|
|
|
|
check_response(isc_buffer_t *buf) {
|
|
|
|
isc_result_t result;
|
|
|
|
dns_message_t *message = NULL;
|
|
|
|
char rcodebuf[20];
|
|
|
|
isc_buffer_t b;
|
|
|
|
|
|
|
|
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
|
|
|
|
notify_start(void **state) {
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_result_t result;
|
|
|
|
ns_client_t *client = NULL;
|
|
|
|
dns_message_t *nmsg = NULL;
|
|
|
|
unsigned char ndata[4096];
|
|
|
|
isc_buffer_t nbuf;
|
|
|
|
size_t nsize;
|
|
|
|
|
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.)
|
|
|
|
*/
|
|
|
|
|
|
|
|
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();
|
2017-09-08 13:39:09 -07:00
|
|
|
|
|
|
|
ns_client_detach(&client);
|
2018-10-24 10:06:21 -07:00
|
|
|
}
|
2017-09-08 13:39:09 -07:00
|
|
|
|
2018-10-24 10:06:21 -07:00
|
|
|
int
|
|
|
|
main(void) {
|
|
|
|
const struct CMUnitTest tests[] = {
|
|
|
|
cmocka_unit_test_setup_teardown(notify_start,
|
|
|
|
_setup, _teardown),
|
|
|
|
};
|
|
|
|
|
|
|
|
return (cmocka_run_group_tests(tests, NULL, NULL));
|
2017-09-08 13:39:09 -07:00
|
|
|
}
|
|
|
|
|
2018-10-24 10:06:21 -07:00
|
|
|
#else /* HAVE_CMOCKA */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void) {
|
|
|
|
printf("1..0 # Skipped: cmocka not available\n");
|
|
|
|
return (0);
|
2017-09-08 13:39:09 -07:00
|
|
|
}
|
2018-10-24 10:06:21 -07:00
|
|
|
|
|
|
|
#endif
|