]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
auth zone test checks stored axfr zonefile
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Thu, 1 Feb 2018 13:29:31 +0000 (13:29 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Thu, 1 Feb 2018 13:29:31 +0000 (13:29 +0000)
git-svn-id: file:///svn/unbound/trunk@4486 be551aaa-1e26-0410-a405-d3ace91eadb9

services/authzone.c
testcode/fake_event.c
testcode/replay.c
testcode/replay.h
testdata/auth_xfr.rpl

index d41f765879f437a781c416f308b58338c5b03756..0e0e74ef69a8349b7b53ed87b3eeff4dbf33ffde 100644 (file)
@@ -1390,9 +1390,6 @@ az_insert_rr_decompress(struct auth_zone* z, uint8_t* pkt, size_t pktlen,
        }
        rr = sldns_buffer_begin(scratch_buffer);
        rr_len = sldns_buffer_limit(scratch_buffer);
-       char buf[512];
-       (void)sldns_wire2str_rr_buf(rr, rr_len, buf, sizeof(buf));
-       log_info("decompress is %s", buf);
        dname_len = dname_valid(rr, rr_len);
        return az_insert_rr(z, rr, rr_len, dname_len, duplicate);
 }
@@ -1685,8 +1682,8 @@ xfr_find_soa(struct auth_zone* z, struct auth_xfer* xfr)
        d = soa->data;
        xfr->have_zone = 1;
        xfr->serial = sldns_read_uint32(d->rr_data[0]+(d->rr_len[0]-20));
-       xfr->retry = sldns_read_uint32(d->rr_data[0]+(d->rr_len[0]-16));
-       xfr->refresh = sldns_read_uint32(d->rr_data[0]+(d->rr_len[0]-12));
+       xfr->refresh = sldns_read_uint32(d->rr_data[0]+(d->rr_len[0]-16));
+       xfr->retry = sldns_read_uint32(d->rr_data[0]+(d->rr_len[0]-12));
        xfr->expiry = sldns_read_uint32(d->rr_data[0]+(d->rr_len[0]-8));
        /* soa minimum at d->rr_len[0]-4 */
        return 1;
@@ -3974,6 +3971,12 @@ xfr_process_chunk_list(struct auth_xfer* xfr, struct module_env* env,
        /* unlock */
        lock_rw_unlock(&z->lock);
 
+       if(verbosity >= VERB_QUERY && xfr->have_zone) {
+               char zname[256];
+               dname_str(xfr->name, zname);
+               verbose(VERB_QUERY, "auth zone %s updated to serial %u", zname,
+                       (unsigned)xfr->serial);
+       }
        /* see if we need to write to a zonefile */
        xfr_write_after_update(xfr, env);
        return 1;
index 016d2d8ad6fd064339917cd9e463ad8a9320f859..034f3ee56b59f6d04c0847c0ba61b65d1f0b3d05 100644 (file)
@@ -158,6 +158,7 @@ repevt_string(enum replay_event_type t)
        case repevt_back_reply:  return "REPLY";
        case repevt_back_query:  return "CHECK_OUT_QUERY";
        case repevt_autotrust_check: return "CHECK_AUTOTRUST";
+       case repevt_tempfile_check: return "CHECK_TEMPFILE";
        case repevt_error:       return "ERROR";
        case repevt_assign:      return "ASSIGN";
        case repevt_traffic:     return "TRAFFIC";
@@ -611,6 +612,59 @@ autotrust_check(struct replay_runtime* runtime, struct replay_moment* mom)
        log_info("autotrust %s is OK", mom->autotrust_id);
 }
 
+/** check tempfile file contents */
+static void
+tempfile_check(struct replay_runtime* runtime, struct replay_moment* mom)
+{
+       char name[1024], line[1024];
+       FILE *in;
+       int lineno = 0, oke=1;
+       char* expanded;
+       struct config_strlist* p;
+       line[sizeof(line)-1] = 0;
+       log_assert(mom->autotrust_id);
+       fake_temp_file("_temp_", mom->autotrust_id, name, sizeof(name));
+       in = fopen(name, "r");
+       if(!in) fatal_exit("could not open %s: %s", name, strerror(errno));
+       for(p=mom->file_content; p; p=p->next) {
+               lineno++;
+               if(!fgets(line, (int)sizeof(line)-1, in)) {
+                       log_err("tempfile check failed, could not read line");
+                       log_err("file %s, line %d", name, lineno);
+                       log_err("should be: %s", p->str);
+                       fatal_exit("tempfile_check failed");
+               }
+               if(line[0]) line[strlen(line)-1] = 0; /* remove newline */
+               expanded = macro_process(runtime->vars, runtime, p->str);
+               if(!expanded) 
+                       fatal_exit("could not expand macro line %d", lineno);
+               if(verbosity >= 7 && strcmp(p->str, expanded) != 0)
+                       log_info("expanded '%s' to '%s'", p->str, expanded);
+               if(strcmp(expanded, line) != 0) {
+                       log_err("mismatch in file %s, line %d", name, lineno);
+                       log_err("file has : %s", line);
+                       log_err("should be: %s", expanded);
+                       free(expanded);
+                       oke = 0;
+                       continue;
+               }
+               free(expanded);
+               fprintf(stderr, "%s:%2d ok : %s\n", name, lineno, line);
+       }
+       if(fgets(line, (int)sizeof(line)-1, in)) {
+               log_err("tempfile check failed, extra lines in %s after %d",
+                       name, lineno);
+               do {
+                       fprintf(stderr, "file has: %s", line);
+               } while(fgets(line, (int)sizeof(line)-1, in));
+               oke = 0;
+       }
+       fclose(in);
+       if(!oke)
+               fatal_exit("tempfile_check STEP %d failed", mom->time_step);
+       log_info("tempfile %s is OK", mom->autotrust_id);
+}
+
 /** Store RTT in infra cache */
 static void
 do_infra_rtt(struct replay_runtime* runtime)
@@ -720,6 +774,10 @@ do_moment_and_advance(struct replay_runtime* runtime)
                autotrust_check(runtime, runtime->now);
                advance_moment(runtime);
                break;
+       case repevt_tempfile_check:
+               tempfile_check(runtime, runtime->now);
+               advance_moment(runtime);
+               break;
        case repevt_assign:
                moment_assign(runtime, runtime->now);
                advance_moment(runtime);
index 085c314759fdfce287ce41355a67f360f979db85..08d87470bd0067c63562a2fcaba54737cfc9a461 100644 (file)
@@ -323,6 +323,15 @@ replay_moment_read(char* remain, FILE* in, const char* name,
                mom->autotrust_id = strdup(remain);
                if(!mom->autotrust_id) fatal_exit("out of memory");
                read_file_content(in, &pstate->lineno, mom);
+       } else if(parse_keyword(&remain, "CHECK_TEMPFILE")) {
+               mom->evt_type = repevt_tempfile_check;
+               while(isspace((unsigned char)*remain))
+                       remain++;
+               if(strlen(remain)>0 && remain[strlen(remain)-1]=='\n')
+                       remain[strlen(remain)-1] = 0;
+               mom->autotrust_id = strdup(remain);
+               if(!mom->autotrust_id) fatal_exit("out of memory");
+               read_file_content(in, &pstate->lineno, mom);
        } else if(parse_keyword(&remain, "ERROR")) {
                mom->evt_type = repevt_error;
        } else if(parse_keyword(&remain, "TRAFFIC")) {
index d77ee0275e9260558ecc90a3cf9500bb3d374c3b..81f0a2c275b22454e6a50ca40b8c59510fe2e07a 100644 (file)
@@ -83,6 +83,7 @@
  *             the step waits for traffic to stop.
  *      o CHECK_AUTOTRUST [id] - followed by FILE_BEGIN [to match] FILE_END.
  *             The file contents is macro expanded before match.
+ *      o CHECK_TEMPFILE [fname] - followed by FILE_BEGIN [to match] FILE_END
  *      o INFRA_RTT [ip] [dp] [rtt] - update infra cache entry with rtt.
  *      o ERROR
  * ; following entry starts on the next line, ENTRY_BEGIN.
@@ -203,6 +204,8 @@ struct replay_moment {
                repevt_back_query,
                /** check autotrust key file */
                repevt_autotrust_check,
+               /** check a temp file */
+               repevt_tempfile_check,
                /** an error happens to outbound query */
                repevt_error,
                /** assignment to a variable */
index b1610202c71c7cb70e5839e0579d33e1ab7b2288..effa5c5ff90a510c38df99eeabc3e7a47d3cc6e7 100644 (file)
@@ -203,4 +203,30 @@ ENTRY_END
 STEP 30 TIME_PASSES ELAPSE 10
 STEP 40 TRAFFIC
 
+STEP 50 QUERY
+ENTRY_BEGIN
+REPLY RD
+SECTION QUESTION
+www.example.com. IN A
+ENTRY_END
+
+; recursion happens here.
+STEP 60 CHECK_ANSWER
+ENTRY_BEGIN
+MATCH all
+REPLY QR AA RD RA NOERROR
+SECTION QUESTION
+www.example.com. IN A
+SECTION ANSWER
+www.example.com. IN A  1.2.3.4
+ENTRY_END
+
+; the zonefile was updated with new contents
+STEP 70 CHECK_TEMPFILE example.com
+FILE_BEGIN
+example.com.   3600    IN      SOA     ns.example.com. hostmaster.example.com. 1 3600 900 86400 3600
+example.com.   3600    IN      NS      ns.example.net.
+www.example.com.       3600    IN      A       1.2.3.4
+FILE_END
+
 SCENARIO_END