mirror of
https://github.com/coredns/coredns.git
synced 2026-10-09 03:55:21 -04:00
plugin/forward: support DNS-over-QUIC upstreams (#8474)
Signed-off-by: houyuwushang <liuluoqianqiu@outlook.com>
This commit is contained in:
@@ -3,6 +3,7 @@ package forward
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -171,6 +172,9 @@ func TestParseAsHostEntry(t *testing.T) {
|
||||
{"tls://dns.example.com", true, "dns.example.com", "853", transport.TLS, ""},
|
||||
{"tls://dns.example.com:8853", true, "dns.example.com", "8853", transport.TLS, ""},
|
||||
{"tls://dns.example.com%servername.example.com", true, "dns.example.com", "853", transport.TLS, "servername.example.com"},
|
||||
{"quic://dns.example.com", true, "dns.example.com", "853", transport.QUIC, ""},
|
||||
{"quic://dns.example.com:8853", true, "dns.example.com", "8853", transport.QUIC, ""},
|
||||
{"quic://dns.example.com%servername.example.com", true, "dns.example.com", "853", transport.QUIC, "servername.example.com"},
|
||||
{"https://dns.example.com", true, "dns.example.com", "443", transport.HTTPS, ""},
|
||||
{"https://dns.example.com:8443", true, "dns.example.com", "8443", transport.HTTPS, ""},
|
||||
{"https://dns.example.com%servername.example.com", true, "dns.example.com", "443", transport.HTTPS, "servername.example.com"},
|
||||
@@ -217,11 +221,15 @@ func TestFormatResolvedAddr(t *testing.T) {
|
||||
{"10.0.0.1", "53", transport.DNS, "", "10.0.0.1:53"},
|
||||
{"10.0.0.1", "853", transport.TLS, "", "tls://10.0.0.1:853"},
|
||||
{"10.0.0.1", "853", transport.TLS, "example.com", "tls://10.0.0.1%example.com:853"},
|
||||
{"10.0.0.1", "853", transport.QUIC, "", "quic://10.0.0.1:853"},
|
||||
{"10.0.0.1", "853", transport.QUIC, "example.com", "quic://10.0.0.1%example.com:853"},
|
||||
{"10.0.0.1", "443", transport.HTTPS, "", "https://10.0.0.1:443"},
|
||||
{"10.0.0.1", "443", transport.HTTPS, "example.com", "https://10.0.0.1%example.com:443"},
|
||||
{"::1", "53", transport.DNS, "", "[::1]:53"},
|
||||
{"::1", "853", transport.TLS, "", "tls://[::1]:853"},
|
||||
{"::1", "853", transport.TLS, "example.com", "tls://[::1%example.com]:853"},
|
||||
{"::1", "853", transport.QUIC, "", "quic://[::1]:853"},
|
||||
{"::1", "853", transport.QUIC, "example.com", "quic://[::1%example.com]:853"},
|
||||
{"::1", "443", transport.HTTPS, "", "https://[::1]:443"},
|
||||
{"::1", "443", transport.HTTPS, "example.com", "https://[::1%example.com]:443"},
|
||||
}
|
||||
@@ -610,6 +618,30 @@ func TestExpandAndDedupTLS(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestExpandAndDedupKeepsDistinctDoTAndDoQEndpoints(t *testing.T) {
|
||||
entries := []toEntry{
|
||||
{static: true, addrs: []string{"tls://192.0.2.1:853"}},
|
||||
{static: true, addrs: []string{"quic://192.0.2.1:853"}},
|
||||
{static: true, addrs: []string{"quic://192.0.2.1%doq.example:853"}},
|
||||
{static: true, addrs: []string{"quic://192.0.2.1%DOQ.EXAMPLE:853"}},
|
||||
{static: true, addrs: []string{"dns://192.0.2.2:53", "192.0.2.2:53"}},
|
||||
}
|
||||
|
||||
result, err := expandAndDedup(entries, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("expandAndDedup() failed: %v", err)
|
||||
}
|
||||
want := []string{
|
||||
"tls://192.0.2.1:853",
|
||||
"quic://192.0.2.1:853",
|
||||
"quic://192.0.2.1%doq.example:853",
|
||||
"dns://192.0.2.2:53",
|
||||
}
|
||||
if !reflect.DeepEqual(result, want) {
|
||||
t.Fatalf("expandAndDedup() = %v, want %v", result, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolverWithHCOptions(t *testing.T) {
|
||||
input := "forward . 127.0.0.1 {\nresolver 10.96.0.10\n}\n"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user