fix(forward): make dnstap FORWARDER_* describe the socket from CoreDNS to upstream (#8184)

Signed-off-by: Jaime Hablutzel <hablutzel1@gmail.com>
This commit is contained in:
Jaime Hablutzel
2026-07-01 23:04:04 -05:00
committed by GitHub
parent 6e7093cafb
commit 8d94712f99
5 changed files with 138 additions and 44 deletions

View File

@@ -1,8 +1,18 @@
package proxy
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/coredns/coredns/plugin/pkg/doh"
"github.com/coredns/coredns/plugin/pkg/transport"
"github.com/coredns/coredns/plugin/test"
"github.com/coredns/coredns/request"
"github.com/miekg/dns"
)
const (
@@ -49,3 +59,50 @@ func TestDial_MultipleCallsAfterStop(t *testing.T) {
}
}
}
// TestConnectHTTPSReportsTCP verifies that Connect reports the transport it
// actually used to reach the upstream. For an HTTPS upstream that is always
// "tcp", even when the downstream client connected over UDP.
func TestConnectHTTPSReportsTCP(t *testing.T) {
s := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
msg, err := doh.RequestToMsg(r)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
ret := new(dns.Msg)
reply := ret.SetReply(msg)
reply.Answer = append(reply.Answer, test.A("example.org. IN A 127.0.0.1"))
buf, err := reply.Pack()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", doh.MimeType)
w.Write(buf)
}))
defer s.Close()
p := NewProxy("TestConnectHTTPSReportsTCP", s.URL, transport.HTTPS)
p.SetHTTPClient(s.Client())
m := new(dns.Msg)
m.SetQuestion("example.org.", dns.TypeA)
// The downstream client connected over UDP.
req := request.Request{W: &test.ResponseWriter{TCP: false}, Req: m}
resp, _, proto, err := p.Connect(context.Background(), req, Options{})
if err != nil {
t.Fatalf("Connect failed: %v", err)
}
if resp == nil {
t.Fatal("Expected response, got nil")
}
if proto != "tcp" {
t.Errorf("HTTPS upstream with a UDP downstream client: expected reported proto %q, got %q", "tcp", proto)
}
}