mirror of
https://github.com/NLnetLabs/unbound.git
synced 2026-09-13 13:27:43 +02:00
zonemd, loop over zone and canonicalize data, test call in unit test.
This commit is contained in:
+4
-4
@@ -517,8 +517,8 @@ del_tmp_file(char* fname)
|
||||
}
|
||||
|
||||
/** Add zone from file for testing */
|
||||
static struct auth_zone*
|
||||
addzone(struct auth_zones* az, const char* name, char* fname)
|
||||
struct auth_zone*
|
||||
authtest_addzone(struct auth_zones* az, const char* name, char* fname)
|
||||
{
|
||||
struct auth_zone* z;
|
||||
size_t nmlen;
|
||||
@@ -593,7 +593,7 @@ check_read_exact(const char* name, const char* zone)
|
||||
|
||||
az = auth_zones_create();
|
||||
unit_assert(az);
|
||||
z = addzone(az, name, fname);
|
||||
z = authtest_addzone(az, name, fname);
|
||||
unit_assert(z);
|
||||
outf = create_tmp_file(NULL);
|
||||
if(!auth_zone_write_file(z, outf)) {
|
||||
@@ -844,7 +844,7 @@ check_queries(const char* name, const char* zone, struct q_ans* queries)
|
||||
fname = create_tmp_file(zone);
|
||||
az = auth_zones_create();
|
||||
if(!az) fatal_exit("out of memory");
|
||||
z = addzone(az, name, fname);
|
||||
z = authtest_addzone(az, name, fname);
|
||||
if(!z) fatal_exit("could not read zone for queries test");
|
||||
del_tmp_file(fname);
|
||||
|
||||
|
||||
@@ -839,6 +839,52 @@ static void respip_test(void)
|
||||
respip_conf_actions_test();
|
||||
}
|
||||
|
||||
#include "services/authzone.h"
|
||||
#include "util/data/dname.h"
|
||||
#include "util/regional.h"
|
||||
/** Add zone from file for testing */
|
||||
struct auth_zone* authtest_addzone(struct auth_zones* az, const char* name,
|
||||
char* fname);
|
||||
/** zonemd unit tests */
|
||||
static void zonemd_test(void)
|
||||
{
|
||||
uint8_t zonemd_hash[512];
|
||||
struct auth_zones* az;
|
||||
struct auth_zone* z;
|
||||
int scheme = 1, hashalgo = 2;
|
||||
size_t hashlen = 0;
|
||||
int result;
|
||||
char* reason = NULL;
|
||||
struct regional* region = NULL;
|
||||
struct sldns_buffer* buf = NULL;
|
||||
unit_show_feature("zonemd");
|
||||
region = regional_create();
|
||||
unit_assert(region);
|
||||
buf = sldns_buffer_new(65535);
|
||||
unit_assert(buf);
|
||||
az = auth_zones_create();
|
||||
unit_assert(az);
|
||||
z = authtest_addzone(az, "example.org", "testdata/zonemd.example1.zone");
|
||||
unit_assert(z);
|
||||
|
||||
/* zonemd test on zone */
|
||||
result = auth_zone_generate_zonemd_hash(z, scheme, hashalgo,
|
||||
zonemd_hash, sizeof(zonemd_hash), &hashlen, region, buf,
|
||||
&reason);
|
||||
if(reason) printf("zonemd failure reason: %s\n", reason);
|
||||
unit_assert(result);
|
||||
if(1) {
|
||||
char zname[255+1];
|
||||
dname_str(z->name, zname);
|
||||
printf("zonemd generated for %s in %s with scheme=%d, hashalgo=%d\n", zname, z->zonefile, scheme, hashalgo);
|
||||
log_hex("digest", zonemd_hash, hashlen);
|
||||
}
|
||||
|
||||
auth_zones_delete(az);
|
||||
regional_destroy(region);
|
||||
sldns_buffer_free(buf);
|
||||
}
|
||||
|
||||
void unit_show_func(const char* file, const char* func)
|
||||
{
|
||||
printf("test %s:%s\n", file, func);
|
||||
@@ -889,6 +935,7 @@ main(int argc, char* argv[])
|
||||
fatal_exit("could not init NSS");
|
||||
#endif /* HAVE_SSL or HAVE_NSS*/
|
||||
checklock_start();
|
||||
zonemd_test();
|
||||
authzone_test();
|
||||
neg_test();
|
||||
rnd_test();
|
||||
|
||||
Reference in New Issue
Block a user