mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 10:13:14 -04:00 
			
		
		
		
	do not log NOERROR in log plugin when response is not available (#4725)
Signed-off-by: Ondrej Benkovsky <ondrej.benkovsky@wandera.com>
This commit is contained in:
		| @@ -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 != "" { | ||||
|   | ||||
| @@ -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) | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user