Not send client info with non-Control D upstream by default

This commit is contained in:
Cuong Manh Le
2023-06-22 22:33:51 +07:00
committed by Cuong Manh Le
parent 12148ec231
commit 2f46d512c6
2 changed files with 57 additions and 5 deletions

View File

@@ -248,11 +248,8 @@ func (uc *UpstreamConfig) VerifyDomain() string {
// - Lan IP
// - Hostname
func (uc *UpstreamConfig) UpstreamSendClientInfo() bool {
if uc.SendClientInfo != nil && !(*uc.SendClientInfo) {
return false
}
if uc.SendClientInfo == nil {
return true
if uc.SendClientInfo != nil {
return *uc.SendClientInfo
}
switch uc.Type {
case ResolverTypeDOH, ResolverTypeDOH3:

View File

@@ -223,6 +223,61 @@ func TestUpstreamConfig_VerifyDomain(t *testing.T) {
})
}
}
func TestUpstreamConfig_UpstreamSendClientInfo(t *testing.T) {
tests := []struct {
name string
uc *UpstreamConfig
sendClientInfo bool
}{
{
"default with controld upstream DoH",
&UpstreamConfig{Endpoint: "https://freedns.controld.com/p2", Type: ResolverTypeDOH},
true,
},
{
"default with controld upstream DoH3",
&UpstreamConfig{Endpoint: "https://freedns.controld.com/p2", Type: ResolverTypeDOH3},
true,
},
{
"default with non-ControlD upstream",
&UpstreamConfig{Endpoint: "https://dns.google/dns-query", Type: ResolverTypeDOH},
false,
},
{
"set false with controld upstream",
&UpstreamConfig{Endpoint: "https://freedns.controld.com/p2", Type: ResolverTypeDOH, SendClientInfo: ptrBool(false)},
false,
},
{
"set true with controld upstream",
&UpstreamConfig{Endpoint: "https://freedns.controld.com/p2", SendClientInfo: ptrBool(true)},
true,
},
{
"set false with non-ControlD upstream",
&UpstreamConfig{Endpoint: "https://dns.google/dns-query", SendClientInfo: ptrBool(false)},
false,
},
{
"set true with non-ControlD upstream",
&UpstreamConfig{Endpoint: "https://dns.google/dns-query", Type: ResolverTypeDOH, SendClientInfo: ptrBool(true)},
true,
},
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
if got := tc.uc.UpstreamSendClientInfo(); got != tc.sendClientInfo {
t.Errorf("unexpected result, want: %v, got: %v", tc.sendClientInfo, got)
}
})
}
}
func ptrBool(b bool) *bool {
return &b
}