Debian Codegraph @

tests/dns/acl_test.c

raw
1 /*
2 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3 *
4 * SPDX-License-Identifier: MPL-2.0
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, you can obtain one at https://mozilla.org/MPL/2.0/.
9 *
10 * See the COPYRIGHT file distributed with this work for additional
11 * information regarding copyright ownership.
12 */
13
14 #include <inttypes.h>
15 #include <sched.h> /* IWYU pragma: keep */
16 #include <setjmp.h>
17 #include <stdarg.h>
18 #include <stddef.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <unistd.h>
23
24 #define UNIT_TESTING
25 #include <cmocka.h>
26
27 #include <isc/string.h>
28 #include <isc/util.h>
29
30 #include <dns/acl.h>
31
32 #include <tests/dns.h>
33
34 #define BUFLEN 255
35 #define BIGBUFLEN (70 * 1024)
36 #define TEST_ORIGIN "test"
37
38 /* test that dns_acl_isinsecure works */
39 ISC_RUN_TEST_IMPL(dns_acl_isinsecure) {
40 isc_result_t result;
41 dns_acl_t *any = NULL;
42 dns_acl_t *none = NULL;
43 dns_acl_t *notnone = NULL;
44 dns_acl_t *notany = NULL;
45 #if defined(HAVE_GEOIP2)
46 dns_acl_t *geoip = NULL;
47 dns_acl_t *notgeoip = NULL;
48 dns_aclelement_t *de;
49 #endif /* HAVE_GEOIP2 */
50
51 UNUSED(state);
52
53 result = dns_acl_any(mctx, &any);
54 assert_int_equal(result, ISC_R_SUCCESS);
55
56 result = dns_acl_none(mctx, &none);
57 assert_int_equal(result, ISC_R_SUCCESS);
58
59 dns_acl_create(mctx, 1, &notnone);
60
61 dns_acl_create(mctx, 1, &notany);
62
63 result = dns_acl_merge(notnone, none, false);
64 assert_int_equal(result, ISC_R_SUCCESS);
65
66 result = dns_acl_merge(notany, any, false);
67 assert_int_equal(result, ISC_R_SUCCESS);
68
69 #if defined(HAVE_GEOIP2)
70 dns_acl_create(mctx, 1, &geoip);
71
72 de = geoip->elements;
73 assert_non_null(de);
74 strlcpy(de->geoip_elem.as_string, "AU",
75 sizeof(de->geoip_elem.as_string));
76 de->geoip_elem.subtype = dns_geoip_country_code;
77 de->type = dns_aclelementtype_geoip;
78 de->negative = false;
79 assert_true(geoip->length < geoip->alloc);
80 dns_acl_node_count(geoip)++;
81 de->node_num = dns_acl_node_count(geoip);
82 geoip->length++;
83
84 dns_acl_create(mctx, 1, &notgeoip);
85
86 result = dns_acl_merge(notgeoip, geoip, false);
87 assert_int_equal(result, ISC_R_SUCCESS);
88 #endif /* HAVE_GEOIP2 */
89
90 assert_true(dns_acl_isinsecure(any)); /* any; */
91 assert_false(dns_acl_isinsecure(none)); /* none; */
92 assert_false(dns_acl_isinsecure(notany)); /* !any; */
93 assert_false(dns_acl_isinsecure(notnone)); /* !none; */
94
95 #if defined(HAVE_GEOIP2)
96 assert_true(dns_acl_isinsecure(geoip)); /* geoip; */
97 assert_false(dns_acl_isinsecure(notgeoip)); /* !geoip; */
98 #endif /* HAVE_GEOIP2 */
99
100 dns_acl_detach(&any);
101 dns_acl_detach(&none);
102 dns_acl_detach(&notany);
103 dns_acl_detach(&notnone);
104 #if defined(HAVE_GEOIP2)
105 dns_acl_detach(&geoip);
106 dns_acl_detach(&notgeoip);
107 #endif /* HAVE_GEOIP2 */
108 }
109
110 ISC_TEST_LIST_START
111 ISC_TEST_ENTRY(dns_acl_isinsecure)
112 ISC_TEST_LIST_END
113
114 ISC_TEST_MAIN