Debian Codegraph @

tests/dns/keytable_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 <stdbool.h>
19 #include <stddef.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <unistd.h>
23
24 #define UNIT_TESTING
25 #include <cmocka.h>
26
27 #include <isc/base64.h>
28 #include <isc/buffer.h>
29 #include <isc/md.h>
30 #include <isc/util.h>
31
32 #include <dns/fixedname.h>
33 #include <dns/keytable.h>
34 #include <dns/name.h>
35 #include <dns/nta.h>
36 #include <dns/rdataclass.h>
37 #include <dns/rdatastruct.h>
38 #include <dns/rootns.h>
39 #include <dns/view.h>
40
41 #include <dst/dst.h>
42
43 #include <tests/dns.h>
44
45 static int
46 setup_test(void **state) {
47 setup_loopmgr(state);
48
49 return 0;
50 }
51
52 static int
53 teardown_test(void **state) {
54 teardown_loopmgr(state);
55
56 return 0;
57 }
58
59 dns_keytable_t *keytable = NULL;
60 dns_ntatable_t *ntatable = NULL;
61
62 static const char *keystr1 = "BQEAAAABok+vaUC9neRv8yeT/"
63 "FEGgN7svR8s7VBUVSBd8NsAiV8AlaAg "
64 "O5FHar3JQd95i/puZos6Vi6at9/"
65 "JBbN8qVmO2AuiXxVqfxMKxIcy+LEB "
66 "0Vw4NaSJ3N3uaVREso6aTSs98H/"
67 "25MjcwLOr7SFfXA7bGhZatLtYY/xu kp6Km5hMfkE=";
68
69 static const char *keystr2 = "BQEAAAABwuHz9Cem0BJ0JQTO7C/a3McR6hMaufljs1dfG/"
70 "inaJpYv7vH "
71 "XTrAOm/MeKp+/x6eT4QLru0KoZkvZJnqTI8JyaFTw2OM/"
72 "ItBfh/hL2lm "
73 "Cft2O7n3MfeqYtvjPnY7dWghYW4sVfH7VVEGm958o9nfi7953"
74 "2Qeklxh x8pXWdeAaRU=";
75
76 static dns_view_t *view = NULL;
77
78 /*
79 * Test utilities. In general, these assume input parameters are valid
80 * (checking with assert_int_equal, thus aborting if not) and unlikely run time
81 * errors (such as memory allocation failure) won't happen. This helps keep
82 * the test code concise.
83 */
84
85 /*
86 * Utility to convert C-string to dns_name_t. Return a pointer to
87 * static data, and so is not thread safe.
88 */
89 static dns_name_t *
90 str2name(const char *namestr) {
91 static dns_fixedname_t fname;
92 static dns_name_t *name;
93 static isc_buffer_t namebuf;
94
95 name = dns_fixedname_initname(&fname);
96 isc_buffer_init(&namebuf, UNCONST(namestr), strlen(namestr));
97 isc_buffer_add(&namebuf, strlen(namestr));
98 assert_int_equal(
99 dns_name_fromtext(name, &namebuf, dns_rootname, 0, NULL),
100 ISC_R_SUCCESS);
101
102 return name;
103 }
104
105 static void
106 create_keystruct(uint16_t flags, uint8_t proto, uint8_t alg, const char *keystr,
107 dns_rdata_dnskey_t *keystruct) {
108 unsigned char keydata[4096];
109 isc_buffer_t keydatabuf;
110 isc_region_t r;
111 const dns_rdataclass_t rdclass = dns_rdataclass_in;
112
113 keystruct->common.rdclass = rdclass;
114 keystruct->common.rdtype = dns_rdatatype_dnskey;
115 keystruct->mctx = mctx;
116 ISC_LINK_INIT(&keystruct->common, link);
117 keystruct->flags = flags;
118 keystruct->protocol = proto;
119 keystruct->algorithm = alg;
120
121 isc_buffer_init(&keydatabuf, keydata, sizeof(keydata));
122 assert_int_equal(isc_base64_decodestring(keystr, &keydatabuf),
123 ISC_R_SUCCESS);
124 isc_buffer_usedregion(&keydatabuf, &r);
125 keystruct->datalen = r.length;
126 keystruct->data = isc_mem_allocate(mctx, r.length);
127 memmove(keystruct->data, r.base, r.length);
128 }
129
130 static void
131 create_dsstruct(dns_name_t *name, uint16_t flags, uint8_t proto, uint8_t alg,
132 const char *keystr, unsigned char *digest,
133 dns_rdata_ds_t *dsstruct) {
134 isc_result_t result;
135 unsigned char rrdata[4096];
136 isc_buffer_t rrdatabuf;
137 dns_rdata_t rdata = DNS_RDATA_INIT;
138 dns_rdata_dnskey_t dnskey;
139
140 /*
141 * Populate DNSKEY rdata structure.
142 */
143 create_keystruct(flags, proto, alg, keystr, &dnskey);
144
145 /*
146 * Convert to wire format.
147 */
148 isc_buffer_init(&rrdatabuf, rrdata, sizeof(rrdata));
149 result = dns_rdata_fromstruct(&rdata, dnskey.common.rdclass,
150 dnskey.common.rdtype, &dnskey,
151 &rrdatabuf);
152 assert_int_equal(result, ISC_R_SUCCESS);
153
154 /*
155 * Build DS rdata struct.
156 */
157 result = dns_ds_fromkeyrdata(name, &rdata, DNS_DSDIGEST_SHA256, digest,
158 dsstruct);
159 assert_int_equal(result, ISC_R_SUCCESS);
160
161 dns_rdata_freestruct(&dnskey);
162 }
163
164 /* Common setup: create a keytable and ntatable to test with a few keys */
165 static void
166 create_tables(void) {
167 unsigned char digest[ISC_MAX_MD_SIZE];
168 dns_rdata_ds_t ds;
169 dns_fixedname_t fn;
170 dns_name_t *keyname = dns_fixedname_name(&fn);
171 isc_stdtime_t now = isc_stdtime_now();
172
173 assert_int_equal(dns_test_makeview("view", false, false, &view),
174 ISC_R_SUCCESS);
175
176 dns_keytable_create(view, &keytable);
177 dns_ntatable_create(view, loopmgr, &ntatable);
178
179 /* Add a normal key */
180 dns_test_namefromstring("example.com.", &fn);
181 create_dsstruct(keyname, 257, 3, 5, keystr1, digest, &ds);
182 assert_int_equal(dns_keytable_add(keytable, false, false, keyname, &ds,
183 NULL, NULL),
184 ISC_R_SUCCESS);
185
186 /* Add an initializing managed key */
187 dns_test_namefromstring("managed.com.", &fn);
188 create_dsstruct(keyname, 257, 3, 5, keystr1, digest, &ds);
189 assert_int_equal(dns_keytable_add(keytable, true, true, keyname, &ds,
190 NULL, NULL),
191 ISC_R_SUCCESS);
192
193 /* Add a null key */
194 assert_int_equal(
195 dns_keytable_marksecure(keytable, str2name("null.example")),
196 ISC_R_SUCCESS);
197
198 /* Add a negative trust anchor, duration 1 hour */
199 assert_int_equal(dns_ntatable_add(ntatable,
200 str2name("insecure.example"), false,
201 now, 3600),
202 ISC_R_SUCCESS);
203 }
204
205 static void
206 destroy_tables(void) {
207 if (ntatable != NULL) {
208 dns_ntatable_shutdown(ntatable);
209 dns_ntatable_detach(&ntatable);
210 }
211 if (keytable != NULL) {
212 dns_keytable_detach(&keytable);
213 }
214
215 dns_view_detach(&view);
216 }
217
218 /* add keys to the keytable */
219 ISC_LOOP_TEST_IMPL(add) {
220 dns_keynode_t *keynode = NULL;
221 dns_keynode_t *null_keynode = NULL;
222 unsigned char digest[ISC_MAX_MD_SIZE];
223 dns_rdata_ds_t ds;
224 dns_fixedname_t fn;
225 dns_name_t *keyname = dns_fixedname_name(&fn);
226
227 UNUSED(arg);
228
229 create_tables();
230
231 /*
232 * Getting the keynode for the example.com key should succeed.
233 */
234 assert_int_equal(
235 dns_keytable_find(keytable, str2name("example.com"), &keynode),
236 ISC_R_SUCCESS);
237
238 /*
239 * Try to add the same key. This should have no effect but
240 * report success.
241 */
242 dns_test_namefromstring("example.com.", &fn);
243 create_dsstruct(keyname, 257, 3, 5, keystr1, digest, &ds);
244 assert_int_equal(dns_keytable_add(keytable, false, false, keyname, &ds,
245 NULL, NULL),
246 ISC_R_SUCCESS);
247 dns_keynode_detach(&keynode);
248 assert_int_equal(
249 dns_keytable_find(keytable, str2name("example.com"), &keynode),
250 ISC_R_SUCCESS);
251
252 /* Add another key (different keydata) */
253 dns_keynode_detach(&keynode);
254 create_dsstruct(keyname, 257, 3, 5, keystr2, digest, &ds);
255 assert_int_equal(dns_keytable_add(keytable, false, false, keyname, &ds,
256 NULL, NULL),
257 ISC_R_SUCCESS);
258 assert_int_equal(
259 dns_keytable_find(keytable, str2name("example.com"), &keynode),
260 ISC_R_SUCCESS);
261 dns_keynode_detach(&keynode);
262
263 /*
264 * Get the keynode for the managed.com key. Ensure the
265 * retrieved key is an initializing key, then mark it as trusted using
266 * dns_keynode_trust() and ensure the latter works as expected.
267 */
268 assert_int_equal(
269 dns_keytable_find(keytable, str2name("managed.com"), &keynode),
270 ISC_R_SUCCESS);
271 assert_int_equal(dns_keynode_initial(keynode), true);
272 dns_keynode_trust(keynode);
273 assert_int_equal(dns_keynode_initial(keynode), false);
274 dns_keynode_detach(&keynode);
275
276 /*
277 * Add a different managed key for managed.com, marking it as an
278 * initializing key. Since there is already a trusted key at the
279 * node, the node should *not* be marked as initializing.
280 */
281 dns_test_namefromstring("managed.com.", &fn);
282 create_dsstruct(keyname, 257, 3, 5, keystr2, digest, &ds);
283 assert_int_equal(dns_keytable_add(keytable, true, true, keyname, &ds,
284 NULL, NULL),
285 ISC_R_SUCCESS);
286 assert_int_equal(
287 dns_keytable_find(keytable, str2name("managed.com"), &keynode),
288 ISC_R_SUCCESS);
289 assert_int_equal(dns_keynode_initial(keynode), false);
290 dns_keynode_detach(&keynode);
291
292 /*
293 * Add the same managed key again, but this time mark it as a
294 * non-initializing key. Ensure the previously added key is upgraded
295 * to a non-initializing key and make sure there are still two key
296 * nodes for managed.com, both containing non-initializing keys.
297 */
298 assert_int_equal(dns_keytable_add(keytable, true, false, keyname, &ds,
299 NULL, NULL),
300 ISC_R_SUCCESS);
301 assert_int_equal(
302 dns_keytable_find(keytable, str2name("managed.com"), &keynode),
303 ISC_R_SUCCESS);
304 assert_int_equal(dns_keynode_initial(keynode), false);
305 dns_keynode_detach(&keynode);
306
307 /*
308 * Add a managed key at a new node, two.com, marking it as an
309 * initializing key.
310 */
311 dns_test_namefromstring("two.com.", &fn);
312 create_dsstruct(keyname, 257, 3, 5, keystr1, digest, &ds);
313 assert_int_equal(dns_keytable_add(keytable, true, true, keyname, &ds,
314 NULL, NULL),
315 ISC_R_SUCCESS);
316 assert_int_equal(
317 dns_keytable_find(keytable, str2name("two.com"), &keynode),
318 ISC_R_SUCCESS);
319 assert_int_equal(dns_keynode_initial(keynode), true);
320 dns_keynode_detach(&keynode);
321
322 /*
323 * Add a different managed key for two.com, marking it as a
324 * non-initializing key. Since there is already an iniitalizing
325 * trust anchor for two.com and we haven't run dns_keynode_trust(),
326 * the initialization status should not change.
327 */
328 create_dsstruct(keyname, 257, 3, 5, keystr2, digest, &ds);
329 assert_int_equal(dns_keytable_add(keytable, true, false, keyname, &ds,
330 NULL, NULL),
331 ISC_R_SUCCESS);
332 assert_int_equal(
333 dns_keytable_find(keytable, str2name("two.com"), &keynode),
334 ISC_R_SUCCESS);
335 assert_int_equal(dns_keynode_initial(keynode), true);
336 dns_keynode_detach(&keynode);
337
338 /*
339 * Add a normal key to a name that has a null key. The null key node
340 * will be updated with the normal key.
341 */
342 assert_int_equal(dns_keytable_find(keytable, str2name("null.example"),
343 &null_keynode),
344 ISC_R_SUCCESS);
345 dns_test_namefromstring("null.example.", &fn);
346 create_dsstruct(keyname, 257, 3, 5, keystr2, digest, &ds);
347 assert_int_equal(dns_keytable_add(keytable, false, false, keyname, &ds,
348 NULL, NULL),
349 ISC_R_SUCCESS);
350 assert_int_equal(
351 dns_keytable_find(keytable, str2name("null.example"), &keynode),
352 ISC_R_SUCCESS);
353 assert_ptr_equal(keynode, null_keynode); /* should be the same node */
354 dns_keynode_detach(&null_keynode);
355
356 /*
357 * Try to add a null key to a name that already has a key. It's
358 * effectively no-op, so the same key node is still there.
359 * (Note: this and above checks confirm that if a name has a null key
360 * that's the only key for the name).
361 */
362 assert_int_equal(
363 dns_keytable_marksecure(keytable, str2name("null.example")),
364 ISC_R_SUCCESS);
365 assert_int_equal(dns_keytable_find(keytable, str2name("null.example"),
366 &null_keynode),
367 ISC_R_SUCCESS);
368 assert_ptr_equal(keynode, null_keynode);
369 dns_keynode_detach(&null_keynode);
370
371 dns_keynode_detach(&keynode);
372 destroy_tables();
373
374 isc_loopmgr_shutdown(loopmgr);
375 }
376
377 /* delete keys from the keytable */
378 ISC_LOOP_TEST_IMPL(delete) {
379 UNUSED(arg);
380
381 create_tables();
382
383 /* dns_keytable_delete requires exact match */
384 assert_int_equal(dns_keytable_delete(keytable, str2name("example.org"),
385 NULL, NULL),
386 ISC_R_NOTFOUND);
387 assert_int_equal(dns_keytable_delete(keytable,
388 str2name("s.example.com"), NULL,
389 NULL),
390 ISC_R_NOTFOUND);
391 assert_int_equal(dns_keytable_delete(keytable, str2name("example.com"),
392 NULL, NULL),
393 ISC_R_SUCCESS);
394
395 /* works also for nodes with a null key */
396 assert_int_equal(dns_keytable_delete(keytable, str2name("null.example"),
397 NULL, NULL),
398 ISC_R_SUCCESS);
399
400 /* or a negative trust anchor */
401 assert_int_equal(
402 dns_ntatable_delete(ntatable, str2name("insecure.example")),
403 ISC_R_SUCCESS);
404
405 destroy_tables();
406
407 isc_loopmgr_shutdown(loopmgr);
408 }
409
410 /* delete key nodes from the keytable */
411 ISC_LOOP_TEST_IMPL(deletekey) {
412 dns_rdata_dnskey_t dnskey;
413 dns_fixedname_t fn;
414 dns_name_t *keyname = dns_fixedname_name(&fn);
415
416 UNUSED(arg);
417
418 create_tables();
419
420 /* key name doesn't match */
421 dns_test_namefromstring("example.org.", &fn);
422 create_keystruct(257, 3, 5, keystr1, &dnskey);
423 assert_int_equal(dns_keytable_deletekey(keytable, keyname, &dnskey),
424 ISC_R_NOTFOUND);
425 dns_rdata_freestruct(&dnskey);
426
427 /* subdomain match is the same as no match */
428 dns_test_namefromstring("sub.example.org.", &fn);
429 create_keystruct(257, 3, 5, keystr1, &dnskey);
430 assert_int_equal(dns_keytable_deletekey(keytable, keyname, &dnskey),
431 ISC_R_NOTFOUND);
432 dns_rdata_freestruct(&dnskey);
433
434 /* name matches but key doesn't match (resulting in PARTIALMATCH) */
435 dns_test_namefromstring("example.com.", &fn);
436 create_keystruct(257, 3, 5, keystr2, &dnskey);
437 assert_int_equal(dns_keytable_deletekey(keytable, keyname, &dnskey),
438 DNS_R_PARTIALMATCH);
439 dns_rdata_freestruct(&dnskey);
440
441 /*
442 * exact match: should return SUCCESS on the first try, then
443 * PARTIALMATCH on the second (because the name existed but
444 * not a matching key).
445 */
446 create_keystruct(257, 3, 5, keystr1, &dnskey);
447 assert_int_equal(dns_keytable_deletekey(keytable, keyname, &dnskey),
448 ISC_R_SUCCESS);
449 assert_int_equal(dns_keytable_deletekey(keytable, keyname, &dnskey),
450 DNS_R_PARTIALMATCH);
451
452 /*
453 * after deleting the node, any deletekey or delete attempt should
454 * result in NOTFOUND.
455 */
456 assert_int_equal(dns_keytable_delete(keytable, keyname, NULL, NULL),
457 ISC_R_SUCCESS);
458 assert_int_equal(dns_keytable_deletekey(keytable, keyname, &dnskey),
459 ISC_R_NOTFOUND);
460 dns_rdata_freestruct(&dnskey);
461
462 /*
463 * A null key node for a name is not deleted when searched by key;
464 * it must be deleted by dns_keytable_delete()
465 */
466 dns_test_namefromstring("null.example.", &fn);
467 create_keystruct(257, 3, 5, keystr1, &dnskey);
468 assert_int_equal(dns_keytable_deletekey(keytable, keyname, &dnskey),
469 DNS_R_PARTIALMATCH);
470 assert_int_equal(dns_keytable_delete(keytable, keyname, NULL, NULL),
471 ISC_R_SUCCESS);
472 dns_rdata_freestruct(&dnskey);
473
474 destroy_tables();
475
476 isc_loopmgr_shutdown(loopmgr);
477 }
478
479 /* check find-variant operations */
480 ISC_LOOP_TEST_IMPL(find) {
481 dns_keynode_t *keynode = NULL;
482 dns_fixedname_t fname;
483 dns_name_t *name;
484
485 UNUSED(arg);
486
487 create_tables();
488
489 /*
490 * dns_keytable_find() requires exact name match. It matches node
491 * that has a null key, too.
492 */
493 assert_int_equal(
494 dns_keytable_find(keytable, str2name("example.org"), &keynode),
495 ISC_R_NOTFOUND);
496 assert_int_equal(dns_keytable_find(keytable,
497 str2name("sub.example.com"),
498 &keynode),
499 ISC_R_NOTFOUND);
500 assert_int_equal(
501 dns_keytable_find(keytable, str2name("example.com"), &keynode),
502 ISC_R_SUCCESS);
503 dns_keynode_detach(&keynode);
504 assert_int_equal(
505 dns_keytable_find(keytable, str2name("null.example"), &keynode),
506 ISC_R_SUCCESS);
507 dns_keynode_detach(&keynode);
508
509 /*
510 * dns_keytable_finddeepestmatch() allows partial match. Also match
511 * nodes with a null key.
512 */
513 name = dns_fixedname_initname(&fname);
514 assert_int_equal(dns_keytable_finddeepestmatch(
515 keytable, str2name("example.com"), name),
516 ISC_R_SUCCESS);
517 assert_true(dns_name_equal(name, str2name("example.com")));
518 assert_int_equal(dns_keytable_finddeepestmatch(
519 keytable, str2name("s.example.com"), name),
520 ISC_R_SUCCESS);
521 assert_true(dns_name_equal(name, str2name("example.com")));
522 assert_int_equal(dns_keytable_finddeepestmatch(
523 keytable, str2name("example.org"), name),
524 ISC_R_NOTFOUND);
525 assert_int_equal(dns_keytable_finddeepestmatch(
526 keytable, str2name("null.example"), name),
527 ISC_R_SUCCESS);
528 assert_true(dns_name_equal(name, str2name("null.example")));
529
530 destroy_tables();
531
532 isc_loopmgr_shutdown(loopmgr);
533 }
534
535 /* check issecuredomain() */
536 ISC_LOOP_TEST_IMPL(issecuredomain) {
537 bool issecure;
538 const char **n;
539 const char *names[] = { "example.com", "sub.example.com",
540 "null.example", "sub.null.example", NULL };
541
542 UNUSED(arg);
543 create_tables();
544
545 /*
546 * Domains that are an exact or partial match of a key name are
547 * considered secure. It's the case even if the key is null
548 * (validation will then fail, but that's actually the intended effect
549 * of installing a null key).
550 */
551 for (n = names; *n != NULL; n++) {
552 assert_int_equal(dns_keytable_issecuredomain(keytable,
553 str2name(*n), NULL,
554 &issecure),
555 ISC_R_SUCCESS);
556 assert_true(issecure);
557 }
558
559 /*
560 * If the key table has no entry (not even a null one) for a domain or
561 * any of its ancestors, that domain is considered insecure.
562 */
563 assert_int_equal(dns_keytable_issecuredomain(keytable,
564 str2name("example.org"),
565 NULL, &issecure),
566 ISC_R_SUCCESS);
567 assert_false(issecure);
568
569 destroy_tables();
570
571 isc_loopmgr_shutdown(loopmgr);
572 }
573
574 /* check dns_keytable_dump() */
575 ISC_LOOP_TEST_IMPL(dump) {
576 FILE *f = fopen("/dev/null", "w");
577
578 UNUSED(arg);
579
580 create_tables();
581
582 /*
583 * Right now, we only confirm the dump attempt doesn't cause disruption
584 * (so we don't check the dump content).
585 */
586 assert_int_equal(dns_keytable_dump(keytable, f), ISC_R_SUCCESS);
587 fclose(f);
588
589 destroy_tables();
590
591 isc_loopmgr_shutdown(loopmgr);
592 }
593
594 /* check negative trust anchors */
595 ISC_LOOP_TEST_IMPL(nta) {
596 isc_result_t result;
597 bool issecure, covered;
598 dns_fixedname_t fn;
599 dns_name_t *keyname = dns_fixedname_name(&fn);
600 unsigned char digest[ISC_MAX_MD_SIZE];
601 dns_rdata_ds_t ds;
602 dns_view_t *myview = NULL;
603 isc_stdtime_t now = isc_stdtime_now();
604
605 result = dns_test_makeview("view", false, false, &myview);
606 assert_int_equal(result, ISC_R_SUCCESS);
607
608 dns_view_initsecroots(myview);
609
610 result = dns_view_getsecroots(myview, &keytable);
611 assert_int_equal(result, ISC_R_SUCCESS);
612
613 dns_view_initntatable(myview, loopmgr);
614 result = dns_view_getntatable(myview, &ntatable);
615 assert_int_equal(result, ISC_R_SUCCESS);
616
617 dns_test_namefromstring("example.", &fn);
618 create_dsstruct(keyname, 257, 3, 5, keystr1, digest, &ds);
619 result = dns_keytable_add(keytable, false, false, keyname, &ds, NULL,
620 NULL),
621 assert_int_equal(result, ISC_R_SUCCESS);
622
623 result = dns_ntatable_add(ntatable, str2name("insecure.example"), false,
624 now, 1);
625 assert_int_equal(result, ISC_R_SUCCESS);
626
627 /* Should be secure */
628 result = dns_view_issecuredomain(myview,
629 str2name("test.secure.example"), now,
630 true, &covered, &issecure);
631 assert_int_equal(result, ISC_R_SUCCESS);
632 assert_false(covered);
633 assert_true(issecure);
634
635 /* Should not be secure */
636 result = dns_view_issecuredomain(myview,
637 str2name("test.insecure.example"), now,
638 true, &covered, &issecure);
639 assert_int_equal(result, ISC_R_SUCCESS);
640 assert_true(covered);
641 assert_false(issecure);
642
643 /* NTA covered */
644 covered = dns_view_ntacovers(myview, now, str2name("insecure.example"),
645 dns_rootname);
646 assert_true(covered);
647
648 /* Not NTA covered */
649 covered = dns_view_ntacovers(myview, now, str2name("secure.example"),
650 dns_rootname);
651 assert_false(covered);
652
653 /* As of now + 2, the NTA should be clear */
654 result = dns_view_issecuredomain(myview,
655 str2name("test.insecure.example"),
656 now + 2, true, &covered, &issecure);
657 assert_int_equal(result, ISC_R_SUCCESS);
658 assert_false(covered);
659 assert_true(issecure);
660
661 /* Now check deletion */
662 result = dns_view_issecuredomain(myview, str2name("test.new.example"),
663 now, true, &covered, &issecure);
664 assert_int_equal(result, ISC_R_SUCCESS);
665 assert_false(covered);
666 assert_true(issecure);
667
668 result = dns_ntatable_add(ntatable, str2name("new.example"), false, now,
669 3600);
670 assert_int_equal(result, ISC_R_SUCCESS);
671
672 result = dns_view_issecuredomain(myview, str2name("test.new.example"),
673 now, true, &covered, &issecure);
674 assert_int_equal(result, ISC_R_SUCCESS);
675 assert_true(covered);
676 assert_false(issecure);
677
678 result = dns_ntatable_delete(ntatable, str2name("new.example"));
679 assert_int_equal(result, ISC_R_SUCCESS);
680
681 result = dns_view_issecuredomain(myview, str2name("test.new.example"),
682 now, true, &covered, &issecure);
683 assert_int_equal(result, ISC_R_SUCCESS);
684 assert_false(covered);
685 assert_true(issecure);
686
687 isc_loopmgr_shutdown(loopmgr);
688
689 /* Clean up */
690 dns_ntatable_detach(&ntatable);
691 dns_keytable_detach(&keytable);
692 dns_view_detach(&myview);
693 }
694
695 ISC_TEST_LIST_START
696 ISC_TEST_ENTRY_CUSTOM(add, setup_test, teardown_test)
697 ISC_TEST_ENTRY_CUSTOM(delete, setup_test, teardown_test)
698 ISC_TEST_ENTRY_CUSTOM(deletekey, setup_test, teardown_test)
699 ISC_TEST_ENTRY_CUSTOM(find, setup_test, teardown_test)
700 ISC_TEST_ENTRY_CUSTOM(issecuredomain, setup_test, teardown_test)
701 ISC_TEST_ENTRY_CUSTOM(dump, setup_test, teardown_test)
702 ISC_TEST_ENTRY_CUSTOM(nta, setup_test, teardown_test)
703 ISC_TEST_LIST_END
704
705 ISC_TEST_MAIN