aboutsummaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorGravatar Ondřej Benkovský <ondrej.benkovsky@wandera.com> 2021-07-09 13:15:34 +0200
committerGravatar GitHub <noreply@github.com> 2021-07-09 13:15:34 +0200
commita6a7e738136cf09950dcdf880fe12ea9e14e3afc (patch)
tree5d9c7a255c00a8043c790b2e5cacb2df434d1c20 /plugin
parent002b748ccd6b7cc2e3a65f1bd71509f80b95d342 (diff)
downloadcoredns-a6a7e738136cf09950dcdf880fe12ea9e14e3afc.tar.gz
coredns-a6a7e738136cf09950dcdf880fe12ea9e14e3afc.tar.zst
coredns-a6a7e738136cf09950dcdf880fe12ea9e14e3afc.zip
do not log NOERROR in log plugin when response is not available (#4725)
Signed-off-by: Ondrej Benkovsky <ondrej.benkovsky@wandera.com>
Diffstat (limited to 'plugin')
-rw-r--r--plugin/pkg/replacer/replacer.go2
-rw-r--r--plugin/pkg/replacer/replacer_test.go49
2 files changed, 50 insertions, 1 deletions
diff --git a/plugin/pkg/replacer/replacer.go b/plugin/pkg/replacer/replacer.go
index 81261ca79..845f11bc3 100644
--- a/plugin/pkg/replacer/replacer.go
+++ b/plugin/pkg/replacer/replacer.go
@@ -86,7 +86,7 @@ func appendValue(b []byte, state request.Request, rr *dnstest.Recorder, label st
return strconv.AppendInt(b, int64(state.Size()), 10)
// Recorded replacements.
case "{rcode}":
- if rr == nil {
+ if rr == nil || rr.Msg == nil {
return append(b, EmptyValue...)
}
if rcode := dns.RcodeToString[rr.Rcode]; rcode != "" {
diff --git a/plugin/pkg/replacer/replacer_test.go b/plugin/pkg/replacer/replacer_test.go
index 3e0a50691..25dd37a5b 100644
--- a/plugin/pkg/replacer/replacer_test.go
+++ b/plugin/pkg/replacer/replacer_test.go
@@ -393,3 +393,52 @@ func TestMetadataMalformed(t *testing.T) {
}
}
}
+
+func TestNoResponseWasWritten(t *testing.T) {
+ w := dnstest.NewRecorder(&test.ResponseWriter{})
+ r := new(dns.Msg)
+ r.SetQuestion("example.org.", dns.TypeHINFO)
+ r.Id = 1053
+ r.AuthenticatedData = true
+ r.CheckingDisabled = true
+ state := request.Request{W: w, Req: r}
+
+ replacer := New()
+ ctx := context.TODO()
+
+ // This couples the test very tightly to the code, but so be it.
+ expect := map[string]string{
+ "{type}": "HINFO",
+ "{name}": "example.org.",
+ "{class}": "IN",
+ "{proto}": "udp",
+ "{size}": "29",
+ "{remote}": "10.240.0.1",
+ "{port}": "40212",
+ "{local}": "127.0.0.1",
+ headerReplacer + "id}": "1053",
+ headerReplacer + "opcode}": "0",
+ headerReplacer + "do}": "false",
+ headerReplacer + "bufsize}": "512",
+ "{rcode}": "-",
+ "{rsize}": "0",
+ "{duration}": "0",
+ headerReplacer + "rflags}": "-",
+ }
+ if len(expect) != len(labels) {
+ t.Fatalf("Expect %d labels, got %d", len(expect), len(labels))
+ }
+
+ for lbl := range labels {
+ repl := replacer.Replace(ctx, state, w, lbl)
+ if lbl == "{duration}" {
+ if repl[len(repl)-1] != 's' {
+ t.Errorf("Expected seconds, got %q", repl)
+ }
+ continue
+ }
+ if repl != expect[lbl] {
+ t.Errorf("Expected value %q, got %q", expect[lbl], repl)
+ }
+ }
+}