add doh support

This commit is contained in:
iceBear67
2026-07-26 14:14:03 +08:00
parent 20097a02a1
commit 5dc1759d80
9 changed files with 335 additions and 32 deletions
+24
View File
@@ -51,6 +51,7 @@ func TestConfigValidateAcceptsValidConfig(t *testing.T) {
cfg := Config{
Core: Core{AuthKey: "tskey-auth-example"},
DNS: DNS{DoHServers: []string{"https://cloudflare-dns.com/dns-query"}},
Forward: map[string][]ForwardRule{
"web": {
{Protocol: "tcp", TailscalePort: 8080, LocalAddr: "127.0.0.1:9090"},
@@ -106,6 +107,29 @@ func TestConfigValidateRejectsInvalidConfig(t *testing.T) {
}
}
func TestConfigValidateRejectsInvalidDoHServer(t *testing.T) {
t.Parallel()
cfg := Config{
Core: Core{AuthKey: "tskey-auth-example"},
DNS: DNS{DoHServers: []string{"https://ok.example/dns-query", "not a url", "ftp://wrong.example"}},
}
err := cfg.Validate()
if err == nil {
t.Fatal("Validate() returned nil, want error")
}
for _, want := range []string{
"dns.doh_servers[1] must be a valid http(s) URL",
"dns.doh_servers[2] must be a valid http(s) URL",
} {
if !strings.Contains(err.Error(), want) {
t.Fatalf("Validate() error %q does not contain %q", err.Error(), want)
}
}
}
func boolPtr(v bool) *bool {
return &v
}