Pull request 2006: 6182-fix-fallback-dns

Updates #6182.

Squashed commit of the following:

commit 7467bf851932a878af0eda01c140056a4261b597
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Fri Sep 8 17:29:44 2023 +0300

    dnsforward: imp test

commit b807123d6030012bf9e9a4a0e454983a2e012a96
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Fri Sep 8 17:22:49 2023 +0300

    dnsforward: add test

commit 698fc69e441e9f1e0e4c2878c81309967c058cab
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Fri Sep 8 16:50:39 2023 +0300

    dnsforward: fix more

commit 444ae2870cd78ef736df744d80438b4dae5133ce
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Fri Sep 8 16:32:49 2023 +0300

    all: upd chlog

commit 114ff58c7010528249f27bdc0b2f9bcc537f74c1
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Fri Sep 8 15:59:13 2023 +0300

    dnsforward: fix fallback dns
This commit is contained in:
Stanislav Chzhen 2023-09-08 17:37:28 +03:00
parent 5f696da9dc
commit 36517fc21b
5 changed files with 33 additions and 0 deletions

View File

@ -25,10 +25,12 @@ NOTE: Add new changes BELOW THIS COMMENT.
### Fixed ### Fixed
- Comments in the *Fallback DNS servers* field in the UI ([#6182]).
- Empty or default Safe Browsing and Parental Control settings ([#6181]). - Empty or default Safe Browsing and Parental Control settings ([#6181]).
- Various UI issues. - Various UI issues.
[#6181]: https://github.com/AdguardTeam/AdGuardHome/issues/6181 [#6181]: https://github.com/AdguardTeam/AdGuardHome/issues/6181
[#6182]: https://github.com/AdguardTeam/AdGuardHome/issues/6182
<!-- <!--
NOTE: Add new changes ABOVE THIS COMMENT. NOTE: Add new changes ABOVE THIS COMMENT.

View File

@ -614,6 +614,7 @@ func (s *Server) Prepare(conf *ServerConfig) (err error) {
// setupFallbackDNS initializes the fallback DNS servers. // setupFallbackDNS initializes the fallback DNS servers.
func (s *Server) setupFallbackDNS() (err error) { func (s *Server) setupFallbackDNS() (err error) {
fallbacks := s.conf.FallbackDNS fallbacks := s.conf.FallbackDNS
fallbacks = stringutil.FilterOut(fallbacks, IsCommentOrEmpty)
if len(fallbacks) == 0 { if len(fallbacks) == 0 {
return nil return nil
} }

View File

@ -372,6 +372,27 @@ func TestServer_timeout(t *testing.T) {
}) })
} }
func TestServer_Prepare_fallbacks(t *testing.T) {
srvConf := &ServerConfig{
Config: Config{
FallbackDNS: []string{
"#tls://1.1.1.1",
"8.8.8.8",
},
EDNSClientSubnet: &EDNSClientSubnet{Enabled: false},
},
}
s, err := NewServer(DNSCreateParams{})
require.NoError(t, err)
err = s.Prepare(srvConf)
require.NoError(t, err)
require.NotNil(t, s.dnsProxy.Fallbacks)
assert.Len(t, s.dnsProxy.Fallbacks.Upstreams, 1)
}
func TestServerWithProtectionDisabled(t *testing.T) { func TestServerWithProtectionDisabled(t *testing.T) {
s := createTestServer(t, &filtering.Config{ s := createTestServer(t, &filtering.Config{
BlockingMode: filtering.BlockingModeDefault, BlockingMode: filtering.BlockingModeDefault,

View File

@ -749,6 +749,7 @@ func (s *Server) handleTestUpstreamDNS(w http.ResponseWriter, r *http.Request) {
} }
req.Upstreams = stringutil.FilterOut(req.Upstreams, IsCommentOrEmpty) req.Upstreams = stringutil.FilterOut(req.Upstreams, IsCommentOrEmpty)
req.FallbackDNS = stringutil.FilterOut(req.FallbackDNS, IsCommentOrEmpty)
req.PrivateUpstreams = stringutil.FilterOut(req.PrivateUpstreams, IsCommentOrEmpty) req.PrivateUpstreams = stringutil.FilterOut(req.PrivateUpstreams, IsCommentOrEmpty)
upsNum := len(req.Upstreams) + len(req.FallbackDNS) + len(req.PrivateUpstreams) upsNum := len(req.Upstreams) + len(req.FallbackDNS) + len(req.PrivateUpstreams)

View File

@ -577,6 +577,14 @@ func TestServer_HandleTestUpstreamDNS(t *testing.T) {
badUps + ` over tcp: dns: id mismatch`, badUps + ` over tcp: dns: id mismatch`,
}, },
name: "fallback_broken", name: "fallback_broken",
}, {
body: map[string]any{
"fallback_dns": []string{goodUps, "#this.is.comment"},
},
wantResp: map[string]any{
goodUps: "OK",
},
name: "fallback_comment_mix",
}} }}
for _, tc := range testCases { for _, tc := range testCases {