mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-08-10 13:20:33 +02:00
Not send client info with non-Control D upstream by default
This commit is contained in:
@@ -248,11 +248,8 @@ func (uc *UpstreamConfig) VerifyDomain() string {
|
|||||||
// - Lan IP
|
// - Lan IP
|
||||||
// - Hostname
|
// - Hostname
|
||||||
func (uc *UpstreamConfig) UpstreamSendClientInfo() bool {
|
func (uc *UpstreamConfig) UpstreamSendClientInfo() bool {
|
||||||
if uc.SendClientInfo != nil && !(*uc.SendClientInfo) {
|
if uc.SendClientInfo != nil {
|
||||||
return false
|
return *uc.SendClientInfo
|
||||||
}
|
|
||||||
if uc.SendClientInfo == nil {
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
switch uc.Type {
|
switch uc.Type {
|
||||||
case ResolverTypeDOH, ResolverTypeDOH3:
|
case ResolverTypeDOH, ResolverTypeDOH3:
|
||||||
|
|||||||
@@ -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 {
|
func ptrBool(b bool) *bool {
|
||||||
return &b
|
return &b
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user