2016-11-02 17:53:19 +11:00
|
|
|
/*
|
2018-02-23 09:53:12 +01:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2016-11-02 17:53:19 +11: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.
|
2016-11-02 17:53:19 +11:00
|
|
|
*/
|
|
|
|
|
2018-10-24 10:19:45 -07:00
|
|
|
#if HAVE_CMOCKA
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <setjmp.h>
|
2016-11-02 17:53:19 +11:00
|
|
|
|
2018-10-24 10:19:45 -07:00
|
|
|
#include <stdlib.h>
|
2016-11-02 17:53:19 +11:00
|
|
|
#include <stdio.h>
|
2018-10-24 10:19:45 -07:00
|
|
|
#include <string.h>
|
2016-11-02 17:53:19 +11:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2018-10-24 10:19:45 -07:00
|
|
|
#define UNIT_TESTING
|
|
|
|
#include <cmocka.h>
|
|
|
|
|
2016-11-02 17:53:19 +11:00
|
|
|
#include <isc/print.h>
|
2018-07-12 14:47:09 +10:00
|
|
|
#include <isc/string.h>
|
2018-10-24 10:19:45 -07:00
|
|
|
#include <isc/util.h>
|
2016-11-02 17:53:19 +11:00
|
|
|
|
|
|
|
#include <dns/acl.h>
|
2018-10-24 10:19:45 -07:00
|
|
|
|
2016-11-02 17:53:19 +11:00
|
|
|
#include "dnstest.h"
|
|
|
|
|
2018-10-24 10:19:45 -07:00
|
|
|
static int
|
|
|
|
_setup(void **state) {
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
UNUSED(state);
|
|
|
|
|
|
|
|
result = dns_test_begin(NULL, false);
|
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
_teardown(void **state) {
|
|
|
|
UNUSED(state);
|
|
|
|
|
|
|
|
dns_test_end();
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
2016-11-02 17:53:19 +11:00
|
|
|
|
|
|
|
#define BUFLEN 255
|
|
|
|
#define BIGBUFLEN (70 * 1024)
|
|
|
|
#define TEST_ORIGIN "test"
|
|
|
|
|
2018-10-24 10:19:45 -07:00
|
|
|
/* test that dns_acl_isinsecure works */
|
|
|
|
static void
|
|
|
|
dns_acl_isinsecure_test(void **state) {
|
2016-11-02 17:53:19 +11:00
|
|
|
isc_result_t result;
|
|
|
|
dns_acl_t *any = NULL;
|
|
|
|
dns_acl_t *none = NULL;
|
|
|
|
dns_acl_t *notnone = NULL;
|
|
|
|
dns_acl_t *notany = NULL;
|
2019-06-11 18:36:52 -07:00
|
|
|
#if defined(HAVE_GEOIP) || defined(HAVE_GEOIP2)
|
2018-07-12 14:47:09 +10:00
|
|
|
dns_acl_t *geoip = NULL;
|
|
|
|
dns_acl_t *notgeoip = NULL;
|
|
|
|
dns_aclelement_t *de;
|
2019-06-11 18:36:52 -07:00
|
|
|
#endif /* HAVE_GEOIP || HAVE_GEOIP2 */
|
2016-11-02 17:53:19 +11:00
|
|
|
|
2018-10-24 10:19:45 -07:00
|
|
|
UNUSED(state);
|
2016-11-02 17:53:19 +11:00
|
|
|
|
2019-06-18 15:01:43 +02:00
|
|
|
result = dns_acl_any(dt_mctx, &any);
|
2018-10-24 10:19:45 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2016-11-02 17:53:19 +11:00
|
|
|
|
2019-06-18 15:01:43 +02:00
|
|
|
result = dns_acl_none(dt_mctx, &none);
|
2018-10-24 10:19:45 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2016-11-02 17:53:19 +11:00
|
|
|
|
2019-06-18 15:01:43 +02:00
|
|
|
result = dns_acl_create(dt_mctx, 1, ¬none);
|
2018-10-24 10:19:45 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2016-11-02 17:53:19 +11:00
|
|
|
|
2019-06-18 15:01:43 +02:00
|
|
|
result = dns_acl_create(dt_mctx, 1, ¬any);
|
2018-10-24 10:19:45 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2016-11-02 17:53:19 +11:00
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
result = dns_acl_merge(notnone, none, false);
|
2018-10-24 10:19:45 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2016-11-02 17:53:19 +11:00
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
result = dns_acl_merge(notany, any, false);
|
2018-10-24 10:19:45 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2016-11-02 17:53:19 +11:00
|
|
|
|
2019-06-11 18:36:52 -07:00
|
|
|
#if defined(HAVE_GEOIP) || defined(HAVE_GEOIP2)
|
2019-06-18 15:01:43 +02:00
|
|
|
result = dns_acl_create(dt_mctx, 1, &geoip);
|
2018-10-24 10:19:45 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2018-07-12 14:47:09 +10:00
|
|
|
|
|
|
|
de = geoip->elements;
|
2018-10-24 10:19:45 -07:00
|
|
|
assert_non_null(de);
|
2018-07-12 14:47:09 +10:00
|
|
|
strlcpy(de->geoip_elem.as_string, "AU",
|
|
|
|
sizeof(de->geoip_elem.as_string));
|
|
|
|
de->geoip_elem.subtype = dns_geoip_country_code;
|
|
|
|
de->type = dns_aclelementtype_geoip;
|
2018-04-17 08:29:14 -07:00
|
|
|
de->negative = false;
|
2018-10-24 10:19:45 -07:00
|
|
|
assert_true(geoip->length < geoip->alloc);
|
2018-07-12 14:47:09 +10:00
|
|
|
geoip->node_count++;
|
|
|
|
de->node_num = geoip->node_count;
|
|
|
|
geoip->length++;
|
|
|
|
|
2019-06-18 15:01:43 +02:00
|
|
|
result = dns_acl_create(dt_mctx, 1, ¬geoip);
|
2018-10-24 10:19:45 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2018-07-12 14:47:09 +10:00
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
result = dns_acl_merge(notgeoip, geoip, false);
|
2018-10-24 10:19:45 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2019-06-11 18:36:52 -07:00
|
|
|
#endif /* HAVE_GEOIP || HAVE_GEOIP2 */
|
2018-07-12 14:47:09 +10:00
|
|
|
|
2018-10-24 10:19:45 -07:00
|
|
|
assert_true(dns_acl_isinsecure(any)); /* any; */
|
|
|
|
assert_false(dns_acl_isinsecure(none)); /* none; */
|
|
|
|
assert_false(dns_acl_isinsecure(notany)); /* !any; */
|
|
|
|
assert_false(dns_acl_isinsecure(notnone)); /* !none; */
|
2016-11-02 17:53:19 +11:00
|
|
|
|
2019-06-11 18:36:52 -07:00
|
|
|
#if defined(HAVE_GEOIP) || defined(HAVE_GEOIP2)
|
2018-10-24 10:19:45 -07:00
|
|
|
assert_true(dns_acl_isinsecure(geoip)); /* geoip; */
|
|
|
|
assert_false(dns_acl_isinsecure(notgeoip)); /* !geoip; */
|
2019-06-11 18:36:52 -07:00
|
|
|
#endif /* HAVE_GEOIP || HAVE_GEOIP2 */
|
2018-07-12 14:47:09 +10:00
|
|
|
|
2016-11-02 17:53:19 +11:00
|
|
|
dns_acl_detach(&any);
|
|
|
|
dns_acl_detach(&none);
|
|
|
|
dns_acl_detach(¬any);
|
|
|
|
dns_acl_detach(¬none);
|
2019-06-11 18:36:52 -07:00
|
|
|
#if defined(HAVE_GEOIP) || defined(HAVE_GEOIP2)
|
2018-07-12 14:47:09 +10:00
|
|
|
dns_acl_detach(&geoip);
|
|
|
|
dns_acl_detach(¬geoip);
|
2019-06-11 18:36:52 -07:00
|
|
|
#endif /* HAVE_GEOIP || HAVE_GEOIP2 */
|
2018-10-24 10:19:45 -07:00
|
|
|
}
|
2016-11-02 17:53:19 +11:00
|
|
|
|
2018-10-24 10:19:45 -07:00
|
|
|
int
|
|
|
|
main(void) {
|
|
|
|
const struct CMUnitTest tests[] = {
|
|
|
|
cmocka_unit_test_setup_teardown(dns_acl_isinsecure_test,
|
|
|
|
_setup, _teardown),
|
|
|
|
};
|
|
|
|
|
|
|
|
return (cmocka_run_group_tests(tests, NULL, NULL));
|
2016-11-02 17:53:19 +11:00
|
|
|
}
|
|
|
|
|
2018-10-24 10:19:45 -07:00
|
|
|
#else /* HAVE_CMOCKA */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void) {
|
|
|
|
printf("1..0 # Skipped: cmocka not available\n");
|
|
|
|
return (0);
|
2016-11-02 17:53:19 +11:00
|
|
|
}
|
2018-10-24 10:19:45 -07:00
|
|
|
|
|
|
|
#endif
|