mirror of
https://github.com/coredns/coredns.git
synced 2026-07-13 19:20:10 -04:00
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:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user