mirror of
https://github.com/NLnetLabs/unbound.git
synced 2026-09-11 04:17:42 +02:00
unit test for auth zone lookup
git-svn-id: file:///svn/unbound/trunk@4469 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
@@ -49,6 +49,14 @@
|
||||
* AUTOTRUST_FILE id
|
||||
* ; contents of that file
|
||||
* AUTOTRUST_END
|
||||
* ; temp file names are echoed as "tmp/xxx.fname"
|
||||
* TEMPFILE_NAME fname
|
||||
* ; temp file contents, inline, deleted at end of run
|
||||
* TEMPFILE_CONTENTS fname
|
||||
* ; contents of that file
|
||||
* ; this creates $INCLUDE /tmp/xxx.fname
|
||||
* $INCLUDE_TEMPFILE fname
|
||||
* TEMPFILE_END
|
||||
* CONFIG_END
|
||||
* ; comment line.
|
||||
* SCENARIO_BEGIN name_of_scenario
|
||||
|
||||
@@ -135,6 +135,65 @@ echo_cmdline(int argc, char* argv[])
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
/** spool temp file name */
|
||||
static void
|
||||
spool_temp_file_name(int* lineno, FILE* cfg, char* id)
|
||||
{
|
||||
char line[MAX_LINE_LEN];
|
||||
/* find filename for new file */
|
||||
while(isspace((unsigned char)*id))
|
||||
id++;
|
||||
if(*id == '\0')
|
||||
fatal_exit("TEMPFILE_NAME must have id, line %d", *lineno);
|
||||
id[strlen(id)-1]=0; /* remove newline */
|
||||
fake_temp_file("_temp_", id, line, sizeof(line));
|
||||
fprintf(cfg, "\"%s\"\n", line);
|
||||
}
|
||||
|
||||
/** spool temp file */
|
||||
static void
|
||||
spool_temp_file(FILE* in, int* lineno, char* id)
|
||||
{
|
||||
char line[MAX_LINE_LEN];
|
||||
char* parse;
|
||||
FILE* spool;
|
||||
/* find filename for new file */
|
||||
while(isspace((unsigned char)*id))
|
||||
id++;
|
||||
if(*id == '\0')
|
||||
fatal_exit("TEMPFILE_CONTENTS must have id, line %d", *lineno);
|
||||
id[strlen(id)-1]=0; /* remove newline */
|
||||
fake_temp_file("_temp_", id, line, sizeof(line));
|
||||
/* open file and spool to it */
|
||||
spool = fopen(line, "w");
|
||||
if(!spool) fatal_exit("could not open %s: %s", line, strerror(errno));
|
||||
fprintf(stderr, "testbound is spooling temp file: %s\n", line);
|
||||
if(!cfg_strlist_insert(&cfgfiles, strdup(line)))
|
||||
fatal_exit("out of memory");
|
||||
line[sizeof(line)-1] = 0;
|
||||
while(fgets(line, MAX_LINE_LEN-1, in)) {
|
||||
parse = line;
|
||||
(*lineno)++;
|
||||
while(isspace((unsigned char)*parse))
|
||||
parse++;
|
||||
if(strncmp(parse, "$INCLUDE_TEMPFILE", 17) == 0) {
|
||||
char l2[MAX_LINE_LEN];
|
||||
char* tid = parse+17;
|
||||
while(isspace((unsigned char)*tid))
|
||||
tid++;
|
||||
tid[strlen(tid)-1]=0; /* remove newline */
|
||||
fake_temp_file("_temp_", tid, l2, sizeof(l2));
|
||||
snprintf(line, sizeof(line), "$INCLUDE %s\n", l2);
|
||||
}
|
||||
if(strncmp(parse, "TEMPFILE_END", 12) == 0) {
|
||||
fclose(spool);
|
||||
return;
|
||||
}
|
||||
fputs(line, spool);
|
||||
}
|
||||
fatal_exit("no TEMPFILE_END in input file");
|
||||
}
|
||||
|
||||
/** spool autotrust file */
|
||||
static void
|
||||
spool_auto_file(FILE* in, int* lineno, FILE* cfg, char* id)
|
||||
@@ -213,6 +272,14 @@ setup_config(FILE* in, int* lineno, int* pass_argc, char* pass_argv[])
|
||||
spool_auto_file(in, lineno, cfg, parse+14);
|
||||
continue;
|
||||
}
|
||||
if(strncmp(parse, "TEMPFILE_NAME", 13) == 0) {
|
||||
spool_temp_file_name(lineno, cfg, parse+13);
|
||||
continue;
|
||||
}
|
||||
if(strncmp(parse, "TEMPFILE_CONTENTS", 17) == 0) {
|
||||
spool_temp_file(in, lineno, parse+17);
|
||||
continue;
|
||||
}
|
||||
if(strncmp(parse, "CONFIG_END", 10) == 0) {
|
||||
fclose(cfg);
|
||||
return;
|
||||
|
||||
+7
-2
@@ -521,6 +521,7 @@ addzone(struct auth_zones* az, const char* name, char* fname)
|
||||
lock_rw_unlock(&az->lock);
|
||||
if(!z) fatal_exit("cannot find zone");
|
||||
auth_zone_set_zonefile(z, fname);
|
||||
z->for_upstream = 1;
|
||||
|
||||
if(!auth_zone_read_zonefile(z)) {
|
||||
fatal_exit("parse failure for auth zone %s", name);
|
||||
@@ -685,8 +686,12 @@ msgtostr(struct dns_msg* msg)
|
||||
char* str;
|
||||
sldns_buffer* buf = sldns_buffer_new(65535);
|
||||
if(!buf) fatal_exit("out of memory");
|
||||
pr_flags(buf, msg->rep->flags);
|
||||
pr_rrs(buf, msg->rep);
|
||||
if(!msg) {
|
||||
sldns_buffer_printf(buf, "null packet\n");
|
||||
} else {
|
||||
pr_flags(buf, msg->rep->flags);
|
||||
pr_rrs(buf, msg->rep);
|
||||
}
|
||||
|
||||
str = strdup((char*)sldns_buffer_begin(buf));
|
||||
if(!str) fatal_exit("out of memory");
|
||||
|
||||
Reference in New Issue
Block a user