Files
coredns/core/dnsserver/quic_test.go
Nicholas Amorim 6b93363b94 feat(core): expose TLS ConnectionState (SNI) for DoQ (#8129)
DoQWriter previously stored only the QUIC stream, so plugins reading
TLS state via dns.ConnectionStater (e.g. for SNI-based routing or
auditing) could not see anything for DoQ connections, even
though the underlying QUIC connection carries a full tls.ConnectionState.

This change adds a *quic.Conn reference to DoQWriter and wires it in serveQUICStream.

It implements dns.ConnectionStater on *DoQWriter, returning the TLS
state from the underlying QUIC connection (mirrors the DoT behavior
that miekg/dns already provides for *tls.Conn)

Forwards ConnectionState through request.ScrubWriter, which wraps
every response writer before the plugin chain runs; the embedded
dns.ResponseWriter interface does not promote ConnectionState (it
belongs to a separate interface), so without this plugins would
still see nil for both DoQ and DoT

Signed-off-by: Nicholas Amorim <nicholas@santos.ee>
2026-05-28 15:45:48 -07:00

59 lines
1.4 KiB
Go

package dnsserver
import (
"net"
"testing"
)
func TestDoQWriterAddPrefix(t *testing.T) {
byteArray := []byte{0x1, 0x2, 0x3}
byteArrayWithPrefix := AddPrefix(byteArray)
if len(byteArrayWithPrefix) != 5 {
t.Error("Expected byte array with prefix to have length of 5")
}
size := int16(byteArrayWithPrefix[0])<<8 | int16(byteArrayWithPrefix[1])
if size != 3 {
t.Errorf("Expected prefixed size to be 3, got: %d", size)
}
}
func TestDoQWriter_ResponseWriterMethods(t *testing.T) {
localAddr := &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 1234}
remoteAddr := &net.UDPAddr{IP: net.ParseIP("8.8.8.8"), Port: 53}
writer := &DoQWriter{
localAddr: localAddr,
remoteAddr: remoteAddr,
}
if err := writer.TsigStatus(); err != nil {
t.Errorf("TsigStatus() returned an error: %v", err)
}
// this is a no-op, just call it
writer.TsigTimersOnly(true)
writer.TsigTimersOnly(false)
// this is a no-op, just call it
writer.Hijack()
if addr := writer.LocalAddr(); addr != localAddr {
t.Errorf("LocalAddr() = %v, want %v", addr, localAddr)
}
if addr := writer.RemoteAddr(); addr != remoteAddr {
t.Errorf("RemoteAddr() = %v, want %v", addr, remoteAddr)
}
}
func TestDoQWriter_ConnectionStateNilConn(t *testing.T) {
writer := &DoQWriter{}
if state := writer.ConnectionState(); state != nil {
t.Errorf("ConnectionState() = %v, want nil when conn is unset", state)
}
}