mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-30 05:57:52 +00:00
convert sigs_test
This commit is contained in:
parent
b915cdbf0b
commit
eda6281f98
@ -9,15 +9,22 @@
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
|
||||
#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 <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <dns/db.h>
|
||||
#include <dns/diff.h>
|
||||
@ -44,6 +51,27 @@
|
||||
|
||||
#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
|
||||
* prepared by dns__zone_updatesigs().
|
||||
@ -72,7 +100,7 @@ typedef struct {
|
||||
*/
|
||||
static void
|
||||
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_type[DNS_RDATATYPE_FORMATSIZE] = { };
|
||||
@ -92,33 +120,21 @@ compare_tuples(const zonediff_t *expected, dns_difftuple_t *found,
|
||||
/*
|
||||
* Check operation.
|
||||
*/
|
||||
ATF_CHECK_EQ_MSG(expected->op, found->op,
|
||||
"test \"%s\": tuple %zu: "
|
||||
"expected op %d, found %d",
|
||||
test->description, index,
|
||||
expected->op, found->op);
|
||||
assert_int_equal(expected->op, found->op);
|
||||
|
||||
/*
|
||||
* Check owner name.
|
||||
*/
|
||||
expected_name = dns_fixedname_initname(&expected_fname);
|
||||
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));
|
||||
ATF_CHECK_MSG(dns_name_equal(expected_name, &found->name),
|
||||
"test \"%s\": tuple %zu: "
|
||||
"expected owner \"%s\", found \"%s\"",
|
||||
test->description, index,
|
||||
expected->owner, found_name);
|
||||
assert_true(dns_name_equal(expected_name, &found->name));
|
||||
|
||||
/*
|
||||
* Check TTL.
|
||||
*/
|
||||
ATF_CHECK_EQ_MSG(expected->ttl, found->ttl,
|
||||
"test \"%s\": tuple %zu: "
|
||||
"expected TTL %u, found %u",
|
||||
test->description, index,
|
||||
expected->ttl, found->ttl);
|
||||
assert_int_equal(expected->ttl, found->ttl);
|
||||
|
||||
/*
|
||||
* Parse expected RR type.
|
||||
@ -127,14 +143,14 @@ compare_tuples(const zonediff_t *expected, dns_difftuple_t *found,
|
||||
typeregion.length = strlen(expected->type);
|
||||
result = dns_rdatatype_fromtext(&expected_type,
|
||||
(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.
|
||||
*/
|
||||
isc_buffer_init(&typebuf, found_type, sizeof(found_type));
|
||||
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.
|
||||
@ -145,11 +161,7 @@ compare_tuples(const zonediff_t *expected, dns_difftuple_t *found,
|
||||
/*
|
||||
* Found tuple must be of type RRSIG.
|
||||
*/
|
||||
ATF_CHECK_EQ_MSG(found->rdata.type, dns_rdatatype_rrsig,
|
||||
"test \"%s\": tuple %zu: "
|
||||
"expected type RRSIG, found %s",
|
||||
test->description, index,
|
||||
found_type);
|
||||
assert_int_equal(found->rdata.type, dns_rdatatype_rrsig);
|
||||
if (found->rdata.type != dns_rdatatype_rrsig) {
|
||||
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'.
|
||||
*/
|
||||
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));
|
||||
result = dns_rdatatype_totext(rrsig.covered, &typebuf);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_CHECK_EQ_MSG(expected_type, rrsig.covered,
|
||||
"test \"%s\": tuple %zu: "
|
||||
"expected RRSIG to cover %s, found covers %s",
|
||||
test->description, index,
|
||||
expected->type, found_covers);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(expected_type, rrsig.covered);
|
||||
break;
|
||||
default:
|
||||
/*
|
||||
* Found tuple must be of type 'expected->type'.
|
||||
*/
|
||||
ATF_CHECK_EQ_MSG(expected_type, found->rdata.type,
|
||||
"test \"%s\": tuple %zu: "
|
||||
"expected type %s, found %s",
|
||||
test->description, index,
|
||||
expected->type, found_type);
|
||||
assert_int_equal(expected_type, found->rdata.type);
|
||||
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.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
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
|
||||
@ -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,
|
||||
zone, now - 3600, now + 3600, 0, now,
|
||||
true, false, &zonediff);
|
||||
ATF_CHECK_EQ_MSG(result, ISC_R_SUCCESS,
|
||||
"test \"%s\": expected success, got %s",
|
||||
test->description, isc_result_totext(result));
|
||||
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);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_true(ISC_LIST_EMPTY(raw_diff.tuples));
|
||||
assert_false(ISC_LIST_EMPTY(zone_diff.tuples));
|
||||
|
||||
/*
|
||||
* Ensure that the number of tuples in the zone diff is as expected.
|
||||
*/
|
||||
|
||||
tuples_expected = 0;
|
||||
for (expected = test->zonediff;
|
||||
expected->owner != NULL;
|
||||
expected++)
|
||||
{
|
||||
for (expected = test->zonediff; expected->owner != NULL; expected++) {
|
||||
tuples_expected++;
|
||||
}
|
||||
|
||||
@ -269,11 +264,7 @@ updatesigs_test(const updatesigs_test_params_t *test, dns_zone_t *zone,
|
||||
tuples_found++;
|
||||
}
|
||||
|
||||
ATF_REQUIRE_EQ_MSG(tuples_expected, tuples_found,
|
||||
"test \"%s\": "
|
||||
"expected %zu tuples in output, found %zu",
|
||||
test->description,
|
||||
tuples_expected, tuples_found);
|
||||
assert_int_equal(tuples_expected, tuples_found);
|
||||
|
||||
/*
|
||||
* 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 = ISC_LIST_NEXT(found, link))
|
||||
{
|
||||
compare_tuples(expected, found, test, index);
|
||||
compare_tuples(expected, found, index);
|
||||
expected++;
|
||||
index++;
|
||||
}
|
||||
@ -297,11 +288,9 @@ updatesigs_test(const updatesigs_test_params_t *test, dns_zone_t *zone,
|
||||
dns_diff_clear(&raw_diff);
|
||||
}
|
||||
|
||||
ATF_TC(updatesigs);
|
||||
ATF_TC_HEAD(updatesigs, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dns__zone_updatesigs() tests");
|
||||
}
|
||||
ATF_TC_BODY(updatesigs, tc) {
|
||||
/* dns__zone_updatesigs() tests */
|
||||
static void
|
||||
updatesigs_next_test(void **state) {
|
||||
dst_key_t *zone_keys[DNS_MAXZONEKEYS];
|
||||
dns_zone_t *zone = NULL;
|
||||
dns_db_t *db = NULL;
|
||||
@ -310,28 +299,27 @@ ATF_TC_BODY(updatesigs, tc) {
|
||||
isc_stdtime_t now;
|
||||
size_t i;
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
/*
|
||||
* Prepare a zone along with its signing keys.
|
||||
*/
|
||||
|
||||
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",
|
||||
"testdata/master/master18.data");
|
||||
ATF_REQUIRE_EQ(result, DNS_R_SEENINCLUDE);
|
||||
assert_int_equal(result, DNS_R_SEENINCLUDE);
|
||||
|
||||
result = dns_zone_setkeydirectory(zone, "testkeys");
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
isc_stdtime_get(&now);
|
||||
result = dns__zone_findkeys(zone, db, NULL, now, mctx, DNS_MAXZONEKEYS,
|
||||
zone_keys, &nkeys);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(nkeys, 2);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(nkeys, 2);
|
||||
|
||||
/*
|
||||
* 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_zone_detach(&zone);
|
||||
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, updatesigs);
|
||||
int
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user