mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 06:25:31 +00:00
convert sigs_test
This commit is contained in:
@@ -9,15 +9,22 @@
|
|||||||
* information regarding copyright ownership.
|
* information regarding copyright ownership.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*! \file */
|
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include <atf-c.h>
|
#if HAVE_CMOCKA
|
||||||
|
|
||||||
#include <isc/util.h>
|
#include <stdarg.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <setjmp.h>
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#define UNIT_TESTING
|
||||||
|
#include <cmocka.h>
|
||||||
|
|
||||||
|
#include <isc/util.h>
|
||||||
|
|
||||||
#include <dns/db.h>
|
#include <dns/db.h>
|
||||||
#include <dns/diff.h>
|
#include <dns/diff.h>
|
||||||
@@ -44,6 +51,27 @@
|
|||||||
|
|
||||||
#include "dnstest.h"
|
#include "dnstest.h"
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
/*%
|
/*%
|
||||||
* Structure characterizing a single diff tuple in the dns_diff_t structure
|
* Structure characterizing a single diff tuple in the dns_diff_t structure
|
||||||
* prepared by dns__zone_updatesigs().
|
* prepared by dns__zone_updatesigs().
|
||||||
@@ -72,7 +100,7 @@ typedef struct {
|
|||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
compare_tuples(const zonediff_t *expected, dns_difftuple_t *found,
|
compare_tuples(const zonediff_t *expected, dns_difftuple_t *found,
|
||||||
const updatesigs_test_params_t *test, size_t index)
|
size_t index)
|
||||||
{
|
{
|
||||||
char found_covers[DNS_RDATATYPE_FORMATSIZE] = { };
|
char found_covers[DNS_RDATATYPE_FORMATSIZE] = { };
|
||||||
char found_type[DNS_RDATATYPE_FORMATSIZE] = { };
|
char found_type[DNS_RDATATYPE_FORMATSIZE] = { };
|
||||||
@@ -92,33 +120,21 @@ compare_tuples(const zonediff_t *expected, dns_difftuple_t *found,
|
|||||||
/*
|
/*
|
||||||
* Check operation.
|
* Check operation.
|
||||||
*/
|
*/
|
||||||
ATF_CHECK_EQ_MSG(expected->op, found->op,
|
assert_int_equal(expected->op, found->op);
|
||||||
"test \"%s\": tuple %zu: "
|
|
||||||
"expected op %d, found %d",
|
|
||||||
test->description, index,
|
|
||||||
expected->op, found->op);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check owner name.
|
* Check owner name.
|
||||||
*/
|
*/
|
||||||
expected_name = dns_fixedname_initname(&expected_fname);
|
expected_name = dns_fixedname_initname(&expected_fname);
|
||||||
result = dns_name_fromstring(expected_name, expected->owner, 0, mctx);
|
result = dns_name_fromstring(expected_name, expected->owner, 0, mctx);
|
||||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
dns_name_format(&found->name, found_name, sizeof(found_name));
|
dns_name_format(&found->name, found_name, sizeof(found_name));
|
||||||
ATF_CHECK_MSG(dns_name_equal(expected_name, &found->name),
|
assert_true(dns_name_equal(expected_name, &found->name));
|
||||||
"test \"%s\": tuple %zu: "
|
|
||||||
"expected owner \"%s\", found \"%s\"",
|
|
||||||
test->description, index,
|
|
||||||
expected->owner, found_name);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check TTL.
|
* Check TTL.
|
||||||
*/
|
*/
|
||||||
ATF_CHECK_EQ_MSG(expected->ttl, found->ttl,
|
assert_int_equal(expected->ttl, found->ttl);
|
||||||
"test \"%s\": tuple %zu: "
|
|
||||||
"expected TTL %u, found %u",
|
|
||||||
test->description, index,
|
|
||||||
expected->ttl, found->ttl);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Parse expected RR type.
|
* Parse expected RR type.
|
||||||
@@ -127,14 +143,14 @@ compare_tuples(const zonediff_t *expected, dns_difftuple_t *found,
|
|||||||
typeregion.length = strlen(expected->type);
|
typeregion.length = strlen(expected->type);
|
||||||
result = dns_rdatatype_fromtext(&expected_type,
|
result = dns_rdatatype_fromtext(&expected_type,
|
||||||
(isc_textregion_t*)&typeregion);
|
(isc_textregion_t*)&typeregion);
|
||||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Format found RR type for reporting purposes.
|
* Format found RR type for reporting purposes.
|
||||||
*/
|
*/
|
||||||
isc_buffer_init(&typebuf, found_type, sizeof(found_type));
|
isc_buffer_init(&typebuf, found_type, sizeof(found_type));
|
||||||
result = dns_rdatatype_totext(found->rdata.type, &typebuf);
|
result = dns_rdatatype_totext(found->rdata.type, &typebuf);
|
||||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check RR type.
|
* Check RR type.
|
||||||
@@ -145,11 +161,7 @@ compare_tuples(const zonediff_t *expected, dns_difftuple_t *found,
|
|||||||
/*
|
/*
|
||||||
* Found tuple must be of type RRSIG.
|
* Found tuple must be of type RRSIG.
|
||||||
*/
|
*/
|
||||||
ATF_CHECK_EQ_MSG(found->rdata.type, dns_rdatatype_rrsig,
|
assert_int_equal(found->rdata.type, dns_rdatatype_rrsig);
|
||||||
"test \"%s\": tuple %zu: "
|
|
||||||
"expected type RRSIG, found %s",
|
|
||||||
test->description, index,
|
|
||||||
found_type);
|
|
||||||
if (found->rdata.type != dns_rdatatype_rrsig) {
|
if (found->rdata.type != dns_rdatatype_rrsig) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -157,25 +169,17 @@ compare_tuples(const zonediff_t *expected, dns_difftuple_t *found,
|
|||||||
* The signature must cover an RRset of type 'expected->type'.
|
* The signature must cover an RRset of type 'expected->type'.
|
||||||
*/
|
*/
|
||||||
result = dns_rdata_tostruct(&found->rdata, &rrsig, NULL);
|
result = dns_rdata_tostruct(&found->rdata, &rrsig, NULL);
|
||||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
isc_buffer_init(&typebuf, found_covers, sizeof(found_covers));
|
isc_buffer_init(&typebuf, found_covers, sizeof(found_covers));
|
||||||
result = dns_rdatatype_totext(rrsig.covered, &typebuf);
|
result = dns_rdatatype_totext(rrsig.covered, &typebuf);
|
||||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
ATF_CHECK_EQ_MSG(expected_type, rrsig.covered,
|
assert_int_equal(expected_type, rrsig.covered);
|
||||||
"test \"%s\": tuple %zu: "
|
|
||||||
"expected RRSIG to cover %s, found covers %s",
|
|
||||||
test->description, index,
|
|
||||||
expected->type, found_covers);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
/*
|
/*
|
||||||
* Found tuple must be of type 'expected->type'.
|
* Found tuple must be of type 'expected->type'.
|
||||||
*/
|
*/
|
||||||
ATF_CHECK_EQ_MSG(expected_type, found->rdata.type,
|
assert_int_equal(expected_type, found->rdata.type);
|
||||||
"test \"%s\": tuple %zu: "
|
|
||||||
"expected type %s, found %s",
|
|
||||||
test->description, index,
|
|
||||||
expected->type, found_type);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -213,13 +217,13 @@ updatesigs_test(const updatesigs_test_params_t *test, dns_zone_t *zone,
|
|||||||
* Create a new version of the zone's database.
|
* Create a new version of the zone's database.
|
||||||
*/
|
*/
|
||||||
result = dns_db_newversion(db, &version);
|
result = dns_db_newversion(db, &version);
|
||||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a diff representing the supplied changes.
|
* Create a diff representing the supplied changes.
|
||||||
*/
|
*/
|
||||||
result = dns_test_difffromchanges(&raw_diff, test->changes, false);
|
result = dns_test_difffromchanges(&raw_diff, test->changes, false);
|
||||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Apply the "raw" diff to the new version of the zone's database as
|
* Apply the "raw" diff to the new version of the zone's database as
|
||||||
@@ -239,25 +243,16 @@ updatesigs_test(const updatesigs_test_params_t *test, dns_zone_t *zone,
|
|||||||
result = dns__zone_updatesigs(&raw_diff, db, version, zone_keys, nkeys,
|
result = dns__zone_updatesigs(&raw_diff, db, version, zone_keys, nkeys,
|
||||||
zone, now - 3600, now + 3600, 0, now,
|
zone, now - 3600, now + 3600, 0, now,
|
||||||
true, false, &zonediff);
|
true, false, &zonediff);
|
||||||
ATF_CHECK_EQ_MSG(result, ISC_R_SUCCESS,
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
"test \"%s\": expected success, got %s",
|
assert_true(ISC_LIST_EMPTY(raw_diff.tuples));
|
||||||
test->description, isc_result_totext(result));
|
assert_false(ISC_LIST_EMPTY(zone_diff.tuples));
|
||||||
ATF_CHECK_MSG(ISC_LIST_EMPTY(raw_diff.tuples),
|
|
||||||
"test \"%s\": raw diff was not emptied",
|
|
||||||
test->description);
|
|
||||||
ATF_CHECK_MSG(!ISC_LIST_EMPTY(zone_diff.tuples),
|
|
||||||
"test \"%s\": zone diff was not created",
|
|
||||||
test->description);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Ensure that the number of tuples in the zone diff is as expected.
|
* Ensure that the number of tuples in the zone diff is as expected.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
tuples_expected = 0;
|
tuples_expected = 0;
|
||||||
for (expected = test->zonediff;
|
for (expected = test->zonediff; expected->owner != NULL; expected++) {
|
||||||
expected->owner != NULL;
|
|
||||||
expected++)
|
|
||||||
{
|
|
||||||
tuples_expected++;
|
tuples_expected++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,11 +264,7 @@ updatesigs_test(const updatesigs_test_params_t *test, dns_zone_t *zone,
|
|||||||
tuples_found++;
|
tuples_found++;
|
||||||
}
|
}
|
||||||
|
|
||||||
ATF_REQUIRE_EQ_MSG(tuples_expected, tuples_found,
|
assert_int_equal(tuples_expected, tuples_found);
|
||||||
"test \"%s\": "
|
|
||||||
"expected %zu tuples in output, found %zu",
|
|
||||||
test->description,
|
|
||||||
tuples_expected, tuples_found);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Ensure that every tuple in the zone diff matches expectations.
|
* Ensure that every tuple in the zone diff matches expectations.
|
||||||
@@ -284,7 +275,7 @@ updatesigs_test(const updatesigs_test_params_t *test, dns_zone_t *zone,
|
|||||||
found != NULL;
|
found != NULL;
|
||||||
found = ISC_LIST_NEXT(found, link))
|
found = ISC_LIST_NEXT(found, link))
|
||||||
{
|
{
|
||||||
compare_tuples(expected, found, test, index);
|
compare_tuples(expected, found, index);
|
||||||
expected++;
|
expected++;
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
@@ -297,11 +288,9 @@ updatesigs_test(const updatesigs_test_params_t *test, dns_zone_t *zone,
|
|||||||
dns_diff_clear(&raw_diff);
|
dns_diff_clear(&raw_diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
ATF_TC(updatesigs);
|
/* dns__zone_updatesigs() tests */
|
||||||
ATF_TC_HEAD(updatesigs, tc) {
|
static void
|
||||||
atf_tc_set_md_var(tc, "descr", "dns__zone_updatesigs() tests");
|
updatesigs_next_test(void **state) {
|
||||||
}
|
|
||||||
ATF_TC_BODY(updatesigs, tc) {
|
|
||||||
dst_key_t *zone_keys[DNS_MAXZONEKEYS];
|
dst_key_t *zone_keys[DNS_MAXZONEKEYS];
|
||||||
dns_zone_t *zone = NULL;
|
dns_zone_t *zone = NULL;
|
||||||
dns_db_t *db = NULL;
|
dns_db_t *db = NULL;
|
||||||
@@ -310,28 +299,27 @@ ATF_TC_BODY(updatesigs, tc) {
|
|||||||
isc_stdtime_t now;
|
isc_stdtime_t now;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
result = dns_test_begin(NULL, true);
|
UNUSED(state);
|
||||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Prepare a zone along with its signing keys.
|
* Prepare a zone along with its signing keys.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
result = dns_test_makezone("example", &zone, NULL, false);
|
result = dns_test_makezone("example", &zone, NULL, false);
|
||||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
|
|
||||||
result = dns_test_loaddb(&db, dns_dbtype_zone, "example",
|
result = dns_test_loaddb(&db, dns_dbtype_zone, "example",
|
||||||
"testdata/master/master18.data");
|
"testdata/master/master18.data");
|
||||||
ATF_REQUIRE_EQ(result, DNS_R_SEENINCLUDE);
|
assert_int_equal(result, DNS_R_SEENINCLUDE);
|
||||||
|
|
||||||
result = dns_zone_setkeydirectory(zone, "testkeys");
|
result = dns_zone_setkeydirectory(zone, "testkeys");
|
||||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
|
|
||||||
isc_stdtime_get(&now);
|
isc_stdtime_get(&now);
|
||||||
result = dns__zone_findkeys(zone, db, NULL, now, mctx, DNS_MAXZONEKEYS,
|
result = dns__zone_findkeys(zone, db, NULL, now, mctx, DNS_MAXZONEKEYS,
|
||||||
zone_keys, &nkeys);
|
zone_keys, &nkeys);
|
||||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
ATF_REQUIRE_EQ(nkeys, 2);
|
assert_int_equal(nkeys, 2);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Define the tests to be run. Note that changes to zone database
|
* Define the tests to be run. Note that changes to zone database
|
||||||
@@ -453,12 +441,26 @@ ATF_TC_BODY(updatesigs, tc) {
|
|||||||
}
|
}
|
||||||
dns_db_detach(&db);
|
dns_db_detach(&db);
|
||||||
dns_zone_detach(&zone);
|
dns_zone_detach(&zone);
|
||||||
|
|
||||||
dns_test_end();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ATF_TP_ADD_TCS(tp) {
|
int
|
||||||
ATF_TP_ADD_TC(tp, updatesigs);
|
main(void) {
|
||||||
|
const struct CMUnitTest tests[] = {
|
||||||
|
cmocka_unit_test_setup_teardown(updatesigs_next_test,
|
||||||
|
_setup, _teardown),
|
||||||
|
};
|
||||||
|
|
||||||
return (atf_no_error());
|
return (cmocka_run_group_tests(tests, NULL, NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else /* HAVE_CMOCKA */
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
main(void) {
|
||||||
|
printf("1..0 # Skipped: cmocka not available\n");
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
Reference in New Issue
Block a user