From ecde0ea2d719153c84fca19eaeeeeb6a01c10c1a Mon Sep 17 00:00:00 2001 From: Evan Hunt Date: Wed, 5 Mar 2025 15:46:17 -0800 Subject: [PATCH] add a unit test with an empty node the db_test unit test now looks up an empty nonterminal node to exercise the behavior of the step() function in qpzone. --- tests/dns/db_test.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/tests/dns/db_test.c b/tests/dns/db_test.c index d9b7a1047a..7fa128b801 100644 --- a/tests/dns/db_test.c +++ b/tests/dns/db_test.c @@ -351,8 +351,40 @@ ISC_LOOP_TEST_IMPL(version) { result = dns_db_find(db, name, ver, dns_rdatatype_a, 0, 0, &node, foundname, &rdataset, NULL); assert_int_equal(result, ISC_R_SUCCESS); - dns_rdataset_disassociate(&rdataset); dns_db_detachnode(db, &node); + + /* Now we create a node with an empty parent */ + result = dns_db_newversion(db, &new); + dns_test_namefromstring("long.ent.name.test.test.", &fname); + result = dns_db_findnode(db, name, true, &node); + assert_int_equal(result, ISC_R_SUCCESS); + result = dns_db_addrdataset(db, node, new, 0, &rdataset, 0, NULL); + assert_int_equal(result, ISC_R_SUCCESS); + dns_rdataset_disassociate(&rdataset); + dns_rdataset_init(&rdataset); + + /* look up the ENT; it should be empty */ + dns_test_namefromstring("ent.name.test.test.", &fname); + dns_db_detachnode(db, &node); + result = dns_db_find(db, name, new, dns_rdatatype_a, 0, 0, &node, + foundname, &rdataset, NULL); + assert_int_equal(result, DNS_R_EMPTYNAME); + + /* ... but then we roll it back... */ + dns_db_closeversion(db, &new, false); + + /* ... and the ENT should be NXDOMAIN now */ + dns_test_namefromstring("ent.name.test.test.", &fname); + result = dns_db_find(db, name, ver, dns_rdatatype_a, 0, 0, &node, + foundname, &rdataset, NULL); + assert_int_equal(result, DNS_R_NXDOMAIN); + + if (dns_rdataset_isassociated(&rdataset)) { + dns_rdataset_disassociate(&rdataset); + } + if (node != NULL) { + dns_db_detachnode(db, &node); + } dns_db_closeversion(db, &ver, false); dns_db_detach(&db);