code_before
stringlengths
16
1.81M
edits
stringlengths
4
328k
next_edit
stringlengths
0
76.5k
code_after
stringlengths
3
49.9M
label_window
sequencelengths
4
1.81k
instruction
stringlengths
20
51.9k
html_url
stringlengths
74
116
file_name
stringlengths
3
311
s.conf = tc.conf() s.handleGetConfig(w, nil) assert.Equal(t, "application/json", w.Header().Get("Content-Type")) assert.JSONEq(t, string(caseWant), w.Body.String()) }) } }
</s> remove if err != http.ErrServerClosed { </s> add if !errors.Is(err, http.ErrServerClosed) { </s> remove log.Fatal(err) </s> add log.Fatalf("web: https: %s", err) </s> remove if err != nil { const msgFmt = "shutting down http server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) } </s> add if err == nil { return } const msgFmt = "shutting down http server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) } } // shutdownSrv3 shuts srv down and prints error messages to the log. // // TODO(a.garipov): Think of a good way to merge with [shutdownSrv]. func shutdownSrv3(srv *http3.Server) { defer log.OnPanic("") if srv == nil { return } err := srv.Close() if err == nil { return } const msgFmt = "shutting down http/3 server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err)
cType := w.Header().Get(aghhttp.HdrNameContentType) assert.Equal(t, aghhttp.HdrValApplicationJSON, cType)
s.conf = tc.conf() s.handleGetConfig(w, nil) cType := w.Header().Get(aghhttp.HdrNameContentType) assert.Equal(t, aghhttp.HdrValApplicationJSON, cType) assert.JSONEq(t, string(caseWant), w.Body.String()) }) } }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/dnsforward/http_test.go
var conf *proxy.UpstreamConfig conf, err = proxy.ParseUpstreamsConfig( upstreams, &upstream.Options{ Bootstrap: config.DNS.BootstrapDNS, Timeout: config.DNS.UpstreamTimeout.Duration, }, ) if err != nil { return nil, err }
</s> remove &upstream.Options{Bootstrap: []string{}, Timeout: DefaultTimeout}, </s> add &upstream.Options{ Bootstrap: []string{}, Timeout: DefaultTimeout, }, </s> remove Bootstrap: s.conf.BootstrapDNS, Timeout: s.conf.UpstreamTimeout, </s> add Bootstrap: s.conf.BootstrapDNS, Timeout: s.conf.UpstreamTimeout, HTTPVersions: httpVersions, </s> remove Bootstrap: s.conf.BootstrapDNS, Timeout: s.conf.UpstreamTimeout, </s> add Bootstrap: s.conf.BootstrapDNS, Timeout: s.conf.UpstreamTimeout, HTTPVersions: httpVersions, </s> remove jsonVal, err := json.Marshal(result) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Unable to marshal status json: %s", err, ) return } w.Header().Set("Content-Type", "application/json") _, err = w.Write(jsonVal) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "Couldn't write body: %s", err) } </s> add _ = aghhttp.WriteJSONResponse(w, r, result)
Bootstrap: config.DNS.BootstrapDNS, Timeout: config.DNS.UpstreamTimeout.Duration, HTTPVersions: dnsforward.UpstreamHTTPVersions(config.DNS.UseHTTP3Upstreams),
var conf *proxy.UpstreamConfig conf, err = proxy.ParseUpstreamsConfig( upstreams, &upstream.Options{ Bootstrap: config.DNS.BootstrapDNS, Timeout: config.DNS.UpstreamTimeout.Duration, HTTPVersions: dnsforward.UpstreamHTTPVersions(config.DNS.UseHTTP3Upstreams), Bootstrap: config.DNS.BootstrapDNS, Timeout: config.DNS.UpstreamTimeout.Duration, HTTPVersions: dnsforward.UpstreamHTTPVersions(config.DNS.UseHTTP3Upstreams), }, ) if err != nil { return nil, err }
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/clients.go
// LocalPTRResolvers is the slice of addresses to be used as upstreams // for PTR queries for locally-served networks. LocalPTRResolvers []string `yaml:"local_ptr_upstreams"` } type tlsConfigSettings struct { Enabled bool `yaml:"enabled" json:"enabled"` // Enabled is the encryption (DoT/DoH/HTTPS) status ServerName string `yaml:"server_name" json:"server_name,omitempty"` // ServerName is the hostname of your HTTPS/TLS server ForceHTTPS bool `yaml:"force_https" json:"force_https"` // ForceHTTPS: if true, forces HTTP->HTTPS redirect
</s> remove // LocalPTRResolvers is a slice of addresses to be used as upstreams for // resolving PTR queries for local addresses. LocalPTRResolvers []string </s> add // ServeHTTP3 defines if HTTP/3 is be allowed for incoming requests. ServeHTTP3 bool // UseHTTP3Upstreams defines if HTTP/3 is be allowed for DNS-over-HTTPS // upstreams. UseHTTP3Upstreams bool </s> remove // HTTPSServer - HTTPS Server type HTTPSServer struct { server *http.Server cond *sync.Cond condLock sync.Mutex shutdown bool // if TRUE, don't restart the server enabled bool cert tls.Certificate </s> add // httpsServer contains the data for the HTTPS server. type httpsServer struct { // server is the pre-HTTP/3 HTTPS server. server *http.Server // server3 is the HTTP/3 HTTPS server. If it is not nil, // [httpsServer.server] must also be non-nil. server3 *http3.Server // TODO(a.garipov): Why is there a *sync.Cond here? Remove. cond *sync.Cond condLock sync.Mutex cert tls.Certificate inShutdown bool enabled bool </s> remove conf *webConfig forceHTTPS bool httpServer *http.Server // HTTP module httpsServer HTTPSServer // HTTPS module </s> add conf *webConfig // TODO(a.garipov): Refactor all these servers. httpServer *http.Server // httpServerBeta is a server for new client. httpServerBeta *http.Server
// ServeHTTP3 defines if HTTP/3 is be allowed for incoming requests. // // TODO(a.garipov): Add to the UI when HTTP/3 support is no longer // experimental. ServeHTTP3 bool `yaml:"serve_http3"` // UseHTTP3Upstreams defines if HTTP/3 is be allowed for DNS-over-HTTPS // upstreams. // // TODO(a.garipov): Add to the UI when HTTP/3 support is no longer // experimental. UseHTTP3Upstreams bool `yaml:"use_http3_upstreams"`
// LocalPTRResolvers is the slice of addresses to be used as upstreams // for PTR queries for locally-served networks. LocalPTRResolvers []string `yaml:"local_ptr_upstreams"` // ServeHTTP3 defines if HTTP/3 is be allowed for incoming requests. // // TODO(a.garipov): Add to the UI when HTTP/3 support is no longer // experimental. ServeHTTP3 bool `yaml:"serve_http3"` // UseHTTP3Upstreams defines if HTTP/3 is be allowed for DNS-over-HTTPS // upstreams. // // TODO(a.garipov): Add to the UI when HTTP/3 support is no longer // experimental. UseHTTP3Upstreams bool `yaml:"use_http3_upstreams"` } type tlsConfigSettings struct { Enabled bool `yaml:"enabled" json:"enabled"` // Enabled is the encryption (DoT/DoH/HTTPS) status ServerName string `yaml:"server_name" json:"server_name,omitempty"` // ServerName is the hostname of your HTTPS/TLS server ForceHTTPS bool `yaml:"force_https" json:"force_https"` // ForceHTTPS: if true, forces HTTP->HTTPS redirect
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/config.go
package home import ( "encoding/json" "fmt" "net" "net/http" "net/url" "runtime"
</s> remove github.com/AdguardTeam/dnsproxy v0.44.0 </s> add github.com/AdguardTeam/dnsproxy v0.45.2 </s> remove github.com/lucas-clemente/quic-go v0.29.0 </s> add github.com/lucas-clemente/quic-go v0.29.1 </s> remove // LocalPTRResolvers is a slice of addresses to be used as upstreams for // resolving PTR queries for local addresses. LocalPTRResolvers []string </s> add // ServeHTTP3 defines if HTTP/3 is be allowed for incoming requests. ServeHTTP3 bool // UseHTTP3Upstreams defines if HTTP/3 is be allowed for DNS-over-HTTPS // upstreams. UseHTTP3Upstreams bool </s> remove Bootstrap: config.DNS.BootstrapDNS, Timeout: config.DNS.UpstreamTimeout.Duration, </s> add Bootstrap: config.DNS.BootstrapDNS, Timeout: config.DNS.UpstreamTimeout.Duration, HTTPVersions: dnsforward.UpstreamHTTPVersions(config.DNS.UseHTTP3Upstreams),
package home import ( "fmt" "net" "net/http" "net/url" "runtime"
[ "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/control.go
Name string `json:"name"` } func handleGetProfile(w http.ResponseWriter, r *http.Request) { pj := profileJSON{} u := Context.auth.getCurrentUser(r) pj.Name = u.Name data, err := json.Marshal(pj)
</s> remove pj.Name = u.Name data, err := json.Marshal(pj) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "json.Marshal: %s", err) return </s> add resp := &profileJSON{ Name: u.Name, </s> remove j := s.accessListJSON() w.Header().Set("Content-Type", "application/json") err := json.NewEncoder(w).Encode(j) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "encoding response: %s", err) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, s.accessListJSON()) </s> remove if err != http.ErrServerClosed { </s> add if !errors.Is(err, http.ErrServerClosed) { </s> remove log.Fatal(err) </s> add log.Fatalf("web: https: %s", err)
Name string `json:"name"` } func handleGetProfile(w http.ResponseWriter, r *http.Request) { u := Context.auth.getCurrentUser(r) pj.Name = u.Name data, err := json.Marshal(pj)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/control.go
func handleGetProfile(w http.ResponseWriter, r *http.Request) { pj := profileJSON{} u := Context.auth.getCurrentUser(r) pj.Name = u.Name data, err := json.Marshal(pj) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "json.Marshal: %s", err) return } _, _ = w.Write(data) }
</s> remove pj := profileJSON{} </s> add </s> remove jsonVal, err := json.Marshal(result) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Unable to marshal status json: %s", err, ) return } w.Header().Set("Content-Type", "application/json") _, err = w.Write(jsonVal) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "Couldn't write body: %s", err) } </s> add _ = aghhttp.WriteJSONResponse(w, r, result) </s> remove j := s.accessListJSON() w.Header().Set("Content-Type", "application/json") err := json.NewEncoder(w).Encode(j) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "encoding response: %s", err) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, s.accessListJSON()) </s> remove w.Header().Set("Content-Type", "application/json") if err = json.NewEncoder(w).Encode(resp); err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "json.Encoder: %s", err) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove aghhttp.Error( r, w, http.StatusBadRequest, "Failed to encode 'check_config' JSON data: %s", err, ) </s> add aghhttp.Error(r, w, http.StatusBadRequest, "encoding configure: %s", err)
resp := &profileJSON{ Name: u.Name,
func handleGetProfile(w http.ResponseWriter, r *http.Request) { pj := profileJSON{} u := Context.auth.getCurrentUser(r) resp := &profileJSON{ Name: u.Name, resp := &profileJSON{ Name: u.Name, resp := &profileJSON{ Name: u.Name, resp := &profileJSON{ Name: u.Name, resp := &profileJSON{ Name: u.Name, resp := &profileJSON{ Name: u.Name, resp := &profileJSON{ Name: u.Name, resp := &profileJSON{ Name: u.Name, } _, _ = w.Write(data) }
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/control.go
return } _, _ = w.Write(data) } // ------------------------ // registration of handlers // ------------------------
</s> remove pj.Name = u.Name data, err := json.Marshal(pj) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "json.Marshal: %s", err) return </s> add resp := &profileJSON{ Name: u.Name, </s> remove jsonVal, err := json.Marshal(result) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Unable to marshal status json: %s", err, ) return } w.Header().Set("Content-Type", "application/json") _, err = w.Write(jsonVal) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "Couldn't write body: %s", err) } </s> add _ = aghhttp.WriteJSONResponse(w, r, result) </s> remove w.Header().Set("Content-Type", "application/json") if err = json.NewEncoder(w).Encode(resp); err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "json.Encoder: %s", err) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove if err != nil { const msgFmt = "shutting down http server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) } </s> add if err == nil { return } const msgFmt = "shutting down http server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) } } // shutdownSrv3 shuts srv down and prints error messages to the log. // // TODO(a.garipov): Think of a good way to merge with [shutdownSrv]. func shutdownSrv3(srv *http3.Server) { defer log.OnPanic("") if srv == nil { return } err := srv.Close() if err == nil { return } const msgFmt = "shutting down http/3 server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err)
_ = aghhttp.WriteJSONResponse(w, r, resp)
return } _ = aghhttp.WriteJSONResponse(w, r, resp) } // ------------------------ // registration of handlers // ------------------------
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/control.go
"github.com/AdguardTeam/golibs/errors" "github.com/AdguardTeam/golibs/log" ) // getAddrsResponse is the response for /install/get_addresses endpoint. type getAddrsResponse struct { Interfaces map[string]*aghnet.NetInterface `json:"interfaces"`
</s> remove // HTTPSServer - HTTPS Server type HTTPSServer struct { server *http.Server cond *sync.Cond condLock sync.Mutex shutdown bool // if TRUE, don't restart the server enabled bool cert tls.Certificate </s> add // httpsServer contains the data for the HTTPS server. type httpsServer struct { // server is the pre-HTTP/3 HTTPS server. server *http.Server // server3 is the HTTP/3 HTTPS server. If it is not nil, // [httpsServer.server] must also be non-nil. server3 *http3.Server // TODO(a.garipov): Why is there a *sync.Cond here? Remove. cond *sync.Cond condLock sync.Mutex cert tls.Certificate inShutdown bool enabled bool </s> remove conf *webConfig forceHTTPS bool httpServer *http.Server // HTTP module httpsServer HTTPSServer // HTTPS module </s> add conf *webConfig // TODO(a.garipov): Refactor all these servers. httpServer *http.Server // httpServerBeta is a server for new client. httpServerBeta *http.Server </s> remove // Web - module object </s> add // Web is the web UI and API server.
"github.com/lucas-clemente/quic-go/http3"
"github.com/AdguardTeam/golibs/errors" "github.com/AdguardTeam/golibs/log" "github.com/lucas-clemente/quic-go/http3" ) // getAddrsResponse is the response for /install/get_addresses endpoint. type getAddrsResponse struct { Interfaces map[string]*aghnet.NetInterface `json:"interfaces"`
[ "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/controlinstall.go
// shutdownTimeout is the timeout for shutting HTTP server down operation. const shutdownTimeout = 5 * time.Second func shutdownSrv(ctx context.Context, srv *http.Server) { defer log.OnPanic("") if srv == nil { return }
</s> remove if err != nil { const msgFmt = "shutting down http server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) } </s> add if err == nil { return } const msgFmt = "shutting down http server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) } } // shutdownSrv3 shuts srv down and prints error messages to the log. // // TODO(a.garipov): Think of a good way to merge with [shutdownSrv]. func shutdownSrv3(srv *http3.Server) { defer log.OnPanic("") if srv == nil { return } err := srv.Close() if err == nil { return } const msgFmt = "shutting down http/3 server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) </s> remove // WebCheckPortAvailable - check if port is available // BUT: if we are already using this port, no need func WebCheckPortAvailable(port int) bool { </s> add // webCheckPortAvailable checks if port, which is considered an HTTPS port, is // available, unless the HTTPS server isn't active. // // TODO(a.garipov): Adapt for HTTP/3. func webCheckPortAvailable(port int) (ok bool) { </s> remove w.Header().Set("Content-Type", "application/json") if err = json.NewEncoder(w).Encode(resp); err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "json.Encoder: %s", err) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove conf *webConfig forceHTTPS bool httpServer *http.Server // HTTP module httpsServer HTTPSServer // HTTPS module </s> add conf *webConfig // TODO(a.garipov): Refactor all these servers. httpServer *http.Server // httpServerBeta is a server for new client. httpServerBeta *http.Server
// shutdownSrv shuts srv down and prints error messages to the log.
// shutdownTimeout is the timeout for shutting HTTP server down operation. const shutdownTimeout = 5 * time.Second // shutdownSrv shuts srv down and prints error messages to the log. func shutdownSrv(ctx context.Context, srv *http.Server) { defer log.OnPanic("") if srv == nil { return }
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/controlinstall.go
return } err := srv.Shutdown(ctx) if err != nil { const msgFmt = "shutting down http server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) } } } // PasswordMinRunes is the minimum length of user's password in runes. const PasswordMinRunes = 8
</s> remove log.Fatal(err) </s> add log.Fatalf("web: https: %s", err) </s> remove jsonVal, err := json.Marshal(result) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Unable to marshal status json: %s", err, ) return } w.Header().Set("Content-Type", "application/json") _, err = w.Write(jsonVal) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "Couldn't write body: %s", err) } </s> add _ = aghhttp.WriteJSONResponse(w, r, result) </s> remove w.Header().Set("Content-Type", "application/json") if err = json.NewEncoder(w).Encode(resp); err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "json.Encoder: %s", err) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove pj.Name = u.Name data, err := json.Marshal(pj) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "json.Marshal: %s", err) return </s> add resp := &profileJSON{ Name: u.Name,
if err == nil { return } const msgFmt = "shutting down http server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) } } // shutdownSrv3 shuts srv down and prints error messages to the log. // // TODO(a.garipov): Think of a good way to merge with [shutdownSrv]. func shutdownSrv3(srv *http3.Server) { defer log.OnPanic("") if srv == nil { return } err := srv.Close() if err == nil { return } const msgFmt = "shutting down http/3 server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err)
return } err := srv.Shutdown(ctx) if err == nil { return } const msgFmt = "shutting down http server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) } } // shutdownSrv3 shuts srv down and prints error messages to the log. // // TODO(a.garipov): Think of a good way to merge with [shutdownSrv]. func shutdownSrv3(srv *http3.Server) { defer log.OnPanic("") if srv == nil { return } err := srv.Close() if err == nil { return } const msgFmt = "shutting down http/3 server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) if err == nil { return } const msgFmt = "shutting down http server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) } } // shutdownSrv3 shuts srv down and prints error messages to the log. // // TODO(a.garipov): Think of a good way to merge with [shutdownSrv]. func shutdownSrv3(srv *http3.Server) { defer log.OnPanic("") if srv == nil { return } err := srv.Close() if err == nil { return } const msgFmt = "shutting down http/3 server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) if err == nil { return } const msgFmt = "shutting down http server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) } } // shutdownSrv3 shuts srv down and prints error messages to the log. // // TODO(a.garipov): Think of a good way to merge with [shutdownSrv]. func shutdownSrv3(srv *http3.Server) { defer log.OnPanic("") if srv == nil { return } err := srv.Close() if err == nil { return } const msgFmt = "shutting down http/3 server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) if err == nil { return } const msgFmt = "shutting down http server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) } } // shutdownSrv3 shuts srv down and prints error messages to the log. // // TODO(a.garipov): Think of a good way to merge with [shutdownSrv]. func shutdownSrv3(srv *http3.Server) { defer log.OnPanic("") if srv == nil { return } err := srv.Close() if err == nil { return } const msgFmt = "shutting down http/3 server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) if err == nil { return } const msgFmt = "shutting down http server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) } } // shutdownSrv3 shuts srv down and prints error messages to the log. // // TODO(a.garipov): Think of a good way to merge with [shutdownSrv]. func shutdownSrv3(srv *http3.Server) { defer log.OnPanic("") if srv == nil { return } err := srv.Close() if err == nil { return } const msgFmt = "shutting down http/3 server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) if err == nil { return } const msgFmt = "shutting down http server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) } } // shutdownSrv3 shuts srv down and prints error messages to the log. // // TODO(a.garipov): Think of a good way to merge with [shutdownSrv]. func shutdownSrv3(srv *http3.Server) { defer log.OnPanic("") if srv == nil { return } err := srv.Close() if err == nil { return } const msgFmt = "shutting down http/3 server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) if err == nil { return } const msgFmt = "shutting down http server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) } } // shutdownSrv3 shuts srv down and prints error messages to the log. // // TODO(a.garipov): Think of a good way to merge with [shutdownSrv]. func shutdownSrv3(srv *http3.Server) { defer log.OnPanic("") if srv == nil { return } err := srv.Close() if err == nil { return } const msgFmt = "shutting down http/3 server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) } } // PasswordMinRunes is the minimum length of user's password in runes. const PasswordMinRunes = 8
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/controlinstall.go
nonBetaReqBody := &strings.Builder{} err = json.NewEncoder(nonBetaReqBody).Encode(nonBetaReqData) if err != nil { aghhttp.Error( r, w, http.StatusBadRequest, "Failed to encode 'check_config' JSON data: %s", err, ) return } body := nonBetaReqBody.String() r.Body = io.NopCloser(strings.NewReader(body))
</s> remove aghhttp.Error( r, w, http.StatusBadRequest, "Failed to encode 'check_config' JSON data: %s", err, ) </s> add aghhttp.Error(r, w, http.StatusBadRequest, "encoding configure: %s", err) </s> remove jsonVal, err := json.Marshal(result) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Unable to marshal status json: %s", err, ) return } w.Header().Set("Content-Type", "application/json") _, err = w.Write(jsonVal) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "Couldn't write body: %s", err) } </s> add _ = aghhttp.WriteJSONResponse(w, r, result) </s> remove w.Header().Set("Content-Type", "application/json") if err = json.NewEncoder(w).Encode(resp); err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "json.Encoder: %s", err) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove pj.Name = u.Name data, err := json.Marshal(pj) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "json.Marshal: %s", err) return </s> add resp := &profileJSON{ Name: u.Name, </s> remove if !WebCheckPortAvailable(setts.PortHTTPS) { </s> add if !webCheckPortAvailable(setts.PortHTTPS) {
aghhttp.Error(r, w, http.StatusBadRequest, "encoding check_config: %s", err)
nonBetaReqBody := &strings.Builder{} err = json.NewEncoder(nonBetaReqBody).Encode(nonBetaReqData) if err != nil { aghhttp.Error(r, w, http.StatusBadRequest, "encoding check_config: %s", err) aghhttp.Error(r, w, http.StatusBadRequest, "encoding check_config: %s", err) aghhttp.Error(r, w, http.StatusBadRequest, "encoding check_config: %s", err) aghhttp.Error(r, w, http.StatusBadRequest, "encoding check_config: %s", err) aghhttp.Error(r, w, http.StatusBadRequest, "encoding check_config: %s", err) aghhttp.Error(r, w, http.StatusBadRequest, "encoding check_config: %s", err) aghhttp.Error(r, w, http.StatusBadRequest, "encoding check_config: %s", err) return } body := nonBetaReqBody.String() r.Body = io.NopCloser(strings.NewReader(body))
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/controlinstall.go
nonBetaReqBody := &strings.Builder{} err = json.NewEncoder(nonBetaReqBody).Encode(nonBetaReqData) if err != nil { aghhttp.Error( r, w, http.StatusBadRequest, "Failed to encode 'check_config' JSON data: %s", err, ) return } body := nonBetaReqBody.String() r.Body = io.NopCloser(strings.NewReader(body))
</s> remove aghhttp.Error( r, w, http.StatusBadRequest, "Failed to encode 'check_config' JSON data: %s", err, ) </s> add aghhttp.Error(r, w, http.StatusBadRequest, "encoding check_config: %s", err) </s> remove jsonVal, err := json.Marshal(result) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Unable to marshal status json: %s", err, ) return } w.Header().Set("Content-Type", "application/json") _, err = w.Write(jsonVal) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "Couldn't write body: %s", err) } </s> add _ = aghhttp.WriteJSONResponse(w, r, result) </s> remove w.Header().Set("Content-Type", "application/json") if err = json.NewEncoder(w).Encode(resp); err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "json.Encoder: %s", err) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove pj.Name = u.Name data, err := json.Marshal(pj) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "json.Marshal: %s", err) return </s> add resp := &profileJSON{ Name: u.Name, </s> remove if !WebCheckPortAvailable(setts.PortHTTPS) { </s> add if !webCheckPortAvailable(setts.PortHTTPS) {
aghhttp.Error(r, w, http.StatusBadRequest, "encoding configure: %s", err)
nonBetaReqBody := &strings.Builder{} err = json.NewEncoder(nonBetaReqBody).Encode(nonBetaReqData) if err != nil { aghhttp.Error(r, w, http.StatusBadRequest, "encoding configure: %s", err) aghhttp.Error(r, w, http.StatusBadRequest, "encoding configure: %s", err) aghhttp.Error(r, w, http.StatusBadRequest, "encoding configure: %s", err) aghhttp.Error(r, w, http.StatusBadRequest, "encoding configure: %s", err) aghhttp.Error(r, w, http.StatusBadRequest, "encoding configure: %s", err) aghhttp.Error(r, w, http.StatusBadRequest, "encoding configure: %s", err) aghhttp.Error(r, w, http.StatusBadRequest, "encoding configure: %s", err) return } body := nonBetaReqBody.String() r.Body = io.NopCloser(strings.NewReader(body))
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/controlinstall.go
newConf.FilterHandler = applyAdditionalFiltering newConf.GetCustomUpstreamByClient = Context.clients.findUpstreams newConf.ResolveClients = config.Clients.Sources.RDNS newConf.UsePrivateRDNS = dnsConf.UsePrivateRDNS newConf.LocalPTRResolvers = dnsConf.LocalPTRResolvers newConf.UpstreamTimeout = dnsConf.UpstreamTimeout.Duration return newConf, nil }
</s> remove web = CreateWeb(&webConf) </s> add web = newWeb(&webConf) </s> remove w.Header().Set("Content-Type", "application/json") if err = json.NewEncoder(w).Encode(resp); err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "json.Encoder: %s", err) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove if err != nil { const msgFmt = "shutting down http server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) } </s> add if err == nil { return } const msgFmt = "shutting down http server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) } } // shutdownSrv3 shuts srv down and prints error messages to the log. // // TODO(a.garipov): Think of a good way to merge with [shutdownSrv]. func shutdownSrv3(srv *http3.Server) { defer log.OnPanic("") if srv == nil { return } err := srv.Close() if err == nil { return } const msgFmt = "shutting down http/3 server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) </s> remove jsonVal, err := json.Marshal(result) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Unable to marshal status json: %s", err, ) return } w.Header().Set("Content-Type", "application/json") _, err = w.Write(jsonVal) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "Couldn't write body: %s", err) } </s> add _ = aghhttp.WriteJSONResponse(w, r, result)
newConf.FilterHandler = applyAdditionalFiltering newConf.GetCustomUpstreamByClient = Context.clients.findUpstreams newConf.LocalPTRResolvers = dnsConf.LocalPTRResolvers newConf.UpstreamTimeout = dnsConf.UpstreamTimeout.Duration return newConf, nil }
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/dns.go
newConf.LocalPTRResolvers = dnsConf.LocalPTRResolvers newConf.UpstreamTimeout = dnsConf.UpstreamTimeout.Duration return newConf, nil } func newDNSCrypt(hosts []net.IP, tlsConf tlsConfigSettings) (dnscc dnsforward.DNSCryptConfig, err error) { if tlsConf.DNSCryptConfigFile == "" {
</s> remove newConf.ResolveClients = config.Clients.Sources.RDNS newConf.UsePrivateRDNS = dnsConf.UsePrivateRDNS </s> add </s> remove w.Header().Set("Content-Type", "application/json") if err = json.NewEncoder(w).Encode(resp); err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "json.Encoder: %s", err) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove if err != nil { const msgFmt = "shutting down http server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) } </s> add if err == nil { return } const msgFmt = "shutting down http server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) } } // shutdownSrv3 shuts srv down and prints error messages to the log. // // TODO(a.garipov): Think of a good way to merge with [shutdownSrv]. func shutdownSrv3(srv *http3.Server) { defer log.OnPanic("") if srv == nil { return } err := srv.Close() if err == nil { return } const msgFmt = "shutting down http/3 server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) </s> remove &upstream.Options{Bootstrap: []string{}, Timeout: DefaultTimeout}, </s> add &upstream.Options{ Bootstrap: []string{}, Timeout: DefaultTimeout, }, </s> remove web = CreateWeb(&webConf) </s> add web = newWeb(&webConf)
newConf.ResolveClients = config.Clients.Sources.RDNS newConf.UsePrivateRDNS = dnsConf.UsePrivateRDNS newConf.ServeHTTP3 = dnsConf.ServeHTTP3 newConf.UseHTTP3Upstreams = dnsConf.UseHTTP3Upstreams
newConf.LocalPTRResolvers = dnsConf.LocalPTRResolvers newConf.UpstreamTimeout = dnsConf.UpstreamTimeout.Duration newConf.ResolveClients = config.Clients.Sources.RDNS newConf.UsePrivateRDNS = dnsConf.UsePrivateRDNS newConf.ServeHTTP3 = dnsConf.ServeHTTP3 newConf.UseHTTP3Upstreams = dnsConf.UseHTTP3Upstreams return newConf, nil } func newDNSCrypt(hosts []net.IP, tlsConf tlsConfigSettings) (dnscc dnsforward.DNSCryptConfig, err error) { if tlsConf.DNSCryptConfigFile == "" {
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/dns.go
WriteTimeout: writeTimeout, clientFS: clientFS, clientBetaFS: clientBetaFS, } web = newWeb(&webConf) if web == nil {
</s> remove web = CreateWeb(&webConf) </s> add web = newWeb(&webConf) </s> remove // CreateWeb - create module func CreateWeb(conf *webConfig) *Web { log.Info("Initialize web module") </s> add // newWeb creates a new instance of the web UI and API server. func newWeb(conf *webConfig) (w *Web) { log.Info("web: initializing") </s> remove w.Header().Set("Content-Type", "application/json") if err = json.NewEncoder(w).Encode(resp); err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "json.Encoder: %s", err) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove if err != nil { const msgFmt = "shutting down http server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) } </s> add if err == nil { return } const msgFmt = "shutting down http server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) } } // shutdownSrv3 shuts srv down and prints error messages to the log. // // TODO(a.garipov): Think of a good way to merge with [shutdownSrv]. func shutdownSrv3(srv *http3.Server) { defer log.OnPanic("") if srv == nil { return } err := srv.Close() if err == nil { return } const msgFmt = "shutting down http/3 server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err)
serveHTTP3: config.DNS.ServeHTTP3,
WriteTimeout: writeTimeout, clientFS: clientFS, clientBetaFS: clientBetaFS, serveHTTP3: config.DNS.ServeHTTP3, } web = newWeb(&webConf) if web == nil {
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/home.go
clientFS: clientFS, clientBetaFS: clientBetaFS, } web = CreateWeb(&webConf) if web == nil { return nil, fmt.Errorf("initializing web: %w", err) } return web, nil
</s> remove &upstream.Options{Bootstrap: []string{}, Timeout: DefaultTimeout}, </s> add &upstream.Options{ Bootstrap: []string{}, Timeout: DefaultTimeout, }, </s> remove w.Header().Set("Content-Type", "application/json") if err = json.NewEncoder(w).Encode(resp); err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "json.Encoder: %s", err) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove if err != nil { const msgFmt = "shutting down http server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) } </s> add if err == nil { return } const msgFmt = "shutting down http server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) } } // shutdownSrv3 shuts srv down and prints error messages to the log. // // TODO(a.garipov): Think of a good way to merge with [shutdownSrv]. func shutdownSrv3(srv *http3.Server) { defer log.OnPanic("") if srv == nil { return } err := srv.Close() if err == nil { return } const msgFmt = "shutting down http/3 server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) </s> remove Bootstrap: s.conf.BootstrapDNS, Timeout: s.conf.UpstreamTimeout, </s> add Bootstrap: s.conf.BootstrapDNS, Timeout: s.conf.UpstreamTimeout, HTTPVersions: httpVersions,
web = newWeb(&webConf)
clientFS: clientFS, clientBetaFS: clientBetaFS, } web = newWeb(&webConf) if web == nil { return nil, fmt.Errorf("initializing web: %w", err) } return web, nil
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/home.go
return } } if !WebCheckPortAvailable(setts.PortHTTPS) { aghhttp.Error( r, w, http.StatusBadRequest, "port %d is not available, cannot enable HTTPS on it",
</s> remove if !WebCheckPortAvailable(data.PortHTTPS) { </s> add if !webCheckPortAvailable(data.PortHTTPS) { </s> remove aghhttp.Error( r, w, http.StatusBadRequest, "Failed to encode 'check_config' JSON data: %s", err, ) </s> add aghhttp.Error(r, w, http.StatusBadRequest, "encoding check_config: %s", err) </s> remove aghhttp.Error( r, w, http.StatusBadRequest, "Failed to encode 'check_config' JSON data: %s", err, ) </s> add aghhttp.Error(r, w, http.StatusBadRequest, "encoding configure: %s", err) </s> remove jsonVal, err := json.Marshal(result) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Unable to marshal status json: %s", err, ) return } w.Header().Set("Content-Type", "application/json") _, err = w.Write(jsonVal) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "Couldn't write body: %s", err) } </s> add _ = aghhttp.WriteJSONResponse(w, r, result)
if !webCheckPortAvailable(setts.PortHTTPS) {
return } } if !webCheckPortAvailable(setts.PortHTTPS) { aghhttp.Error( r, w, http.StatusBadRequest, "port %d is not available, cannot enable HTTPS on it",
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/tls.go
} } // TODO(e.burkov): Investigate and perhaps check other ports. if !WebCheckPortAvailable(data.PortHTTPS) { aghhttp.Error( r, w, http.StatusBadRequest, "port %d is not available, cannot enable HTTPS on it",
</s> remove if !WebCheckPortAvailable(setts.PortHTTPS) { </s> add if !webCheckPortAvailable(setts.PortHTTPS) { </s> remove aghhttp.Error( r, w, http.StatusBadRequest, "Failed to encode 'check_config' JSON data: %s", err, ) </s> add aghhttp.Error(r, w, http.StatusBadRequest, "encoding check_config: %s", err) </s> remove aghhttp.Error( r, w, http.StatusBadRequest, "Failed to encode 'check_config' JSON data: %s", err, ) </s> add aghhttp.Error(r, w, http.StatusBadRequest, "encoding configure: %s", err) </s> remove jsonVal, err := json.Marshal(result) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Unable to marshal status json: %s", err, ) return } w.Header().Set("Content-Type", "application/json") _, err = w.Write(jsonVal) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "Couldn't write body: %s", err) } </s> add _ = aghhttp.WriteJSONResponse(w, r, result) </s> remove // WebCheckPortAvailable - check if port is available // BUT: if we are already using this port, no need func WebCheckPortAvailable(port int) bool { </s> add // webCheckPortAvailable checks if port, which is considered an HTTPS port, is // available, unless the HTTPS server isn't active. // // TODO(a.garipov): Adapt for HTTP/3. func webCheckPortAvailable(port int) (ok bool) {
if !webCheckPortAvailable(data.PortHTTPS) {
} } // TODO(e.burkov): Investigate and perhaps check other ports. if !webCheckPortAvailable(data.PortHTTPS) { aghhttp.Error( r, w, http.StatusBadRequest, "port %d is not available, cannot enable HTTPS on it",
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/tls.go
"github.com/AdguardTeam/golibs/errors" "github.com/AdguardTeam/golibs/log" "github.com/AdguardTeam/golibs/netutil" "github.com/NYTimes/gziphandler" "golang.org/x/net/http2" "golang.org/x/net/http2/h2c" )
</s> remove Bootstrap: config.DNS.BootstrapDNS, Timeout: config.DNS.UpstreamTimeout.Duration, </s> add Bootstrap: config.DNS.BootstrapDNS, Timeout: config.DNS.UpstreamTimeout.Duration, HTTPVersions: dnsforward.UpstreamHTTPVersions(config.DNS.UseHTTP3Upstreams), </s> remove golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 golang.org/x/exp v0.0.0-20220827204233-334a2380cb91 golang.org/x/net v0.0.0-20220906165146-f3363e06e74c golang.org/x/sys v0.0.0-20220906135438-9e1f76180b77 </s> add golang.org/x/crypto v0.0.0-20220926161630-eccd6366d1be golang.org/x/exp v0.0.0-20220929160808-de9c53c655b9 golang.org/x/net v0.0.0-20220927171203-f486391704dc golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec </s> remove Bootstrap: s.conf.BootstrapDNS, Timeout: s.conf.UpstreamTimeout, </s> add Bootstrap: s.conf.BootstrapDNS, Timeout: s.conf.UpstreamTimeout, HTTPVersions: httpVersions,
"github.com/lucas-clemente/quic-go" "github.com/lucas-clemente/quic-go/http3"
"github.com/AdguardTeam/golibs/errors" "github.com/AdguardTeam/golibs/log" "github.com/AdguardTeam/golibs/netutil" "github.com/NYTimes/gziphandler" "github.com/lucas-clemente/quic-go" "github.com/lucas-clemente/quic-go/http3" "golang.org/x/net/http2" "golang.org/x/net/http2/h2c" )
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/web.go
// appropriate field. WriteTimeout time.Duration firstRun bool } // httpsServer contains the data for the HTTPS server. type httpsServer struct { // server is the pre-HTTP/3 HTTPS server.
</s> remove // HTTPSServer - HTTPS Server type HTTPSServer struct { server *http.Server cond *sync.Cond condLock sync.Mutex shutdown bool // if TRUE, don't restart the server enabled bool cert tls.Certificate </s> add // httpsServer contains the data for the HTTPS server. type httpsServer struct { // server is the pre-HTTP/3 HTTPS server. server *http.Server // server3 is the HTTP/3 HTTPS server. If it is not nil, // [httpsServer.server] must also be non-nil. server3 *http3.Server // TODO(a.garipov): Why is there a *sync.Cond here? Remove. cond *sync.Cond condLock sync.Mutex cert tls.Certificate inShutdown bool enabled bool </s> remove // Web - module object </s> add // Web is the web UI and API server. </s> remove // httpServerBeta is a server for new client. httpServerBeta *http.Server </s> add // httpsServer is the server that handles HTTPS traffic. If it is not nil, // [Web.http3Server] must also not be nil. httpsServer httpsServer forceHTTPS bool </s> remove conf *webConfig forceHTTPS bool httpServer *http.Server // HTTP module httpsServer HTTPSServer // HTTPS module </s> add conf *webConfig // TODO(a.garipov): Refactor all these servers. httpServer *http.Server // httpServerBeta is a server for new client. httpServerBeta *http.Server </s> remove // WebCheckPortAvailable - check if port is available // BUT: if we are already using this port, no need func WebCheckPortAvailable(port int) bool { </s> add // webCheckPortAvailable checks if port, which is considered an HTTPS port, is // available, unless the HTTPS server isn't active. // // TODO(a.garipov): Adapt for HTTP/3. func webCheckPortAvailable(port int) (ok bool) {
serveHTTP3 bool
// appropriate field. WriteTimeout time.Duration firstRun bool serveHTTP3 bool } // httpsServer contains the data for the HTTPS server. type httpsServer struct { // server is the pre-HTTP/3 HTTPS server.
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/web.go
firstRun bool } // HTTPSServer - HTTPS Server type HTTPSServer struct { server *http.Server cond *sync.Cond condLock sync.Mutex shutdown bool // if TRUE, don't restart the server enabled bool cert tls.Certificate } // Web - module object type Web struct { conf *webConfig
</s> remove // Web - module object </s> add // Web is the web UI and API server. </s> remove conf *webConfig forceHTTPS bool httpServer *http.Server // HTTP module httpsServer HTTPSServer // HTTPS module </s> add conf *webConfig // TODO(a.garipov): Refactor all these servers. httpServer *http.Server // httpServerBeta is a server for new client. httpServerBeta *http.Server </s> remove // httpServerBeta is a server for new client. httpServerBeta *http.Server </s> add // httpsServer is the server that handles HTTPS traffic. If it is not nil, // [Web.http3Server] must also not be nil. httpsServer httpsServer forceHTTPS bool
// httpsServer contains the data for the HTTPS server. type httpsServer struct { // server is the pre-HTTP/3 HTTPS server. server *http.Server // server3 is the HTTP/3 HTTPS server. If it is not nil, // [httpsServer.server] must also be non-nil. server3 *http3.Server // TODO(a.garipov): Why is there a *sync.Cond here? Remove. cond *sync.Cond condLock sync.Mutex cert tls.Certificate inShutdown bool enabled bool
firstRun bool } // httpsServer contains the data for the HTTPS server. type httpsServer struct { // server is the pre-HTTP/3 HTTPS server. server *http.Server // server3 is the HTTP/3 HTTPS server. If it is not nil, // [httpsServer.server] must also be non-nil. server3 *http3.Server // TODO(a.garipov): Why is there a *sync.Cond here? Remove. cond *sync.Cond condLock sync.Mutex cert tls.Certificate inShutdown bool enabled bool // httpsServer contains the data for the HTTPS server. type httpsServer struct { // server is the pre-HTTP/3 HTTPS server. server *http.Server // server3 is the HTTP/3 HTTPS server. If it is not nil, // [httpsServer.server] must also be non-nil. server3 *http3.Server // TODO(a.garipov): Why is there a *sync.Cond here? Remove. cond *sync.Cond condLock sync.Mutex cert tls.Certificate inShutdown bool enabled bool // httpsServer contains the data for the HTTPS server. type httpsServer struct { // server is the pre-HTTP/3 HTTPS server. server *http.Server // server3 is the HTTP/3 HTTPS server. If it is not nil, // [httpsServer.server] must also be non-nil. server3 *http3.Server // TODO(a.garipov): Why is there a *sync.Cond here? Remove. cond *sync.Cond condLock sync.Mutex cert tls.Certificate inShutdown bool enabled bool // httpsServer contains the data for the HTTPS server. type httpsServer struct { // server is the pre-HTTP/3 HTTPS server. server *http.Server // server3 is the HTTP/3 HTTPS server. If it is not nil, // [httpsServer.server] must also be non-nil. server3 *http3.Server // TODO(a.garipov): Why is there a *sync.Cond here? Remove. cond *sync.Cond condLock sync.Mutex cert tls.Certificate inShutdown bool enabled bool // httpsServer contains the data for the HTTPS server. type httpsServer struct { // server is the pre-HTTP/3 HTTPS server. server *http.Server // server3 is the HTTP/3 HTTPS server. If it is not nil, // [httpsServer.server] must also be non-nil. server3 *http3.Server // TODO(a.garipov): Why is there a *sync.Cond here? Remove. cond *sync.Cond condLock sync.Mutex cert tls.Certificate inShutdown bool enabled bool // httpsServer contains the data for the HTTPS server. type httpsServer struct { // server is the pre-HTTP/3 HTTPS server. server *http.Server // server3 is the HTTP/3 HTTPS server. If it is not nil, // [httpsServer.server] must also be non-nil. server3 *http3.Server // TODO(a.garipov): Why is there a *sync.Cond here? Remove. cond *sync.Cond condLock sync.Mutex cert tls.Certificate inShutdown bool enabled bool // httpsServer contains the data for the HTTPS server. type httpsServer struct { // server is the pre-HTTP/3 HTTPS server. server *http.Server // server3 is the HTTP/3 HTTPS server. If it is not nil, // [httpsServer.server] must also be non-nil. server3 *http3.Server // TODO(a.garipov): Why is there a *sync.Cond here? Remove. cond *sync.Cond condLock sync.Mutex cert tls.Certificate inShutdown bool enabled bool // httpsServer contains the data for the HTTPS server. type httpsServer struct { // server is the pre-HTTP/3 HTTPS server. server *http.Server // server3 is the HTTP/3 HTTPS server. If it is not nil, // [httpsServer.server] must also be non-nil. server3 *http3.Server // TODO(a.garipov): Why is there a *sync.Cond here? Remove. cond *sync.Cond condLock sync.Mutex cert tls.Certificate inShutdown bool enabled bool } // Web - module object type Web struct { conf *webConfig
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/web.go
enabled bool cert tls.Certificate } // Web - module object type Web struct { conf *webConfig forceHTTPS bool httpServer *http.Server // HTTP module httpsServer HTTPSServer // HTTPS module
</s> remove conf *webConfig forceHTTPS bool httpServer *http.Server // HTTP module httpsServer HTTPSServer // HTTPS module </s> add conf *webConfig // TODO(a.garipov): Refactor all these servers. httpServer *http.Server // httpServerBeta is a server for new client. httpServerBeta *http.Server </s> remove // HTTPSServer - HTTPS Server type HTTPSServer struct { server *http.Server cond *sync.Cond condLock sync.Mutex shutdown bool // if TRUE, don't restart the server enabled bool cert tls.Certificate </s> add // httpsServer contains the data for the HTTPS server. type httpsServer struct { // server is the pre-HTTP/3 HTTPS server. server *http.Server // server3 is the HTTP/3 HTTPS server. If it is not nil, // [httpsServer.server] must also be non-nil. server3 *http3.Server // TODO(a.garipov): Why is there a *sync.Cond here? Remove. cond *sync.Cond condLock sync.Mutex cert tls.Certificate inShutdown bool enabled bool </s> remove // httpServerBeta is a server for new client. httpServerBeta *http.Server </s> add // httpsServer is the server that handles HTTPS traffic. If it is not nil, // [Web.http3Server] must also not be nil. httpsServer httpsServer forceHTTPS bool </s> remove // CreateWeb - create module func CreateWeb(conf *webConfig) *Web { log.Info("Initialize web module") </s> add // newWeb creates a new instance of the web UI and API server. func newWeb(conf *webConfig) (w *Web) { log.Info("web: initializing")
// Web is the web UI and API server.
enabled bool cert tls.Certificate } // Web is the web UI and API server. type Web struct { conf *webConfig forceHTTPS bool httpServer *http.Server // HTTP module httpsServer HTTPSServer // HTTPS module
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/web.go
} // Web - module object type Web struct { conf *webConfig forceHTTPS bool httpServer *http.Server // HTTP module httpsServer HTTPSServer // HTTPS module // handlerBeta is the handler for new client. handlerBeta http.Handler // installerBeta is the pre-install handler for new client. installerBeta http.Handler
</s> remove // httpServerBeta is a server for new client. httpServerBeta *http.Server </s> add // httpsServer is the server that handles HTTPS traffic. If it is not nil, // [Web.http3Server] must also not be nil. httpsServer httpsServer forceHTTPS bool </s> remove // Web - module object </s> add // Web is the web UI and API server. </s> remove // HTTPSServer - HTTPS Server type HTTPSServer struct { server *http.Server cond *sync.Cond condLock sync.Mutex shutdown bool // if TRUE, don't restart the server enabled bool cert tls.Certificate </s> add // httpsServer contains the data for the HTTPS server. type httpsServer struct { // server is the pre-HTTP/3 HTTPS server. server *http.Server // server3 is the HTTP/3 HTTPS server. If it is not nil, // [httpsServer.server] must also be non-nil. server3 *http3.Server // TODO(a.garipov): Why is there a *sync.Cond here? Remove. cond *sync.Cond condLock sync.Mutex cert tls.Certificate inShutdown bool enabled bool </s> remove // CreateWeb - create module func CreateWeb(conf *webConfig) *Web { log.Info("Initialize web module") </s> add // newWeb creates a new instance of the web UI and API server. func newWeb(conf *webConfig) (w *Web) { log.Info("web: initializing")
conf *webConfig // TODO(a.garipov): Refactor all these servers. httpServer *http.Server // httpServerBeta is a server for new client. httpServerBeta *http.Server
} // Web - module object type Web struct { conf *webConfig // TODO(a.garipov): Refactor all these servers. httpServer *http.Server // httpServerBeta is a server for new client. httpServerBeta *http.Server conf *webConfig // TODO(a.garipov): Refactor all these servers. httpServer *http.Server // httpServerBeta is a server for new client. httpServerBeta *http.Server conf *webConfig // TODO(a.garipov): Refactor all these servers. httpServer *http.Server // httpServerBeta is a server for new client. httpServerBeta *http.Server conf *webConfig // TODO(a.garipov): Refactor all these servers. httpServer *http.Server // httpServerBeta is a server for new client. httpServerBeta *http.Server // handlerBeta is the handler for new client. handlerBeta http.Handler // installerBeta is the pre-install handler for new client. installerBeta http.Handler
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/web.go
handlerBeta http.Handler // installerBeta is the pre-install handler for new client. installerBeta http.Handler // httpServerBeta is a server for new client. httpServerBeta *http.Server } // CreateWeb - create module func CreateWeb(conf *webConfig) *Web { log.Info("Initialize web module")
</s> remove conf *webConfig forceHTTPS bool httpServer *http.Server // HTTP module httpsServer HTTPSServer // HTTPS module </s> add conf *webConfig // TODO(a.garipov): Refactor all these servers. httpServer *http.Server // httpServerBeta is a server for new client. httpServerBeta *http.Server </s> remove // CreateWeb - create module func CreateWeb(conf *webConfig) *Web { log.Info("Initialize web module") </s> add // newWeb creates a new instance of the web UI and API server. func newWeb(conf *webConfig) (w *Web) { log.Info("web: initializing") </s> remove w := Web{} w.conf = conf </s> add w = &Web{ conf: conf, } </s> remove // Web - module object </s> add // Web is the web UI and API server. </s> remove // HTTPSServer - HTTPS Server type HTTPSServer struct { server *http.Server cond *sync.Cond condLock sync.Mutex shutdown bool // if TRUE, don't restart the server enabled bool cert tls.Certificate </s> add // httpsServer contains the data for the HTTPS server. type httpsServer struct { // server is the pre-HTTP/3 HTTPS server. server *http.Server // server3 is the HTTP/3 HTTPS server. If it is not nil, // [httpsServer.server] must also be non-nil. server3 *http3.Server // TODO(a.garipov): Why is there a *sync.Cond here? Remove. cond *sync.Cond condLock sync.Mutex cert tls.Certificate inShutdown bool enabled bool
// httpsServer is the server that handles HTTPS traffic. If it is not nil, // [Web.http3Server] must also not be nil. httpsServer httpsServer forceHTTPS bool
handlerBeta http.Handler // installerBeta is the pre-install handler for new client. installerBeta http.Handler // httpsServer is the server that handles HTTPS traffic. If it is not nil, // [Web.http3Server] must also not be nil. httpsServer httpsServer forceHTTPS bool // httpsServer is the server that handles HTTPS traffic. If it is not nil, // [Web.http3Server] must also not be nil. httpsServer httpsServer forceHTTPS bool } // CreateWeb - create module func CreateWeb(conf *webConfig) *Web { log.Info("Initialize web module")
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/web.go
// httpServerBeta is a server for new client. httpServerBeta *http.Server } // CreateWeb - create module func CreateWeb(conf *webConfig) *Web { log.Info("Initialize web module") w := Web{} w.conf = conf clientFS := http.FileServer(http.FS(conf.clientFS))
</s> remove w := Web{} w.conf = conf </s> add w = &Web{ conf: conf, } </s> remove // httpServerBeta is a server for new client. httpServerBeta *http.Server </s> add // httpsServer is the server that handles HTTPS traffic. If it is not nil, // [Web.http3Server] must also not be nil. httpsServer httpsServer forceHTTPS bool </s> remove conf *webConfig forceHTTPS bool httpServer *http.Server // HTTP module httpsServer HTTPSServer // HTTPS module </s> add conf *webConfig // TODO(a.garipov): Refactor all these servers. httpServer *http.Server // httpServerBeta is a server for new client. httpServerBeta *http.Server </s> remove // Web - module object </s> add // Web is the web UI and API server. </s> remove // HTTPSServer - HTTPS Server type HTTPSServer struct { server *http.Server cond *sync.Cond condLock sync.Mutex shutdown bool // if TRUE, don't restart the server enabled bool cert tls.Certificate </s> add // httpsServer contains the data for the HTTPS server. type httpsServer struct { // server is the pre-HTTP/3 HTTPS server. server *http.Server // server3 is the HTTP/3 HTTPS server. If it is not nil, // [httpsServer.server] must also be non-nil. server3 *http3.Server // TODO(a.garipov): Why is there a *sync.Cond here? Remove. cond *sync.Cond condLock sync.Mutex cert tls.Certificate inShutdown bool enabled bool
// newWeb creates a new instance of the web UI and API server. func newWeb(conf *webConfig) (w *Web) { log.Info("web: initializing")
// httpServerBeta is a server for new client. httpServerBeta *http.Server } // newWeb creates a new instance of the web UI and API server. func newWeb(conf *webConfig) (w *Web) { log.Info("web: initializing") // newWeb creates a new instance of the web UI and API server. func newWeb(conf *webConfig) (w *Web) { log.Info("web: initializing") // newWeb creates a new instance of the web UI and API server. func newWeb(conf *webConfig) (w *Web) { log.Info("web: initializing") w := Web{} w.conf = conf clientFS := http.FileServer(http.FS(conf.clientFS))
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/web.go
// CreateWeb - create module func CreateWeb(conf *webConfig) *Web { log.Info("Initialize web module") w := Web{} w.conf = conf clientFS := http.FileServer(http.FS(conf.clientFS)) betaClientFS := http.FileServer(http.FS(conf.clientBetaFS)) // if not configured, redirect / to /install.html, otherwise redirect /install.html to /
</s> remove // CreateWeb - create module func CreateWeb(conf *webConfig) *Web { log.Info("Initialize web module") </s> add // newWeb creates a new instance of the web UI and API server. func newWeb(conf *webConfig) (w *Web) { log.Info("web: initializing") </s> remove // httpServerBeta is a server for new client. httpServerBeta *http.Server </s> add // httpsServer is the server that handles HTTPS traffic. If it is not nil, // [Web.http3Server] must also not be nil. httpsServer httpsServer forceHTTPS bool </s> remove // Web - module object </s> add // Web is the web UI and API server. </s> remove for !web.httpsServer.shutdown { </s> add for !web.httpsServer.inShutdown { </s> remove conf *webConfig forceHTTPS bool httpServer *http.Server // HTTP module httpsServer HTTPSServer // HTTPS module </s> add conf *webConfig // TODO(a.garipov): Refactor all these servers. httpServer *http.Server // httpServerBeta is a server for new client. httpServerBeta *http.Server
w = &Web{ conf: conf, }
// CreateWeb - create module func CreateWeb(conf *webConfig) *Web { log.Info("Initialize web module") w = &Web{ conf: conf, } w = &Web{ conf: conf, } clientFS := http.FileServer(http.FS(conf.clientFS)) betaClientFS := http.FileServer(http.FS(conf.clientBetaFS)) // if not configured, redirect / to /install.html, otherwise redirect /install.html to /
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/web.go
registerControlHandlers() } w.httpsServer.cond = sync.NewCond(&w.httpsServer.condLock) return &w } // WebCheckPortAvailable - check if port is available // BUT: if we are already using this port, no need func WebCheckPortAvailable(port int) bool {
</s> remove // WebCheckPortAvailable - check if port is available // BUT: if we are already using this port, no need func WebCheckPortAvailable(port int) bool { </s> add // webCheckPortAvailable checks if port, which is considered an HTTPS port, is // available, unless the HTTPS server isn't active. // // TODO(a.garipov): Adapt for HTTP/3. func webCheckPortAvailable(port int) (ok bool) { </s> remove if web.httpsServer.shutdown { </s> add if web.httpsServer.inShutdown { </s> remove if web.httpsServer.shutdown { </s> add if web.httpsServer.inShutdown { </s> remove for !web.httpsServer.shutdown { </s> add for !web.httpsServer.inShutdown { </s> remove if !WebCheckPortAvailable(data.PortHTTPS) { </s> add if !webCheckPortAvailable(data.PortHTTPS) {
return w
registerControlHandlers() } w.httpsServer.cond = sync.NewCond(&w.httpsServer.condLock) return w } // WebCheckPortAvailable - check if port is available // BUT: if we are already using this port, no need func WebCheckPortAvailable(port int) bool {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/web.go
w.httpsServer.cond = sync.NewCond(&w.httpsServer.condLock) return &w } // WebCheckPortAvailable - check if port is available // BUT: if we are already using this port, no need func WebCheckPortAvailable(port int) bool { return Context.web.httpsServer.server != nil || aghnet.CheckPort("tcp", config.BindHost, port) == nil } // TLSConfigChanged updates the TLS configuration and restarts the HTTPS server
</s> remove return &w </s> add return w </s> remove log.Debug("Web: applying new TLS configuration") </s> add log.Debug("web: applying new tls configuration") </s> remove if err != nil { const msgFmt = "shutting down http server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) } </s> add if err == nil { return } const msgFmt = "shutting down http server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) } } // shutdownSrv3 shuts srv down and prints error messages to the log. // // TODO(a.garipov): Think of a good way to merge with [shutdownSrv]. func shutdownSrv3(srv *http3.Server) { defer log.OnPanic("") if srv == nil { return } err := srv.Close() if err == nil { return } const msgFmt = "shutting down http/3 server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err)
// webCheckPortAvailable checks if port, which is considered an HTTPS port, is // available, unless the HTTPS server isn't active. // // TODO(a.garipov): Adapt for HTTP/3. func webCheckPortAvailable(port int) (ok bool) {
w.httpsServer.cond = sync.NewCond(&w.httpsServer.condLock) return &w } // webCheckPortAvailable checks if port, which is considered an HTTPS port, is // available, unless the HTTPS server isn't active. // // TODO(a.garipov): Adapt for HTTP/3. func webCheckPortAvailable(port int) (ok bool) { // webCheckPortAvailable checks if port, which is considered an HTTPS port, is // available, unless the HTTPS server isn't active. // // TODO(a.garipov): Adapt for HTTP/3. func webCheckPortAvailable(port int) (ok bool) { // webCheckPortAvailable checks if port, which is considered an HTTPS port, is // available, unless the HTTPS server isn't active. // // TODO(a.garipov): Adapt for HTTP/3. func webCheckPortAvailable(port int) (ok bool) { return Context.web.httpsServer.server != nil || aghnet.CheckPort("tcp", config.BindHost, port) == nil } // TLSConfigChanged updates the TLS configuration and restarts the HTTPS server
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/web.go
// TLSConfigChanged updates the TLS configuration and restarts the HTTPS server // if necessary. func (web *Web) TLSConfigChanged(ctx context.Context, tlsConf tlsConfigSettings) { log.Debug("Web: applying new TLS configuration") web.conf.PortHTTPS = tlsConf.PortHTTPS web.forceHTTPS = (tlsConf.ForceHTTPS && tlsConf.Enabled && tlsConf.PortHTTPS != 0) enabled := tlsConf.Enabled && tlsConf.PortHTTPS != 0 &&
</s> remove // WebCheckPortAvailable - check if port is available // BUT: if we are already using this port, no need func WebCheckPortAvailable(port int) bool { </s> add // webCheckPortAvailable checks if port, which is considered an HTTPS port, is // available, unless the HTTPS server isn't active. // // TODO(a.garipov): Adapt for HTTP/3. func webCheckPortAvailable(port int) (ok bool) { </s> remove // CreateWeb - create module func CreateWeb(conf *webConfig) *Web { log.Info("Initialize web module") </s> add // newWeb creates a new instance of the web UI and API server. func newWeb(conf *webConfig) (w *Web) { log.Info("web: initializing") </s> remove // HTTPSServer - HTTPS Server type HTTPSServer struct { server *http.Server cond *sync.Cond condLock sync.Mutex shutdown bool // if TRUE, don't restart the server enabled bool cert tls.Certificate </s> add // httpsServer contains the data for the HTTPS server. type httpsServer struct { // server is the pre-HTTP/3 HTTPS server. server *http.Server // server3 is the HTTP/3 HTTPS server. If it is not nil, // [httpsServer.server] must also be non-nil. server3 *http3.Server // TODO(a.garipov): Why is there a *sync.Cond here? Remove. cond *sync.Cond condLock sync.Mutex cert tls.Certificate inShutdown bool enabled bool
log.Debug("web: applying new tls configuration")
// TLSConfigChanged updates the TLS configuration and restarts the HTTPS server // if necessary. func (web *Web) TLSConfigChanged(ctx context.Context, tlsConf tlsConfigSettings) { log.Debug("web: applying new tls configuration") web.conf.PortHTTPS = tlsConf.PortHTTPS web.forceHTTPS = (tlsConf.ForceHTTPS && tlsConf.Enabled && tlsConf.PortHTTPS != 0) enabled := tlsConf.Enabled && tlsConf.PortHTTPS != 0 &&
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/web.go
var cancel context.CancelFunc ctx, cancel = context.WithTimeout(ctx, shutdownTimeout) shutdownSrv(ctx, web.httpsServer.server) cancel() } web.httpsServer.enabled = enabled web.httpsServer.cert = cert
</s> remove web.httpsServer.shutdown = true </s> add web.httpsServer.inShutdown = true </s> remove // Web - module object </s> add // Web is the web UI and API server. </s> remove // HTTPSServer - HTTPS Server type HTTPSServer struct { server *http.Server cond *sync.Cond condLock sync.Mutex shutdown bool // if TRUE, don't restart the server enabled bool cert tls.Certificate </s> add // httpsServer contains the data for the HTTPS server. type httpsServer struct { // server is the pre-HTTP/3 HTTPS server. server *http.Server // server3 is the HTTP/3 HTTPS server. If it is not nil, // [httpsServer.server] must also be non-nil. server3 *http3.Server // TODO(a.garipov): Why is there a *sync.Cond here? Remove. cond *sync.Cond condLock sync.Mutex cert tls.Certificate inShutdown bool enabled bool </s> remove var protocols = []string{"udp://", "tcp://", "tls://", "https://", "sdns://", "quic://"} </s> add var protocols = []string{ "h3://", "https://", "quic://", "sdns://", "tcp://", "tls://", "udp://", }
shutdownSrv3(web.httpsServer.server3)
var cancel context.CancelFunc ctx, cancel = context.WithTimeout(ctx, shutdownTimeout) shutdownSrv(ctx, web.httpsServer.server) shutdownSrv3(web.httpsServer.server3) cancel() } web.httpsServer.enabled = enabled web.httpsServer.cert = cert
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/web.go
// for https, we have a separate goroutine loop go web.tlsServerLoop() // this loop is used as an ability to change listening host and/or port for !web.httpsServer.shutdown { printHTTPAddresses(aghhttp.SchemeHTTP) errs := make(chan error, 2) // Use an h2c handler to support unencrypted HTTP/2, e.g. for proxies. hdlr := h2c.NewHandler(withMiddlewares(Context.mux, limitRequestBody), &http2.Server{})
</s> remove j := s.accessListJSON() w.Header().Set("Content-Type", "application/json") err := json.NewEncoder(w).Encode(j) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "encoding response: %s", err) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, s.accessListJSON()) </s> remove // LocalPTRResolvers is a slice of addresses to be used as upstreams for // resolving PTR queries for local addresses. LocalPTRResolvers []string </s> add // ServeHTTP3 defines if HTTP/3 is be allowed for incoming requests. ServeHTTP3 bool // UseHTTP3Upstreams defines if HTTP/3 is be allowed for DNS-over-HTTPS // upstreams. UseHTTP3Upstreams bool </s> remove // WebCheckPortAvailable - check if port is available // BUT: if we are already using this port, no need func WebCheckPortAvailable(port int) bool { </s> add // webCheckPortAvailable checks if port, which is considered an HTTPS port, is // available, unless the HTTPS server isn't active. // // TODO(a.garipov): Adapt for HTTP/3. func webCheckPortAvailable(port int) (ok bool) {
for !web.httpsServer.inShutdown {
// for https, we have a separate goroutine loop go web.tlsServerLoop() // this loop is used as an ability to change listening host and/or port for !web.httpsServer.inShutdown { printHTTPAddresses(aghhttp.SchemeHTTP) errs := make(chan error, 2) // Use an h2c handler to support unencrypted HTTP/2, e.g. for proxies. hdlr := h2c.NewHandler(withMiddlewares(Context.mux, limitRequestBody), &http2.Server{})
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/web.go
func (web *Web) Close(ctx context.Context) { log.Info("stopping http server...") web.httpsServer.cond.L.Lock() web.httpsServer.shutdown = true web.httpsServer.cond.L.Unlock() var cancel context.CancelFunc ctx, cancel = context.WithTimeout(ctx, shutdownTimeout) defer cancel()
</s> remove if web.httpsServer.shutdown { </s> add if web.httpsServer.inShutdown { </s> remove if web.httpsServer.shutdown { </s> add if web.httpsServer.inShutdown { </s> remove log.Debug("Web: applying new TLS configuration") </s> add log.Debug("web: applying new tls configuration")
web.httpsServer.inShutdown = true
func (web *Web) Close(ctx context.Context) { log.Info("stopping http server...") web.httpsServer.cond.L.Lock() web.httpsServer.inShutdown = true web.httpsServer.cond.L.Unlock() var cancel context.CancelFunc ctx, cancel = context.WithTimeout(ctx, shutdownTimeout) defer cancel()
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/web.go
defer cancel() shutdownSrv(ctx, web.httpsServer.server) shutdownSrv(ctx, web.httpServer) shutdownSrv(ctx, web.httpServerBeta) log.Info("stopped http server") }
</s> remove web.httpsServer.shutdown = true </s> add web.httpsServer.inShutdown = true </s> remove if err != nil { const msgFmt = "shutting down http server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) } </s> add if err == nil { return } const msgFmt = "shutting down http server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) } } // shutdownSrv3 shuts srv down and prints error messages to the log. // // TODO(a.garipov): Think of a good way to merge with [shutdownSrv]. func shutdownSrv3(srv *http3.Server) { defer log.OnPanic("") if srv == nil { return } err := srv.Close() if err == nil { return } const msgFmt = "shutting down http/3 server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err)
shutdownSrv3(web.httpsServer.server3)
defer cancel() shutdownSrv(ctx, web.httpsServer.server) shutdownSrv3(web.httpsServer.server3) shutdownSrv(ctx, web.httpServer) shutdownSrv(ctx, web.httpServerBeta) log.Info("stopped http server") }
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/web.go
func (web *Web) tlsServerLoop() { for { web.httpsServer.cond.L.Lock() if web.httpsServer.shutdown { web.httpsServer.cond.L.Unlock() break } // this mechanism doesn't let us through until all conditions are met
</s> remove if web.httpsServer.shutdown { </s> add if web.httpsServer.inShutdown { </s> remove web.httpsServer.shutdown = true </s> add web.httpsServer.inShutdown = true </s> remove return &w </s> add return w </s> remove // WebCheckPortAvailable - check if port is available // BUT: if we are already using this port, no need func WebCheckPortAvailable(port int) bool { </s> add // webCheckPortAvailable checks if port, which is considered an HTTPS port, is // available, unless the HTTPS server isn't active. // // TODO(a.garipov): Adapt for HTTP/3. func webCheckPortAvailable(port int) (ok bool) { </s> remove // CreateWeb - create module func CreateWeb(conf *webConfig) *Web { log.Info("Initialize web module") </s> add // newWeb creates a new instance of the web UI and API server. func newWeb(conf *webConfig) (w *Web) { log.Info("web: initializing")
if web.httpsServer.inShutdown {
func (web *Web) tlsServerLoop() { for { web.httpsServer.cond.L.Lock() if web.httpsServer.inShutdown { web.httpsServer.cond.L.Unlock() break } // this mechanism doesn't let us through until all conditions are met
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/web.go
// this mechanism doesn't let us through until all conditions are met for !web.httpsServer.enabled { // sleep until necessary data is supplied web.httpsServer.cond.Wait() if web.httpsServer.shutdown { web.httpsServer.cond.L.Unlock() return } }
</s> remove if web.httpsServer.shutdown { </s> add if web.httpsServer.inShutdown { </s> remove return &w </s> add return w </s> remove // WebCheckPortAvailable - check if port is available // BUT: if we are already using this port, no need func WebCheckPortAvailable(port int) bool { </s> add // webCheckPortAvailable checks if port, which is considered an HTTPS port, is // available, unless the HTTPS server isn't active. // // TODO(a.garipov): Adapt for HTTP/3. func webCheckPortAvailable(port int) (ok bool) {
if web.httpsServer.inShutdown {
// this mechanism doesn't let us through until all conditions are met for !web.httpsServer.enabled { // sleep until necessary data is supplied web.httpsServer.cond.Wait() if web.httpsServer.inShutdown { web.httpsServer.cond.L.Unlock() return } }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/web.go
} web.httpsServer.cond.L.Unlock() // prepare HTTPS server address := netutil.JoinHostPort(web.conf.BindHost.String(), web.conf.PortHTTPS) web.httpsServer.server = &http.Server{ ErrorLog: log.StdLog("web: https", log.DEBUG), Addr: address, TLSConfig: &tls.Config{ Certificates: []tls.Certificate{web.httpsServer.cert},
</s> remove Addr: address, </s> add Addr: addr, </s> remove // HTTPSServer - HTTPS Server type HTTPSServer struct { server *http.Server cond *sync.Cond condLock sync.Mutex shutdown bool // if TRUE, don't restart the server enabled bool cert tls.Certificate </s> add // httpsServer contains the data for the HTTPS server. type httpsServer struct { // server is the pre-HTTP/3 HTTPS server. server *http.Server // server3 is the HTTP/3 HTTPS server. If it is not nil, // [httpsServer.server] must also be non-nil. server3 *http3.Server // TODO(a.garipov): Why is there a *sync.Cond here? Remove. cond *sync.Cond condLock sync.Mutex cert tls.Certificate inShutdown bool enabled bool </s> remove // WebCheckPortAvailable - check if port is available // BUT: if we are already using this port, no need func WebCheckPortAvailable(port int) bool { </s> add // webCheckPortAvailable checks if port, which is considered an HTTPS port, is // available, unless the HTTPS server isn't active. // // TODO(a.garipov): Adapt for HTTP/3. func webCheckPortAvailable(port int) (ok bool) { </s> remove if web.httpsServer.shutdown { </s> add if web.httpsServer.inShutdown {
addr := netutil.JoinHostPort(web.conf.BindHost.String(), web.conf.PortHTTPS)
} web.httpsServer.cond.L.Unlock() addr := netutil.JoinHostPort(web.conf.BindHost.String(), web.conf.PortHTTPS) addr := netutil.JoinHostPort(web.conf.BindHost.String(), web.conf.PortHTTPS) web.httpsServer.server = &http.Server{ ErrorLog: log.StdLog("web: https", log.DEBUG), Addr: address, TLSConfig: &tls.Config{ Certificates: []tls.Certificate{web.httpsServer.cert},
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/web.go
// prepare HTTPS server address := netutil.JoinHostPort(web.conf.BindHost.String(), web.conf.PortHTTPS) web.httpsServer.server = &http.Server{ ErrorLog: log.StdLog("web: https", log.DEBUG), Addr: address, TLSConfig: &tls.Config{ Certificates: []tls.Certificate{web.httpsServer.cert}, RootCAs: Context.tlsRoots, CipherSuites: aghtls.SaferCipherSuites(), MinVersion: tls.VersionTLS12,
</s> remove // prepare HTTPS server address := netutil.JoinHostPort(web.conf.BindHost.String(), web.conf.PortHTTPS) </s> add addr := netutil.JoinHostPort(web.conf.BindHost.String(), web.conf.PortHTTPS) </s> remove // HTTPSServer - HTTPS Server type HTTPSServer struct { server *http.Server cond *sync.Cond condLock sync.Mutex shutdown bool // if TRUE, don't restart the server enabled bool cert tls.Certificate </s> add // httpsServer contains the data for the HTTPS server. type httpsServer struct { // server is the pre-HTTP/3 HTTPS server. server *http.Server // server3 is the HTTP/3 HTTPS server. If it is not nil, // [httpsServer.server] must also be non-nil. server3 *http3.Server // TODO(a.garipov): Why is there a *sync.Cond here? Remove. cond *sync.Cond condLock sync.Mutex cert tls.Certificate inShutdown bool enabled bool </s> remove // WebCheckPortAvailable - check if port is available // BUT: if we are already using this port, no need func WebCheckPortAvailable(port int) bool { </s> add // webCheckPortAvailable checks if port, which is considered an HTTPS port, is // available, unless the HTTPS server isn't active. // // TODO(a.garipov): Adapt for HTTP/3. func webCheckPortAvailable(port int) (ok bool) { </s> remove log.Debug("Web: applying new TLS configuration") </s> add log.Debug("web: applying new tls configuration")
Addr: addr,
// prepare HTTPS server address := netutil.JoinHostPort(web.conf.BindHost.String(), web.conf.PortHTTPS) web.httpsServer.server = &http.Server{ ErrorLog: log.StdLog("web: https", log.DEBUG), Addr: addr, TLSConfig: &tls.Config{ Certificates: []tls.Certificate{web.httpsServer.cert}, RootCAs: Context.tlsRoots, CipherSuites: aghtls.SaferCipherSuites(), MinVersion: tls.VersionTLS12,
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/web.go
WriteTimeout: web.conf.WriteTimeout, } printHTTPAddresses(aghhttp.SchemeHTTPS) err := web.httpsServer.server.ListenAndServeTLS("", "") if !errors.Is(err, http.ErrServerClosed) { cleanupAlways() log.Fatalf("web: https: %s", err) } }
</s> remove log.Fatal(err) </s> add log.Fatalf("web: https: %s", err) </s> remove if err != http.ErrServerClosed { </s> add if !errors.Is(err, http.ErrServerClosed) { </s> remove pj.Name = u.Name data, err := json.Marshal(pj) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "json.Marshal: %s", err) return </s> add resp := &profileJSON{ Name: u.Name, </s> remove jsonVal, err := json.Marshal(result) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Unable to marshal status json: %s", err, ) return } w.Header().Set("Content-Type", "application/json") _, err = w.Write(jsonVal) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "Couldn't write body: %s", err) } </s> add _ = aghhttp.WriteJSONResponse(w, r, result) </s> remove aghhttp.Error( r, w, http.StatusBadRequest, "Failed to encode 'check_config' JSON data: %s", err, ) </s> add aghhttp.Error(r, w, http.StatusBadRequest, "encoding check_config: %s", err)
if web.conf.serveHTTP3 { go web.mustStartHTTP3(addr) } log.Debug("web: starting https server")
WriteTimeout: web.conf.WriteTimeout, } printHTTPAddresses(aghhttp.SchemeHTTPS) if web.conf.serveHTTP3 { go web.mustStartHTTP3(addr) } log.Debug("web: starting https server") err := web.httpsServer.server.ListenAndServeTLS("", "") if !errors.Is(err, http.ErrServerClosed) { cleanupAlways() log.Fatalf("web: https: %s", err) } }
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/web.go
} printHTTPAddresses(aghhttp.SchemeHTTPS) err := web.httpsServer.server.ListenAndServeTLS("", "") if err != http.ErrServerClosed { cleanupAlways() log.Fatal(err) } } }
</s> remove log.Fatal(err) </s> add log.Fatalf("web: https: %s", err) </s> remove jsonVal, err := json.Marshal(result) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Unable to marshal status json: %s", err, ) return } w.Header().Set("Content-Type", "application/json") _, err = w.Write(jsonVal) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "Couldn't write body: %s", err) } </s> add _ = aghhttp.WriteJSONResponse(w, r, result) </s> remove pj.Name = u.Name data, err := json.Marshal(pj) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "json.Marshal: %s", err) return </s> add resp := &profileJSON{ Name: u.Name, </s> remove if err != nil { const msgFmt = "shutting down http server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) } </s> add if err == nil { return } const msgFmt = "shutting down http server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) } } // shutdownSrv3 shuts srv down and prints error messages to the log. // // TODO(a.garipov): Think of a good way to merge with [shutdownSrv]. func shutdownSrv3(srv *http3.Server) { defer log.OnPanic("") if srv == nil { return } err := srv.Close() if err == nil { return } const msgFmt = "shutting down http/3 server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err)
if !errors.Is(err, http.ErrServerClosed) {
} printHTTPAddresses(aghhttp.SchemeHTTPS) err := web.httpsServer.server.ListenAndServeTLS("", "") if !errors.Is(err, http.ErrServerClosed) { cleanupAlways() log.Fatal(err) } } }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/web.go
printHTTPAddresses(aghhttp.SchemeHTTPS) err := web.httpsServer.server.ListenAndServeTLS("", "") if err != http.ErrServerClosed { cleanupAlways() log.Fatal(err) } } }
</s> remove if err != http.ErrServerClosed { </s> add if !errors.Is(err, http.ErrServerClosed) { </s> remove jsonVal, err := json.Marshal(result) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Unable to marshal status json: %s", err, ) return } w.Header().Set("Content-Type", "application/json") _, err = w.Write(jsonVal) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "Couldn't write body: %s", err) } </s> add _ = aghhttp.WriteJSONResponse(w, r, result) </s> remove pj.Name = u.Name data, err := json.Marshal(pj) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "json.Marshal: %s", err) return </s> add resp := &profileJSON{ Name: u.Name, </s> remove if err != nil { const msgFmt = "shutting down http server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) } </s> add if err == nil { return } const msgFmt = "shutting down http server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err) } } // shutdownSrv3 shuts srv down and prints error messages to the log. // // TODO(a.garipov): Think of a good way to merge with [shutdownSrv]. func shutdownSrv3(srv *http3.Server) { defer log.OnPanic("") if srv == nil { return } err := srv.Close() if err == nil { return } const msgFmt = "shutting down http/3 server %q: %s" if errors.Is(err, context.Canceled) { log.Debug(msgFmt, srv.Addr, err) } else { log.Error(msgFmt, srv.Addr, err)
log.Fatalf("web: https: %s", err)
printHTTPAddresses(aghhttp.SchemeHTTPS) err := web.httpsServer.server.ListenAndServeTLS("", "") if err != http.ErrServerClosed { cleanupAlways() log.Fatalf("web: https: %s", err) } } }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep" ]
Pull request: 3955-doh3 Updates #3955. Squashed commit of the following: commit acfd5ccc29ff03dfae1e51e52649acdf05042d9f Merge: caeac6e5 61bd217e Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 18:00:37 2022 +0300 Merge branch 'master' into 3955-doh3 commit caeac6e5401bcaa95bba8d2b84a943b6c9a5898a Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:54:16 2022 +0300 all: fix server closing; imp docs commit 87396141ff49d48ae54b4184559070e7885bccc7 Author: Ainar Garipov <[email protected]> Date: Mon Oct 3 17:33:39 2022 +0300 all: add doh3 support
https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60
internal/home/web.go
// update Name index if old.Name != c.Name { clients.list[c.Name] = old } // update upstreams cache if old.Name != c.Name {
</s> remove delete(clients.upstreamsCache, name) delete(clients.upstreamsCache, old.Name) </s> add if old.Name != c.Name { delete(clients.upstreamsCache, old.Name) } else { delete(clients.upstreamsCache, c.Name) }
delete(clients.list, old.Name)
// update Name index if old.Name != c.Name { delete(clients.list, old.Name) clients.list[c.Name] = old } // update upstreams cache if old.Name != c.Name {
[ "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
Merge: - clients: fix rename Close #1340 Squashed commit of the following: commit 95f0291c681f98c29f4014b651c159d387301af4 Author: Simon Zolin <[email protected]> Date: Thu Jan 9 18:56:23 2020 +0300 add test commit 293be277e245ff2f430e8c1e9ee3e82dc7da0995 Author: Simon Zolin <[email protected]> Date: Thu Jan 9 16:04:36 2020 +0300 - clients: fix rename
https://github.com/AdguardTeam/AdGuardHome/commit/0cd25cf598096505f9b77c4d0a64bd1bbf08d6fe
home/clients.go
clients.list[c.Name] = old } // update upstreams cache delete(clients.upstreamsCache, name) delete(clients.upstreamsCache, old.Name) *old = c return nil }
</s>
if old.Name != c.Name { delete(clients.upstreamsCache, old.Name) } else { delete(clients.upstreamsCache, c.Name) }
clients.list[c.Name] = old } // update upstreams cache if old.Name != c.Name { delete(clients.upstreamsCache, old.Name) } else { delete(clients.upstreamsCache, c.Name) } if old.Name != c.Name { delete(clients.upstreamsCache, old.Name) } else { delete(clients.upstreamsCache, c.Name) } *old = c return nil }
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Merge: - clients: fix rename Close #1340 Squashed commit of the following: commit 95f0291c681f98c29f4014b651c159d387301af4 Author: Simon Zolin <[email protected]> Date: Thu Jan 9 18:56:23 2020 +0300 add test commit 293be277e245ff2f430e8c1e9ee3e82dc7da0995 Author: Simon Zolin <[email protected]> Date: Thu Jan 9 16:04:36 2020 +0300 - clients: fix rename
https://github.com/AdguardTeam/AdGuardHome/commit/0cd25cf598096505f9b77c4d0a64bd1bbf08d6fe
home/clients.go
c = Client{} c, b = clients.Find("1.1.1.2") assert.True(t, b && c.Name == "client1-renamed" && c.IDs[0] == "1.1.1.2" && c.UseOwnSettings) // failed remove - no such name if clients.Del("client3") { t.Fatalf("Del - no such name") }
</s> remove delete(clients.upstreamsCache, name) delete(clients.upstreamsCache, old.Name) </s> add if old.Name != c.Name { delete(clients.upstreamsCache, old.Name) } else { delete(clients.upstreamsCache, c.Name) }
assert.True(t, clients.list["client1"] == nil)
c = Client{} c, b = clients.Find("1.1.1.2") assert.True(t, b && c.Name == "client1-renamed" && c.IDs[0] == "1.1.1.2" && c.UseOwnSettings) assert.True(t, clients.list["client1"] == nil) // failed remove - no such name if clients.Del("client3") { t.Fatalf("Del - no such name") }
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
Merge: - clients: fix rename Close #1340 Squashed commit of the following: commit 95f0291c681f98c29f4014b651c159d387301af4 Author: Simon Zolin <[email protected]> Date: Thu Jan 9 18:56:23 2020 +0300 add test commit 293be277e245ff2f430e8c1e9ee3e82dc7da0995 Author: Simon Zolin <[email protected]> Date: Thu Jan 9 16:04:36 2020 +0300 - clients: fix rename
https://github.com/AdguardTeam/AdGuardHome/commit/0cd25cf598096505f9b77c4d0a64bd1bbf08d6fe
home/clients_test.go
upstreamAddr := "" if d.Upstream != nil { upstreamAddr = d.Upstream.Address() } s.queryLog.Add(msg, d.Res, res, elapsed, d.Addr, upstreamAddr) } s.updateStats(d, elapsed, *res) s.RUnlock()
</s> remove IP: ip, </s> add IP: ip.String(), </s> remove ip := getIPString(addr) </s> add </s> remove // getIPString is a helper function that extracts IP address from net.Addr func getIPString(addr net.Addr) string { switch addr := addr.(type) { case *net.UDPAddr: return addr.IP.String() case *net.TCPAddr: return addr.IP.String() } return "" } func (l *queryLog) Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, addr net.Addr, upstream string) { </s> add func (l *queryLog) Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, ip net.IP, upstream string) { </s> remove Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, addr net.Addr, upstream string) </s> add Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, ip net.IP, upstream string)
s.queryLog.Add(msg, d.Res, res, elapsed, getIP(d.Addr), upstreamAddr)
upstreamAddr := "" if d.Upstream != nil { upstreamAddr = d.Upstream.Address() } s.queryLog.Add(msg, d.Res, res, elapsed, getIP(d.Addr), upstreamAddr) } s.updateStats(d, elapsed, *res) s.RUnlock()
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
* QueryLog.Add() now receives net.IP, not net.Addr
https://github.com/AdguardTeam/AdGuardHome/commit/0cd6781a9a94bbb0cf1d0bd310fc50d665da4674
dnsforward/dnsforward.go
} func (s *Server) updateStats(d *proxy.DNSContext, elapsed time.Duration, res dnsfilter.Result) { if s.stats == nil { return } e := stats.Entry{}
</s> remove // getIPString is a helper function that extracts IP address from net.Addr func getIPString(addr net.Addr) string { switch addr := addr.(type) { case *net.UDPAddr: return addr.IP.String() case *net.TCPAddr: return addr.IP.String() } return "" } func (l *queryLog) Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, addr net.Addr, upstream string) { </s> add func (l *queryLog) Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, ip net.IP, upstream string) { </s> remove ip := getIPString(addr) </s> add </s> remove s.queryLog.Add(msg, d.Res, res, elapsed, d.Addr, upstreamAddr) </s> add s.queryLog.Add(msg, d.Res, res, elapsed, getIP(d.Addr), upstreamAddr) </s> remove IP: ip, </s> add IP: ip.String(), </s> remove Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, addr net.Addr, upstream string) </s> add Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, ip net.IP, upstream string)
// Get IP address from net.Addr func getIP(addr net.Addr) net.IP { switch addr := addr.(type) { case *net.UDPAddr: return addr.IP case *net.TCPAddr: return addr.IP } return nil }
} // Get IP address from net.Addr func getIP(addr net.Addr) net.IP { switch addr := addr.(type) { case *net.UDPAddr: return addr.IP case *net.TCPAddr: return addr.IP } return nil } func (s *Server) updateStats(d *proxy.DNSContext, elapsed time.Duration, res dnsfilter.Result) { if s.stats == nil { return } e := stats.Entry{}
[ "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
* QueryLog.Add() now receives net.IP, not net.Addr
https://github.com/AdguardTeam/AdGuardHome/commit/0cd6781a9a94bbb0cf1d0bd310fc50d665da4674
dnsforward/dnsforward.go
Elapsed time.Duration Upstream string `json:",omitempty"` // if empty, means it was cached } // getIPString is a helper function that extracts IP address from net.Addr func getIPString(addr net.Addr) string { switch addr := addr.(type) { case *net.UDPAddr: return addr.IP.String() case *net.TCPAddr: return addr.IP.String() } return "" } func (l *queryLog) Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, addr net.Addr, upstream string) { if !l.conf.Enabled { return } if question == nil || len(question.Question) != 1 || len(question.Question[0].Name) == 0 ||
</s> remove Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, addr net.Addr, upstream string) </s> add Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, ip net.IP, upstream string) </s> remove s.queryLog.Add(msg, d.Res, res, elapsed, d.Addr, upstreamAddr) </s> add s.queryLog.Add(msg, d.Res, res, elapsed, getIP(d.Addr), upstreamAddr) </s> remove ip := getIPString(addr) </s> add </s> remove IP: ip, </s> add IP: ip.String(),
func (l *queryLog) Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, ip net.IP, upstream string) {
Elapsed time.Duration Upstream string `json:",omitempty"` // if empty, means it was cached } func (l *queryLog) Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, ip net.IP, upstream string) { func (l *queryLog) Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, ip net.IP, upstream string) { func (l *queryLog) Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, ip net.IP, upstream string) { func (l *queryLog) Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, ip net.IP, upstream string) { func (l *queryLog) Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, ip net.IP, upstream string) { func (l *queryLog) Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, ip net.IP, upstream string) { func (l *queryLog) Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, ip net.IP, upstream string) { func (l *queryLog) Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, ip net.IP, upstream string) { func (l *queryLog) Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, ip net.IP, upstream string) { func (l *queryLog) Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, ip net.IP, upstream string) { func (l *queryLog) Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, ip net.IP, upstream string) { func (l *queryLog) Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, ip net.IP, upstream string) { if !l.conf.Enabled { return } if question == nil || len(question.Question) != 1 || len(question.Question[0].Name) == 0 ||
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
* QueryLog.Add() now receives net.IP, not net.Addr
https://github.com/AdguardTeam/AdGuardHome/commit/0cd6781a9a94bbb0cf1d0bd310fc50d665da4674
querylog/qlog.go
} var a []byte var err error ip := getIPString(addr) if answer != nil { a, err = answer.Pack() if err != nil { log.Printf("failed to pack answer for querylog: %s", err)
</s> remove s.queryLog.Add(msg, d.Res, res, elapsed, d.Addr, upstreamAddr) </s> add s.queryLog.Add(msg, d.Res, res, elapsed, getIP(d.Addr), upstreamAddr) </s> remove // getIPString is a helper function that extracts IP address from net.Addr func getIPString(addr net.Addr) string { switch addr := addr.(type) { case *net.UDPAddr: return addr.IP.String() case *net.TCPAddr: return addr.IP.String() } return "" } func (l *queryLog) Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, addr net.Addr, upstream string) { </s> add func (l *queryLog) Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, ip net.IP, upstream string) { </s> remove IP: ip, </s> add IP: ip.String(), </s> remove Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, addr net.Addr, upstream string) </s> add Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, ip net.IP, upstream string)
} var a []byte var err error if answer != nil { a, err = answer.Pack() if err != nil { log.Printf("failed to pack answer for querylog: %s", err)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
* QueryLog.Add() now receives net.IP, not net.Addr
https://github.com/AdguardTeam/AdGuardHome/commit/0cd6781a9a94bbb0cf1d0bd310fc50d665da4674
querylog/qlog.go
} now := time.Now() entry := logEntry{ IP: ip, Time: now, Answer: a, Result: *result, Elapsed: elapsed,
</s> remove s.queryLog.Add(msg, d.Res, res, elapsed, d.Addr, upstreamAddr) </s> add s.queryLog.Add(msg, d.Res, res, elapsed, getIP(d.Addr), upstreamAddr) </s> remove ip := getIPString(addr) </s> add </s> remove Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, addr net.Addr, upstream string) </s> add Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, ip net.IP, upstream string) </s> remove // getIPString is a helper function that extracts IP address from net.Addr func getIPString(addr net.Addr) string { switch addr := addr.(type) { case *net.UDPAddr: return addr.IP.String() case *net.TCPAddr: return addr.IP.String() } return "" } func (l *queryLog) Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, addr net.Addr, upstream string) { </s> add func (l *queryLog) Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, ip net.IP, upstream string) {
IP: ip.String(),
} now := time.Now() entry := logEntry{ IP: ip.String(), Time: now, Answer: a, Result: *result, Elapsed: elapsed,
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
* QueryLog.Add() now receives net.IP, not net.Addr
https://github.com/AdguardTeam/AdGuardHome/commit/0cd6781a9a94bbb0cf1d0bd310fc50d665da4674
querylog/qlog.go
// Close query log object Close() // Add a log entry Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, addr net.Addr, upstream string) // WriteDiskConfig - write configuration WriteDiskConfig(dc *DiskConfig) }
</s> remove // getIPString is a helper function that extracts IP address from net.Addr func getIPString(addr net.Addr) string { switch addr := addr.(type) { case *net.UDPAddr: return addr.IP.String() case *net.TCPAddr: return addr.IP.String() } return "" } func (l *queryLog) Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, addr net.Addr, upstream string) { </s> add func (l *queryLog) Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, ip net.IP, upstream string) { </s> remove IP: ip, </s> add IP: ip.String(), </s> remove s.queryLog.Add(msg, d.Res, res, elapsed, d.Addr, upstreamAddr) </s> add s.queryLog.Add(msg, d.Res, res, elapsed, getIP(d.Addr), upstreamAddr) </s> remove ip := getIPString(addr) </s> add
Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, ip net.IP, upstream string)
// Close query log object Close() // Add a log entry Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, ip net.IP, upstream string) // WriteDiskConfig - write configuration WriteDiskConfig(dc *DiskConfig) }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
* QueryLog.Add() now receives net.IP, not net.Addr
https://github.com/AdguardTeam/AdGuardHome/commit/0cd6781a9a94bbb0cf1d0bd310fc50d665da4674
querylog/querylog.go
// Package dnsfilter implements a DNS request and response filter. package dnsfilter import ( "fmt" "io/ioutil" "net" "net/http"
</s> remove func TestCheckHostSafeSearchGoogle(t *testing.T) { d := NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() // Slice of google domains googleDomains := []string{"www.google.com", "www.google.im", "www.google.co.in", "www.google.iq", "www.google.is", "www.google.it", "www.google.je"} </s> add // testResolver is a Resolver for tests. type testResolver struct{} // LookupIP implements Resolver interface for *testResolver. func (r *testResolver) LookupIPAddr(_ context.Context, host string) (ips []net.IPAddr, err error) { hash := sha256.Sum256([]byte(host)) addrs := []net.IPAddr{{ IP: net.IP(hash[:4]), Zone: "somezone", }, { IP: net.IP(hash[4:20]), Zone: "somezone", }} return addrs, nil }
"context"
// Package dnsfilter implements a DNS request and response filter. package dnsfilter import ( "context" "fmt" "io/ioutil" "net" "net/http"
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter.go
blockFilters []Filter } // DNSFilter matches hostnames and DNS requests against filtering rules. type DNSFilter struct { rulesStorage *filterlist.RuleStorage filteringEngine *urlfilter.DNSEngine rulesStorageAllow *filterlist.RuleStorage
</s> remove var r Result filters := []Filter{{ ID: 0, Data: []byte("||example.org^\n"), </s> add d := newForTest( &Config{ ParentalEnabled: true, SafeBrowsingEnabled: false, }, []Filter{{ ID: 0, Data: []byte("||example.org^\n"), }}, ) t.Cleanup(d.Close) d.parentalUpstream = &testSbUpstream{ hostname: "pornhub.com", block: true, } d.safeBrowsingUpstream = &testSbUpstream{ hostname: "wmconvirus.narod.ru", block: true, } type testCase struct { name string host string before bool wantReason Reason } testCases := []testCase{{ name: "filters", host: "example.org", before: true, wantReason: FilteredBlockList, }, { name: "parental", host: "pornhub.com", before: true, wantReason: FilteredParental, }, { name: "safebrowsing", host: "wmconvirus.narod.ru", before: false, wantReason: FilteredSafeBrowsing, }, { name: "additional_rules", host: "facebook.com", before: false, wantReason: FilteredBlockedService, </s> remove // not blocked r, _ = d.CheckHost("facebook.com", dns.TypeA, &setts) assert.False(t, r.IsFiltered) // override client settings: </s> add
// Resolver is the interface for net.Resolver to simplify testing. type Resolver interface { // TODO(e.burkov): Replace with LookupIP after upgrading go to v1.15. LookupIPAddr(ctx context.Context, host string) (ips []net.IPAddr, err error) }
blockFilters []Filter } // Resolver is the interface for net.Resolver to simplify testing. type Resolver interface { // TODO(e.burkov): Replace with LookupIP after upgrading go to v1.15. LookupIPAddr(ctx context.Context, host string) (ips []net.IPAddr, err error) } // DNSFilter matches hostnames and DNS requests against filtering rules. type DNSFilter struct { rulesStorage *filterlist.RuleStorage filteringEngine *urlfilter.DNSEngine rulesStorageAllow *filterlist.RuleStorage
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter.go
// Channel for passing data to filters-initializer goroutine filtersInitializerChan chan filtersInitializerParams filtersInitializerLock sync.Mutex } // Filter represents a filter list type Filter struct { ID int64 // auto-assigned when filter is added (see nextFilterID)
</s> remove func TestCheckHostSafeSearchGoogle(t *testing.T) { d := NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() // Slice of google domains googleDomains := []string{"www.google.com", "www.google.im", "www.google.co.in", "www.google.iq", "www.google.is", "www.google.it", "www.google.je"} </s> add // testResolver is a Resolver for tests. type testResolver struct{} // LookupIP implements Resolver interface for *testResolver. func (r *testResolver) LookupIPAddr(_ context.Context, host string) (ips []net.IPAddr, err error) { hash := sha256.Sum256([]byte(host)) addrs := []net.IPAddr{{ IP: net.IP(hash[:4]), Zone: "somezone", }, { IP: net.IP(hash[4:20]), Zone: "somezone", }} return addrs, nil } </s> remove // not matched by white filter, but matched by block filter </s> add // Not matched by white filter, but matched by block filter. </s> remove // matched by white filter </s> add // Matched by white filter.
// resolver only looks up the IP address of the host while safe search. // // TODO(e.burkov): Use upstream that configured in dnsforward instead. resolver Resolver
// Channel for passing data to filters-initializer goroutine filtersInitializerChan chan filtersInitializerParams filtersInitializerLock sync.Mutex // resolver only looks up the IP address of the host while safe search. // // TODO(e.burkov): Use upstream that configured in dnsforward instead. resolver Resolver } // Filter represents a filter list type Filter struct { ID int64 // auto-assigned when filter is added (see nextFilterID)
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter.go
gctx.parentalCache = cache.New(cacheConf) } } d := new(DNSFilter) err := d.initSecurityServices() if err != nil { log.Error("dnsfilter: initialize services: %s", err) return nil
</s> remove if gctx.safebrowsingCache != nil { gctx.safebrowsingCache.Clear() } if gctx.parentalCache != nil { gctx.parentalCache.Clear() } if gctx.safeSearchCache != nil { gctx.safeSearchCache.Clear() </s> add for _, c := range []cache.Cache{ gctx.safebrowsingCache, gctx.parentalCache, gctx.safeSearchCache, } { if c != nil { c.Clear() } </s> remove ip := ips[0] for _, i := range ips { if i.To4() != nil { ip = i </s> add ip := ipAddrs[0].IP for _, ipAddr := range ipAddrs { if ipAddr.IP.To4() != nil { ip = ipAddr.IP </s> remove // TODO this address should be resolved with upstream that was configured in dnsforward ips, err := net.LookupIP(safeHost) </s> add ipAddrs, err := d.resolver.LookupIPAddr(context.Background(), safeHost) </s> remove for _, ip := range ips { if ipv4 := ip.To4(); ipv4 != nil { </s> add for _, ipAddr := range ipAddrs { if ipv4 := ipAddr.IP.To4(); ipv4 != nil { </s> remove ips, err := net.LookupIP(safeDomain) </s> add ipAddrs, err := resolver.LookupIPAddr(context.Background(), safeDomain)
d := &DNSFilter{ resolver: net.DefaultResolver, }
gctx.parentalCache = cache.New(cacheConf) } } d := &DNSFilter{ resolver: net.DefaultResolver, } err := d.initSecurityServices() if err != nil { log.Error("dnsfilter: initialize services: %s", err) return nil
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter.go
package dnsfilter import ( "bytes" "fmt" "net" "testing" "github.com/AdguardTeam/AdGuardHome/internal/testutil"
</s> remove // FILTERING const nl = "\n" const ( blockingRules = `||example.org^` + nl allowlistRules = `||example.org^` + nl + `@@||test.example.org` + nl importantRules = `@@||example.org^` + nl + `||test.example.org^$important` + nl regexRules = `/example\.org/` + nl + `@@||test.example.org^` + nl maskRules = `test*.example.org^` + nl + `exam*.com` + nl dnstypeRules = `||example.org^$dnstype=AAAA` + nl + `@@||test.example.org^` + nl ) var tests = []struct { testname string rules string hostname string isFiltered bool reason Reason dnsType uint16 }{ {"sanity", "||doubleclick.net^", "www.doubleclick.net", true, FilteredBlockList, dns.TypeA}, {"sanity", "||doubleclick.net^", "nodoubleclick.net", false, NotFilteredNotFound, dns.TypeA}, {"sanity", "||doubleclick.net^", "doubleclick.net.ru", false, NotFilteredNotFound, dns.TypeA}, {"sanity", "||doubleclick.net^", "wmconvirus.narod.ru", false, NotFilteredNotFound, dns.TypeA}, {"blocking", blockingRules, "example.org", true, FilteredBlockList, dns.TypeA}, {"blocking", blockingRules, "test.example.org", true, FilteredBlockList, dns.TypeA}, {"blocking", blockingRules, "test.test.example.org", true, FilteredBlockList, dns.TypeA}, {"blocking", blockingRules, "testexample.org", false, NotFilteredNotFound, dns.TypeA}, {"blocking", blockingRules, "onemoreexample.org", false, NotFilteredNotFound, dns.TypeA}, {"allowlist", allowlistRules, "example.org", true, FilteredBlockList, dns.TypeA}, {"allowlist", allowlistRules, "test.example.org", false, NotFilteredAllowList, dns.TypeA}, {"allowlist", allowlistRules, "test.test.example.org", false, NotFilteredAllowList, dns.TypeA}, {"allowlist", allowlistRules, "testexample.org", false, NotFilteredNotFound, dns.TypeA}, {"allowlist", allowlistRules, "onemoreexample.org", false, NotFilteredNotFound, dns.TypeA}, {"important", importantRules, "example.org", false, NotFilteredAllowList, dns.TypeA}, {"important", importantRules, "test.example.org", true, FilteredBlockList, dns.TypeA}, {"important", importantRules, "test.test.example.org", true, FilteredBlockList, dns.TypeA}, {"important", importantRules, "testexample.org", false, NotFilteredNotFound, dns.TypeA}, {"important", importantRules, "onemoreexample.org", false, NotFilteredNotFound, dns.TypeA}, {"regex", regexRules, "example.org", true, FilteredBlockList, dns.TypeA}, {"regex", regexRules, "test.example.org", false, NotFilteredAllowList, dns.TypeA}, {"regex", regexRules, "test.test.example.org", false, NotFilteredAllowList, dns.TypeA}, {"regex", regexRules, "testexample.org", true, FilteredBlockList, dns.TypeA}, {"regex", regexRules, "onemoreexample.org", true, FilteredBlockList, dns.TypeA}, {"mask", maskRules, "test.example.org", true, FilteredBlockList, dns.TypeA}, {"mask", maskRules, "test2.example.org", true, FilteredBlockList, dns.TypeA}, {"mask", maskRules, "example.com", true, FilteredBlockList, dns.TypeA}, {"mask", maskRules, "exampleeee.com", true, FilteredBlockList, dns.TypeA}, {"mask", maskRules, "onemoreexamsite.com", true, FilteredBlockList, dns.TypeA}, {"mask", maskRules, "example.org", false, NotFilteredNotFound, dns.TypeA}, {"mask", maskRules, "testexample.org", false, NotFilteredNotFound, dns.TypeA}, {"mask", maskRules, "example.co.uk", false, NotFilteredNotFound, dns.TypeA}, {"dnstype", dnstypeRules, "onemoreexample.org", false, NotFilteredNotFound, dns.TypeA}, {"dnstype", dnstypeRules, "example.org", false, NotFilteredNotFound, dns.TypeA}, {"dnstype", dnstypeRules, "example.org", true, FilteredBlockList, dns.TypeAAAA}, {"dnstype", dnstypeRules, "test.example.org", false, NotFilteredAllowList, dns.TypeA}, {"dnstype", dnstypeRules, "test.example.org", false, NotFilteredAllowList, dns.TypeAAAA}, } </s> add // Filtering.
"context" "crypto/sha256"
package dnsfilter import ( "bytes" "context" "crypto/sha256" "fmt" "net" "testing" "github.com/AdguardTeam/AdGuardHome/internal/testutil"
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
"testing" "github.com/AdguardTeam/AdGuardHome/internal/testutil" "github.com/AdguardTeam/golibs/log" "github.com/AdguardTeam/urlfilter/rules" "github.com/miekg/dns" "github.com/stretchr/testify/assert"
</s> remove d := DNSFilter{} </s> add d := newForTest(nil, nil) t.Cleanup(d.Close) </s> remove for _, ip := range ips { if ipv4 := ip.To4(); ipv4 != nil { </s> add for _, ipAddr := range ipAddrs { if ipv4 := ipAddr.IP.To4(); ipv4 != nil { </s> remove d.checkMatch(t, "test.wmconvirus.narod.ru") </s> add d.checkMatch(t, "test."+matching)
"github.com/AdguardTeam/golibs/cache"
"testing" "github.com/AdguardTeam/AdGuardHome/internal/testutil" "github.com/AdguardTeam/golibs/cache" "github.com/AdguardTeam/golibs/log" "github.com/AdguardTeam/urlfilter/rules" "github.com/miekg/dns" "github.com/stretchr/testify/assert"
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
} var setts RequestFilteringSettings // HELPERS // SAFE BROWSING // SAFE SEARCH // PARENTAL // FILTERING // BENCHMARKS // HELPERS func purgeCaches() { if gctx.safebrowsingCache != nil { gctx.safebrowsingCache.Clear() }
</s> remove if gctx.safebrowsingCache != nil { gctx.safebrowsingCache.Clear() } if gctx.parentalCache != nil { gctx.parentalCache.Clear() } if gctx.safeSearchCache != nil { gctx.safeSearchCache.Clear() </s> add for _, c := range []cache.Cache{ gctx.safebrowsingCache, gctx.parentalCache, gctx.safeSearchCache, } { if c != nil { c.Clear() } </s> remove // SAFE BROWSING </s> add // Safe Browsing. </s> remove // SAFE SEARCH </s> add // Safe Search. </s> remove d := NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() </s> add d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) </s> remove loopback6 := net.IP{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1} assert.Equal(t, res.Rules[0].IP, loopback6) </s> add assert.Equal(t, res.Rules[0].IP, net.IPv6loopback)
// Helpers.
} var setts RequestFilteringSettings // Helpers. // Helpers. // Helpers. // Helpers. // Helpers. // Helpers. // Helpers. // Helpers. func purgeCaches() { if gctx.safebrowsingCache != nil { gctx.safebrowsingCache.Clear() }
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
// HELPERS func purgeCaches() { if gctx.safebrowsingCache != nil { gctx.safebrowsingCache.Clear() } if gctx.parentalCache != nil { gctx.parentalCache.Clear() } if gctx.safeSearchCache != nil { gctx.safeSearchCache.Clear() } } func NewForTest(c *Config, filters []Filter) *DNSFilter { setts = RequestFilteringSettings{}
</s> remove func NewForTest(c *Config, filters []Filter) *DNSFilter { </s> add func newForTest(c *Config, filters []Filter) *DNSFilter { </s> remove // HELPERS // SAFE BROWSING // SAFE SEARCH // PARENTAL // FILTERING // BENCHMARKS // HELPERS </s> add // Helpers. </s> remove d := new(DNSFilter) </s> add d := &DNSFilter{ resolver: net.DefaultResolver, } </s> remove ip := ips[0] for _, i := range ips { if i.To4() != nil { ip = i </s> add ip := ipAddrs[0].IP for _, ipAddr := range ipAddrs { if ipAddr.IP.To4() != nil { ip = ipAddr.IP </s> remove // blocked by parental r, _ = d.CheckHost("pornhub.com", dns.TypeA, &setts) if !r.IsFiltered || r.Reason != FilteredParental { t.Fatalf("CheckHost FilteredParental") </s> add makeTester := func(tc testCase, before bool) func(t *testing.T) { return func(t *testing.T) { r, _ := d.CheckHost(tc.host, dns.TypeA, &setts) if before { assert.True(t, r.IsFiltered) assert.Equal(t, tc.wantReason, r.Reason) } else { assert.False(t, r.IsFiltered) } }
for _, c := range []cache.Cache{ gctx.safebrowsingCache, gctx.parentalCache, gctx.safeSearchCache, } { if c != nil { c.Clear() }
// HELPERS func purgeCaches() { for _, c := range []cache.Cache{ gctx.safebrowsingCache, gctx.parentalCache, gctx.safeSearchCache, } { if c != nil { c.Clear() } for _, c := range []cache.Cache{ gctx.safebrowsingCache, gctx.parentalCache, gctx.safeSearchCache, } { if c != nil { c.Clear() } for _, c := range []cache.Cache{ gctx.safebrowsingCache, gctx.parentalCache, gctx.safeSearchCache, } { if c != nil { c.Clear() } for _, c := range []cache.Cache{ gctx.safebrowsingCache, gctx.parentalCache, gctx.safeSearchCache, } { if c != nil { c.Clear() } for _, c := range []cache.Cache{ gctx.safebrowsingCache, gctx.parentalCache, gctx.safeSearchCache, } { if c != nil { c.Clear() } for _, c := range []cache.Cache{ gctx.safebrowsingCache, gctx.parentalCache, gctx.safeSearchCache, } { if c != nil { c.Clear() } for _, c := range []cache.Cache{ gctx.safebrowsingCache, gctx.parentalCache, gctx.safeSearchCache, } { if c != nil { c.Clear() } for _, c := range []cache.Cache{ gctx.safebrowsingCache, gctx.parentalCache, gctx.safeSearchCache, } { if c != nil { c.Clear() } } } func NewForTest(c *Config, filters []Filter) *DNSFilter { setts = RequestFilteringSettings{}
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
gctx.safeSearchCache.Clear() } } func NewForTest(c *Config, filters []Filter) *DNSFilter { setts = RequestFilteringSettings{} setts.FilteringEnabled = true if c != nil { c.SafeBrowsingCacheSize = 10000 c.ParentalCacheSize = 10000
</s> remove if gctx.safebrowsingCache != nil { gctx.safebrowsingCache.Clear() } if gctx.parentalCache != nil { gctx.parentalCache.Clear() } if gctx.safeSearchCache != nil { gctx.safeSearchCache.Clear() </s> add for _, c := range []cache.Cache{ gctx.safebrowsingCache, gctx.parentalCache, gctx.safeSearchCache, } { if c != nil { c.Clear() } </s> remove // CLIENT SETTINGS </s> add // Client Settings. </s> remove ip := ips[0] for _, i := range ips { if i.To4() != nil { ip = i </s> add ip := ipAddrs[0].IP for _, ipAddr := range ipAddrs { if ipAddr.IP.To4() != nil { ip = ipAddr.IP </s> remove d := NewForTest(&Config{ParentalEnabled: true, SafeBrowsingEnabled: false}, filters) defer d.Close() // no client settings: // blocked by filters r, _ = d.CheckHost("example.org", dns.TypeA, &setts) if !r.IsFiltered || r.Reason != FilteredBlockList { t.Fatalf("CheckHost FilteredBlockList") } </s> add </s> remove d := new(DNSFilter) </s> add d := &DNSFilter{ resolver: net.DefaultResolver, }
func newForTest(c *Config, filters []Filter) *DNSFilter {
gctx.safeSearchCache.Clear() } } func newForTest(c *Config, filters []Filter) *DNSFilter { setts = RequestFilteringSettings{} setts.FilteringEnabled = true if c != nil { c.SafeBrowsingCacheSize = 10000 c.ParentalCacheSize = 10000
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
func (d *DNSFilter) checkMatch(t *testing.T, hostname string) { t.Helper() res, err := d.CheckHost(hostname, dns.TypeA, &setts) if err != nil { t.Errorf("Error while matching host %s: %s", hostname, err) } if !res.IsFiltered { t.Errorf("Expected hostname %s to match", hostname) } } func (d *DNSFilter) checkMatchIP(t *testing.T, hostname, ip string, qtype uint16) { t.Helper()
</s> remove if err != nil { t.Errorf("Error while matching host %s: %s", hostname, err) } if !res.IsFiltered { t.Errorf("Expected hostname %s to match", hostname) } if len(res.Rules) == 0 { t.Errorf("Expected result to have rules") return } r := res.Rules[0] if r.IP == nil || r.IP.String() != ip { t.Errorf("Expected ip %s to match, actual: %v", ip, r.IP) </s> add assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Truef(t, res.IsFiltered, "Expected hostname %s to match", hostname) if assert.NotEmpty(t, res.Rules, "Expected result to have rules") { r := res.Rules[0] assert.NotNilf(t, r.IP, "Expected ip %s to match, actual: %v", ip, r.IP) assert.Equalf(t, ip, r.IP.String(), "Expected ip %s to match, actual: %v", ip, r.IP) </s> remove if err != nil { t.Errorf("Error while matching host %s: %s", hostname, err) } if res.IsFiltered { t.Errorf("Expected hostname %s to not match", hostname) } </s> add assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Falsef(t, res.IsFiltered, "Expected hostname %s to not match", hostname) </s> remove hostname := "wmconvirus.narod.ru" res, err := d.CheckHost(hostname, dns.TypeA, &setts) if err != nil { b.Errorf("Error while matching host %s: %s", hostname, err) } if !res.IsFiltered { b.Errorf("Expected hostname %s to match", hostname) } </s> add res, err := d.CheckHost(blocked, dns.TypeA, &setts) assert.Nilf(b, err, "Error while matching host %s: %s", blocked, err) assert.True(b, res.IsFiltered, "Expected hostname %s to match", blocked) </s> remove hostname := "wmconvirus.narod.ru" res, err := d.CheckHost(hostname, dns.TypeA, &setts) if err != nil { b.Errorf("Error while matching host %s: %s", hostname, err) } if !res.IsFiltered { b.Errorf("Expected hostname %s to match", hostname) } </s> add res, err := d.CheckHost(blocked, dns.TypeA, &setts) assert.Nilf(b, err, "Error while matching host %s: %s", blocked, err) assert.True(b, res.IsFiltered, "Expected hostname %s to match", blocked) </s> remove d := NewForTest(&Config{SafeBrowsingEnabled: true}, nil) defer d.Close() </s> add d := newForTest(&Config{SafeBrowsingEnabled: true}, nil) b.Cleanup(d.Close) blocked := "wmconvirus.narod.ru" d.safeBrowsingUpstream = &testSbUpstream{ hostname: blocked, block: true, }
assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Truef(t, res.IsFiltered, "Expected hostname %s to match", hostname)
func (d *DNSFilter) checkMatch(t *testing.T, hostname string) { t.Helper() res, err := d.CheckHost(hostname, dns.TypeA, &setts) assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Truef(t, res.IsFiltered, "Expected hostname %s to match", hostname) assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Truef(t, res.IsFiltered, "Expected hostname %s to match", hostname) assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Truef(t, res.IsFiltered, "Expected hostname %s to match", hostname) assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Truef(t, res.IsFiltered, "Expected hostname %s to match", hostname) assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Truef(t, res.IsFiltered, "Expected hostname %s to match", hostname) assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Truef(t, res.IsFiltered, "Expected hostname %s to match", hostname) } func (d *DNSFilter) checkMatchIP(t *testing.T, hostname, ip string, qtype uint16) { t.Helper()
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
func (d *DNSFilter) checkMatchIP(t *testing.T, hostname, ip string, qtype uint16) { t.Helper() res, err := d.CheckHost(hostname, qtype, &setts) if err != nil { t.Errorf("Error while matching host %s: %s", hostname, err) } if !res.IsFiltered { t.Errorf("Expected hostname %s to match", hostname) } if len(res.Rules) == 0 { t.Errorf("Expected result to have rules") return } r := res.Rules[0] if r.IP == nil || r.IP.String() != ip { t.Errorf("Expected ip %s to match, actual: %v", ip, r.IP) } } func (d *DNSFilter) checkMatchEmpty(t *testing.T, hostname string) { t.Helper()
</s> remove if err != nil { t.Errorf("Error while matching host %s: %s", hostname, err) } if !res.IsFiltered { t.Errorf("Expected hostname %s to match", hostname) } </s> add assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Truef(t, res.IsFiltered, "Expected hostname %s to match", hostname) </s> remove if err != nil { t.Errorf("Error while matching host %s: %s", hostname, err) } if res.IsFiltered { t.Errorf("Expected hostname %s to not match", hostname) } </s> add assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Falsef(t, res.IsFiltered, "Expected hostname %s to not match", hostname) </s> remove hostname := "wmconvirus.narod.ru" res, err := d.CheckHost(hostname, dns.TypeA, &setts) if err != nil { b.Errorf("Error while matching host %s: %s", hostname, err) } if !res.IsFiltered { b.Errorf("Expected hostname %s to match", hostname) } </s> add res, err := d.CheckHost(blocked, dns.TypeA, &setts) assert.Nilf(b, err, "Error while matching host %s: %s", blocked, err) assert.True(b, res.IsFiltered, "Expected hostname %s to match", blocked) </s> remove hostname := "wmconvirus.narod.ru" res, err := d.CheckHost(hostname, dns.TypeA, &setts) if err != nil { b.Errorf("Error while matching host %s: %s", hostname, err) } if !res.IsFiltered { b.Errorf("Expected hostname %s to match", hostname) } </s> add res, err := d.CheckHost(blocked, dns.TypeA, &setts) assert.Nilf(b, err, "Error while matching host %s: %s", blocked, err) assert.True(b, res.IsFiltered, "Expected hostname %s to match", blocked) </s> remove ip := ips[0] for _, i := range ips { if i.To4() != nil { ip = i </s> add ip := ipAddrs[0].IP for _, ipAddr := range ipAddrs { if ipAddr.IP.To4() != nil { ip = ipAddr.IP
assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Truef(t, res.IsFiltered, "Expected hostname %s to match", hostname) if assert.NotEmpty(t, res.Rules, "Expected result to have rules") { r := res.Rules[0] assert.NotNilf(t, r.IP, "Expected ip %s to match, actual: %v", ip, r.IP) assert.Equalf(t, ip, r.IP.String(), "Expected ip %s to match, actual: %v", ip, r.IP)
func (d *DNSFilter) checkMatchIP(t *testing.T, hostname, ip string, qtype uint16) { t.Helper() res, err := d.CheckHost(hostname, qtype, &setts) assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Truef(t, res.IsFiltered, "Expected hostname %s to match", hostname) if assert.NotEmpty(t, res.Rules, "Expected result to have rules") { r := res.Rules[0] assert.NotNilf(t, r.IP, "Expected ip %s to match, actual: %v", ip, r.IP) assert.Equalf(t, ip, r.IP.String(), "Expected ip %s to match, actual: %v", ip, r.IP) assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Truef(t, res.IsFiltered, "Expected hostname %s to match", hostname) if assert.NotEmpty(t, res.Rules, "Expected result to have rules") { r := res.Rules[0] assert.NotNilf(t, r.IP, "Expected ip %s to match, actual: %v", ip, r.IP) assert.Equalf(t, ip, r.IP.String(), "Expected ip %s to match, actual: %v", ip, r.IP) assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Truef(t, res.IsFiltered, "Expected hostname %s to match", hostname) if assert.NotEmpty(t, res.Rules, "Expected result to have rules") { r := res.Rules[0] assert.NotNilf(t, r.IP, "Expected ip %s to match, actual: %v", ip, r.IP) assert.Equalf(t, ip, r.IP.String(), "Expected ip %s to match, actual: %v", ip, r.IP) assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Truef(t, res.IsFiltered, "Expected hostname %s to match", hostname) if assert.NotEmpty(t, res.Rules, "Expected result to have rules") { r := res.Rules[0] assert.NotNilf(t, r.IP, "Expected ip %s to match, actual: %v", ip, r.IP) assert.Equalf(t, ip, r.IP.String(), "Expected ip %s to match, actual: %v", ip, r.IP) assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Truef(t, res.IsFiltered, "Expected hostname %s to match", hostname) if assert.NotEmpty(t, res.Rules, "Expected result to have rules") { r := res.Rules[0] assert.NotNilf(t, r.IP, "Expected ip %s to match, actual: %v", ip, r.IP) assert.Equalf(t, ip, r.IP.String(), "Expected ip %s to match, actual: %v", ip, r.IP) assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Truef(t, res.IsFiltered, "Expected hostname %s to match", hostname) if assert.NotEmpty(t, res.Rules, "Expected result to have rules") { r := res.Rules[0] assert.NotNilf(t, r.IP, "Expected ip %s to match, actual: %v", ip, r.IP) assert.Equalf(t, ip, r.IP.String(), "Expected ip %s to match, actual: %v", ip, r.IP) assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Truef(t, res.IsFiltered, "Expected hostname %s to match", hostname) if assert.NotEmpty(t, res.Rules, "Expected result to have rules") { r := res.Rules[0] assert.NotNilf(t, r.IP, "Expected ip %s to match, actual: %v", ip, r.IP) assert.Equalf(t, ip, r.IP.String(), "Expected ip %s to match, actual: %v", ip, r.IP) assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Truef(t, res.IsFiltered, "Expected hostname %s to match", hostname) if assert.NotEmpty(t, res.Rules, "Expected result to have rules") { r := res.Rules[0] assert.NotNilf(t, r.IP, "Expected ip %s to match, actual: %v", ip, r.IP) assert.Equalf(t, ip, r.IP.String(), "Expected ip %s to match, actual: %v", ip, r.IP) assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Truef(t, res.IsFiltered, "Expected hostname %s to match", hostname) if assert.NotEmpty(t, res.Rules, "Expected result to have rules") { r := res.Rules[0] assert.NotNilf(t, r.IP, "Expected ip %s to match, actual: %v", ip, r.IP) assert.Equalf(t, ip, r.IP.String(), "Expected ip %s to match, actual: %v", ip, r.IP) assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Truef(t, res.IsFiltered, "Expected hostname %s to match", hostname) if assert.NotEmpty(t, res.Rules, "Expected result to have rules") { r := res.Rules[0] assert.NotNilf(t, r.IP, "Expected ip %s to match, actual: %v", ip, r.IP) assert.Equalf(t, ip, r.IP.String(), "Expected ip %s to match, actual: %v", ip, r.IP) assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Truef(t, res.IsFiltered, "Expected hostname %s to match", hostname) if assert.NotEmpty(t, res.Rules, "Expected result to have rules") { r := res.Rules[0] assert.NotNilf(t, r.IP, "Expected ip %s to match, actual: %v", ip, r.IP) assert.Equalf(t, ip, r.IP.String(), "Expected ip %s to match, actual: %v", ip, r.IP) assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Truef(t, res.IsFiltered, "Expected hostname %s to match", hostname) if assert.NotEmpty(t, res.Rules, "Expected result to have rules") { r := res.Rules[0] assert.NotNilf(t, r.IP, "Expected ip %s to match, actual: %v", ip, r.IP) assert.Equalf(t, ip, r.IP.String(), "Expected ip %s to match, actual: %v", ip, r.IP) assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Truef(t, res.IsFiltered, "Expected hostname %s to match", hostname) if assert.NotEmpty(t, res.Rules, "Expected result to have rules") { r := res.Rules[0] assert.NotNilf(t, r.IP, "Expected ip %s to match, actual: %v", ip, r.IP) assert.Equalf(t, ip, r.IP.String(), "Expected ip %s to match, actual: %v", ip, r.IP) assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Truef(t, res.IsFiltered, "Expected hostname %s to match", hostname) if assert.NotEmpty(t, res.Rules, "Expected result to have rules") { r := res.Rules[0] assert.NotNilf(t, r.IP, "Expected ip %s to match, actual: %v", ip, r.IP) assert.Equalf(t, ip, r.IP.String(), "Expected ip %s to match, actual: %v", ip, r.IP) assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Truef(t, res.IsFiltered, "Expected hostname %s to match", hostname) if assert.NotEmpty(t, res.Rules, "Expected result to have rules") { r := res.Rules[0] assert.NotNilf(t, r.IP, "Expected ip %s to match, actual: %v", ip, r.IP) assert.Equalf(t, ip, r.IP.String(), "Expected ip %s to match, actual: %v", ip, r.IP) assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Truef(t, res.IsFiltered, "Expected hostname %s to match", hostname) if assert.NotEmpty(t, res.Rules, "Expected result to have rules") { r := res.Rules[0] assert.NotNilf(t, r.IP, "Expected ip %s to match, actual: %v", ip, r.IP) assert.Equalf(t, ip, r.IP.String(), "Expected ip %s to match, actual: %v", ip, r.IP) assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Truef(t, res.IsFiltered, "Expected hostname %s to match", hostname) if assert.NotEmpty(t, res.Rules, "Expected result to have rules") { r := res.Rules[0] assert.NotNilf(t, r.IP, "Expected ip %s to match, actual: %v", ip, r.IP) assert.Equalf(t, ip, r.IP.String(), "Expected ip %s to match, actual: %v", ip, r.IP) } } func (d *DNSFilter) checkMatchEmpty(t *testing.T, hostname string) { t.Helper()
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
func (d *DNSFilter) checkMatchEmpty(t *testing.T, hostname string) { t.Helper() res, err := d.CheckHost(hostname, dns.TypeA, &setts) if err != nil { t.Errorf("Error while matching host %s: %s", hostname, err) } if res.IsFiltered { t.Errorf("Expected hostname %s to not match", hostname) } } func TestEtcHostsMatching(t *testing.T) { addr := "216.239.38.120" addr6 := "::1"
</s> remove if err != nil { t.Errorf("Error while matching host %s: %s", hostname, err) } if !res.IsFiltered { t.Errorf("Expected hostname %s to match", hostname) } </s> add assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Truef(t, res.IsFiltered, "Expected hostname %s to match", hostname) </s> remove if err != nil { t.Errorf("Error while matching host %s: %s", hostname, err) } if !res.IsFiltered { t.Errorf("Expected hostname %s to match", hostname) } if len(res.Rules) == 0 { t.Errorf("Expected result to have rules") return } r := res.Rules[0] if r.IP == nil || r.IP.String() != ip { t.Errorf("Expected ip %s to match, actual: %v", ip, r.IP) </s> add assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Truef(t, res.IsFiltered, "Expected hostname %s to match", hostname) if assert.NotEmpty(t, res.Rules, "Expected result to have rules") { r := res.Rules[0] assert.NotNilf(t, r.IP, "Expected ip %s to match, actual: %v", ip, r.IP) assert.Equalf(t, ip, r.IP.String(), "Expected ip %s to match, actual: %v", ip, r.IP) </s> remove hostname := "wmconvirus.narod.ru" res, err := d.CheckHost(hostname, dns.TypeA, &setts) if err != nil { b.Errorf("Error while matching host %s: %s", hostname, err) } if !res.IsFiltered { b.Errorf("Expected hostname %s to match", hostname) } </s> add res, err := d.CheckHost(blocked, dns.TypeA, &setts) assert.Nilf(b, err, "Error while matching host %s: %s", blocked, err) assert.True(b, res.IsFiltered, "Expected hostname %s to match", blocked) </s> remove hostname := "wmconvirus.narod.ru" res, err := d.CheckHost(hostname, dns.TypeA, &setts) if err != nil { b.Errorf("Error while matching host %s: %s", hostname, err) } if !res.IsFiltered { b.Errorf("Expected hostname %s to match", hostname) } </s> add res, err := d.CheckHost(blocked, dns.TypeA, &setts) assert.Nilf(b, err, "Error while matching host %s: %s", blocked, err) assert.True(b, res.IsFiltered, "Expected hostname %s to match", blocked) </s> remove d := NewForTest(&Config{SafeBrowsingEnabled: true}, nil) defer d.Close() </s> add d := newForTest(&Config{SafeBrowsingEnabled: true}, nil) b.Cleanup(d.Close) blocked := "wmconvirus.narod.ru" d.safeBrowsingUpstream = &testSbUpstream{ hostname: blocked, block: true, }
assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Falsef(t, res.IsFiltered, "Expected hostname %s to not match", hostname)
func (d *DNSFilter) checkMatchEmpty(t *testing.T, hostname string) { t.Helper() res, err := d.CheckHost(hostname, dns.TypeA, &setts) assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Falsef(t, res.IsFiltered, "Expected hostname %s to not match", hostname) assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Falsef(t, res.IsFiltered, "Expected hostname %s to not match", hostname) assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Falsef(t, res.IsFiltered, "Expected hostname %s to not match", hostname) assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Falsef(t, res.IsFiltered, "Expected hostname %s to not match", hostname) assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Falsef(t, res.IsFiltered, "Expected hostname %s to not match", hostname) assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Falsef(t, res.IsFiltered, "Expected hostname %s to not match", hostname) } func TestEtcHostsMatching(t *testing.T) { addr := "216.239.38.120" addr6 := "::1"
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
addr, addr6) filters := []Filter{{ ID: 0, Data: []byte(text), }} d := NewForTest(nil, filters) defer d.Close() d.checkMatchIP(t, "google.com", addr, dns.TypeA) d.checkMatchIP(t, "www.google.com", addr, dns.TypeA) d.checkMatchEmpty(t, "subdomain.google.com") d.checkMatchEmpty(t, "example.org")
</s> remove // IPv4 </s> add // IPv4 match. </s> remove d := NewForTest(nil, filters) </s> add d := newForTest(nil, filters) </s> remove defer d.Close() </s> add t.Cleanup(d.Close) </s> remove d := NewForTest(&Config{ParentalEnabled: true, SafeBrowsingEnabled: false}, filters) defer d.Close() // no client settings: // blocked by filters r, _ = d.CheckHost("example.org", dns.TypeA, &setts) if !r.IsFiltered || r.Reason != FilteredBlockList { t.Fatalf("CheckHost FilteredBlockList") } </s> add </s> remove // Check behaviour without any per-client settings, // then apply per-client settings and check behaviour once again </s> add
d := newForTest(nil, filters) t.Cleanup(d.Close)
addr, addr6) filters := []Filter{{ ID: 0, Data: []byte(text), }} d := newForTest(nil, filters) t.Cleanup(d.Close) d := newForTest(nil, filters) t.Cleanup(d.Close) d.checkMatchIP(t, "google.com", addr, dns.TypeA) d.checkMatchIP(t, "www.google.com", addr, dns.TypeA) d.checkMatchEmpty(t, "subdomain.google.com") d.checkMatchEmpty(t, "example.org")
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
d.checkMatchIP(t, "www.google.com", addr, dns.TypeA) d.checkMatchEmpty(t, "subdomain.google.com") d.checkMatchEmpty(t, "example.org") // IPv4 d.checkMatchIP(t, "block.com", "0.0.0.0", dns.TypeA) // ...but empty IPv6 res, err := d.CheckHost("block.com", dns.TypeAAAA, &setts) assert.Nil(t, err)
</s> remove // ...but empty IPv6 </s> add // Empty IPv6. </s> remove d := NewForTest(nil, filters) defer d.Close() </s> add d := newForTest(nil, filters) t.Cleanup(d.Close) </s> remove // IPv6 </s> add // IPv6 match. </s> remove // ...but empty IPv4 </s> add // Empty IPv4. </s> remove loopback4 := net.IP{0, 0, 0, 1} assert.Equal(t, res.Rules[0].IP, loopback4) </s> add assert.Equal(t, res.Rules[0].IP, net.IP{0, 0, 0, 1})
// IPv4 match.
d.checkMatchIP(t, "www.google.com", addr, dns.TypeA) d.checkMatchEmpty(t, "subdomain.google.com") d.checkMatchEmpty(t, "example.org") // IPv4 match. d.checkMatchIP(t, "block.com", "0.0.0.0", dns.TypeA) // ...but empty IPv6 res, err := d.CheckHost("block.com", dns.TypeAAAA, &setts) assert.Nil(t, err)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
// IPv4 d.checkMatchIP(t, "block.com", "0.0.0.0", dns.TypeA) // ...but empty IPv6 res, err := d.CheckHost("block.com", dns.TypeAAAA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) if assert.Len(t, res.Rules, 1) { assert.Equal(t, "0.0.0.0 block.com", res.Rules[0].Text)
</s> remove // IPv4 </s> add // IPv4 match. </s> remove // ...but empty IPv4 </s> add // Empty IPv4. </s> remove // IPv6 </s> add // IPv6 match. </s> remove loopback4 := net.IP{0, 0, 0, 1} assert.Equal(t, res.Rules[0].IP, loopback4) </s> add assert.Equal(t, res.Rules[0].IP, net.IP{0, 0, 0, 1}) </s> remove // 2 IPv4 (return only the first one) </s> add // Two IPv4, the first one returned.
// Empty IPv6.
// IPv4 d.checkMatchIP(t, "block.com", "0.0.0.0", dns.TypeA) // Empty IPv6. res, err := d.CheckHost("block.com", dns.TypeAAAA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) if assert.Len(t, res.Rules, 1) { assert.Equal(t, "0.0.0.0 block.com", res.Rules[0].Text)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
assert.Equal(t, "0.0.0.0 block.com", res.Rules[0].Text) assert.Empty(t, res.Rules[0].IP) } // IPv6 d.checkMatchIP(t, "ipv6.com", addr6, dns.TypeAAAA) // ...but empty IPv4 res, err = d.CheckHost("ipv6.com", dns.TypeA, &setts) assert.Nil(t, err)
</s> remove // ...but empty IPv4 </s> add // Empty IPv4. </s> remove // ...but empty IPv6 </s> add // Empty IPv6. </s> remove // IPv4 </s> add // IPv4 match. </s> remove // 2 IPv4 (return only the first one) </s> add // Two IPv4, the first one returned. </s> remove loopback4 := net.IP{0, 0, 0, 1} assert.Equal(t, res.Rules[0].IP, loopback4) </s> add assert.Equal(t, res.Rules[0].IP, net.IP{0, 0, 0, 1})
// IPv6 match.
assert.Equal(t, "0.0.0.0 block.com", res.Rules[0].Text) assert.Empty(t, res.Rules[0].IP) } // IPv6 match. d.checkMatchIP(t, "ipv6.com", addr6, dns.TypeAAAA) // ...but empty IPv4 res, err = d.CheckHost("ipv6.com", dns.TypeA, &setts) assert.Nil(t, err)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
// IPv6 d.checkMatchIP(t, "ipv6.com", addr6, dns.TypeAAAA) // ...but empty IPv4 res, err = d.CheckHost("ipv6.com", dns.TypeA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) if assert.Len(t, res.Rules, 1) { assert.Equal(t, "::1 ipv6.com", res.Rules[0].Text)
</s> remove // IPv6 </s> add // IPv6 match. </s> remove // ...but empty IPv6 </s> add // Empty IPv6. </s> remove // 2 IPv4 (return only the first one) </s> add // Two IPv4, the first one returned. </s> remove // IPv4 </s> add // IPv4 match. </s> remove // not matched by white filter, but matched by block filter </s> add // Not matched by white filter, but matched by block filter.
// Empty IPv4.
// IPv6 d.checkMatchIP(t, "ipv6.com", addr6, dns.TypeAAAA) // Empty IPv4. res, err = d.CheckHost("ipv6.com", dns.TypeA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) if assert.Len(t, res.Rules, 1) { assert.Equal(t, "::1 ipv6.com", res.Rules[0].Text)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
assert.Equal(t, "::1 ipv6.com", res.Rules[0].Text) assert.Empty(t, res.Rules[0].IP) } // 2 IPv4 (return only the first one) res, err = d.CheckHost("host2", dns.TypeA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) if assert.Len(t, res.Rules, 1) { loopback4 := net.IP{0, 0, 0, 1}
</s> remove loopback4 := net.IP{0, 0, 0, 1} assert.Equal(t, res.Rules[0].IP, loopback4) </s> add assert.Equal(t, res.Rules[0].IP, net.IP{0, 0, 0, 1}) </s> remove // ...and 1 IPv6 address </s> add // One IPv6 address. </s> remove loopback6 := net.IP{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1} assert.Equal(t, res.Rules[0].IP, loopback6) </s> add assert.Equal(t, res.Rules[0].IP, net.IPv6loopback) </s> remove // ...but empty IPv4 </s> add // Empty IPv4. </s> remove // not matched by white filter, but matched by block filter </s> add // Not matched by white filter, but matched by block filter.
// Two IPv4, the first one returned.
assert.Equal(t, "::1 ipv6.com", res.Rules[0].Text) assert.Empty(t, res.Rules[0].IP) } // Two IPv4, the first one returned. res, err = d.CheckHost("host2", dns.TypeA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) if assert.Len(t, res.Rules, 1) { loopback4 := net.IP{0, 0, 0, 1}
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
res, err = d.CheckHost("host2", dns.TypeA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) if assert.Len(t, res.Rules, 1) { loopback4 := net.IP{0, 0, 0, 1} assert.Equal(t, res.Rules[0].IP, loopback4) } // ...and 1 IPv6 address res, err = d.CheckHost("host2", dns.TypeAAAA, &setts) assert.Nil(t, err)
</s> remove // ...and 1 IPv6 address </s> add // One IPv6 address. </s> remove loopback6 := net.IP{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1} assert.Equal(t, res.Rules[0].IP, loopback6) </s> add assert.Equal(t, res.Rules[0].IP, net.IPv6loopback) </s> remove // 2 IPv4 (return only the first one) </s> add // Two IPv4, the first one returned. </s> remove // not matched by white filter, but matched by block filter </s> add // Not matched by white filter, but matched by block filter. </s> remove // ...but empty IPv6 </s> add // Empty IPv6.
assert.Equal(t, res.Rules[0].IP, net.IP{0, 0, 0, 1})
res, err = d.CheckHost("host2", dns.TypeA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) if assert.Len(t, res.Rules, 1) { assert.Equal(t, res.Rules[0].IP, net.IP{0, 0, 0, 1}) assert.Equal(t, res.Rules[0].IP, net.IP{0, 0, 0, 1}) } // ...and 1 IPv6 address res, err = d.CheckHost("host2", dns.TypeAAAA, &setts) assert.Nil(t, err)
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
loopback4 := net.IP{0, 0, 0, 1} assert.Equal(t, res.Rules[0].IP, loopback4) } // ...and 1 IPv6 address res, err = d.CheckHost("host2", dns.TypeAAAA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) if assert.Len(t, res.Rules, 1) { loopback6 := net.IP{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
</s> remove loopback4 := net.IP{0, 0, 0, 1} assert.Equal(t, res.Rules[0].IP, loopback4) </s> add assert.Equal(t, res.Rules[0].IP, net.IP{0, 0, 0, 1}) </s> remove loopback6 := net.IP{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1} assert.Equal(t, res.Rules[0].IP, loopback6) </s> add assert.Equal(t, res.Rules[0].IP, net.IPv6loopback) </s> remove // 2 IPv4 (return only the first one) </s> add // Two IPv4, the first one returned. </s> remove f := NewForTest(nil, []Filter{{ID: 0, Data: []byte(text)}}) </s> add f := newForTest(nil, []Filter{{ID: 0, Data: []byte(text)}}) </s> remove d := DNSFilter{} </s> add d := newForTest(nil, nil) t.Cleanup(d.Close)
// One IPv6 address.
loopback4 := net.IP{0, 0, 0, 1} assert.Equal(t, res.Rules[0].IP, loopback4) } // One IPv6 address. res, err = d.CheckHost("host2", dns.TypeAAAA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) if assert.Len(t, res.Rules, 1) { loopback6 := net.IP{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
res, err = d.CheckHost("host2", dns.TypeAAAA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) if assert.Len(t, res.Rules, 1) { loopback6 := net.IP{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1} assert.Equal(t, res.Rules[0].IP, loopback6) } } // SAFE BROWSING
</s> remove // ...and 1 IPv6 address </s> add // One IPv6 address. </s> remove loopback4 := net.IP{0, 0, 0, 1} assert.Equal(t, res.Rules[0].IP, loopback4) </s> add assert.Equal(t, res.Rules[0].IP, net.IP{0, 0, 0, 1}) </s> remove // 2 IPv4 (return only the first one) </s> add // Two IPv4, the first one returned. </s> remove f := NewForTest(nil, []Filter{{ID: 0, Data: []byte(text)}}) </s> add f := newForTest(nil, []Filter{{ID: 0, Data: []byte(text)}}) </s> remove d := DNSFilter{} </s> add d := newForTest(nil, nil) t.Cleanup(d.Close)
assert.Equal(t, res.Rules[0].IP, net.IPv6loopback)
res, err = d.CheckHost("host2", dns.TypeAAAA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) if assert.Len(t, res.Rules, 1) { assert.Equal(t, res.Rules[0].IP, net.IPv6loopback) assert.Equal(t, res.Rules[0].IP, net.IPv6loopback) } } // SAFE BROWSING
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
assert.Equal(t, res.Rules[0].IP, loopback6) } } // SAFE BROWSING func TestSafeBrowsing(t *testing.T) { logOutput := &bytes.Buffer{} testutil.ReplaceLogWriter(t, logOutput) testutil.ReplaceLogLevel(t, log.DEBUG)
</s> remove // PARENTAL </s> add // Parental. </s> remove d := NewForTest(&Config{SafeBrowsingEnabled: true}, nil) defer d.Close() d.checkMatch(t, "wmconvirus.narod.ru") </s> add d := newForTest(&Config{SafeBrowsingEnabled: true}, nil) t.Cleanup(d.Close) matching := "wmconvirus.narod.ru" d.safeBrowsingUpstream = &testSbUpstream{ hostname: matching, block: true, } d.checkMatch(t, matching) </s> remove loopback6 := net.IP{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1} assert.Equal(t, res.Rules[0].IP, loopback6) </s> add assert.Equal(t, res.Rules[0].IP, net.IPv6loopback) </s> remove d := NewForTest(&Config{ParentalEnabled: true}, nil) defer d.Close() d.checkMatch(t, "pornhub.com") assert.Contains(t, logOutput.String(), "Parental lookup for pornhub.com") d.checkMatch(t, "www.pornhub.com") </s> add d := newForTest(&Config{ParentalEnabled: true}, nil) t.Cleanup(d.Close) matching := "pornhub.com" d.parentalUpstream = &testSbUpstream{ hostname: matching, block: true, } d.checkMatch(t, matching) assert.Contains(t, logOutput.String(), "Parental lookup for "+matching) d.checkMatch(t, "www."+matching) </s> remove // HELPERS // SAFE BROWSING // SAFE SEARCH // PARENTAL // FILTERING // BENCHMARKS // HELPERS </s> add // Helpers.
// Safe Browsing.
assert.Equal(t, res.Rules[0].IP, loopback6) } } // Safe Browsing. func TestSafeBrowsing(t *testing.T) { logOutput := &bytes.Buffer{} testutil.ReplaceLogWriter(t, logOutput) testutil.ReplaceLogLevel(t, log.DEBUG)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
logOutput := &bytes.Buffer{} testutil.ReplaceLogWriter(t, logOutput) testutil.ReplaceLogLevel(t, log.DEBUG) d := NewForTest(&Config{SafeBrowsingEnabled: true}, nil) defer d.Close() d.checkMatch(t, "wmconvirus.narod.ru") assert.Contains(t, logOutput.String(), "SafeBrowsing lookup for wmconvirus.narod.ru") d.checkMatch(t, "test.wmconvirus.narod.ru") d.checkMatchEmpty(t, "yandex.ru")
</s> remove assert.Contains(t, logOutput.String(), "SafeBrowsing lookup for wmconvirus.narod.ru") </s> add assert.Contains(t, logOutput.String(), "SafeBrowsing lookup for "+matching) </s> remove d := NewForTest(&Config{ParentalEnabled: true}, nil) defer d.Close() d.checkMatch(t, "pornhub.com") assert.Contains(t, logOutput.String(), "Parental lookup for pornhub.com") d.checkMatch(t, "www.pornhub.com") </s> add d := newForTest(&Config{ParentalEnabled: true}, nil) t.Cleanup(d.Close) matching := "pornhub.com" d.parentalUpstream = &testSbUpstream{ hostname: matching, block: true, } d.checkMatch(t, matching) assert.Contains(t, logOutput.String(), "Parental lookup for "+matching) d.checkMatch(t, "www."+matching) </s> remove d.checkMatch(t, "test.wmconvirus.narod.ru") </s> add d.checkMatch(t, "test."+matching) </s> remove // PARENTAL </s> add // Parental. </s> remove // SAFE BROWSING </s> add // Safe Browsing.
d := newForTest(&Config{SafeBrowsingEnabled: true}, nil) t.Cleanup(d.Close) matching := "wmconvirus.narod.ru" d.safeBrowsingUpstream = &testSbUpstream{ hostname: matching, block: true, } d.checkMatch(t, matching)
logOutput := &bytes.Buffer{} testutil.ReplaceLogWriter(t, logOutput) testutil.ReplaceLogLevel(t, log.DEBUG) d := newForTest(&Config{SafeBrowsingEnabled: true}, nil) t.Cleanup(d.Close) matching := "wmconvirus.narod.ru" d.safeBrowsingUpstream = &testSbUpstream{ hostname: matching, block: true, } d.checkMatch(t, matching) d := newForTest(&Config{SafeBrowsingEnabled: true}, nil) t.Cleanup(d.Close) matching := "wmconvirus.narod.ru" d.safeBrowsingUpstream = &testSbUpstream{ hostname: matching, block: true, } d.checkMatch(t, matching) d := newForTest(&Config{SafeBrowsingEnabled: true}, nil) t.Cleanup(d.Close) matching := "wmconvirus.narod.ru" d.safeBrowsingUpstream = &testSbUpstream{ hostname: matching, block: true, } d.checkMatch(t, matching) assert.Contains(t, logOutput.String(), "SafeBrowsing lookup for wmconvirus.narod.ru") d.checkMatch(t, "test.wmconvirus.narod.ru") d.checkMatchEmpty(t, "yandex.ru")
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
d := NewForTest(&Config{SafeBrowsingEnabled: true}, nil) defer d.Close() d.checkMatch(t, "wmconvirus.narod.ru") assert.Contains(t, logOutput.String(), "SafeBrowsing lookup for wmconvirus.narod.ru") d.checkMatch(t, "test.wmconvirus.narod.ru") d.checkMatchEmpty(t, "yandex.ru") d.checkMatchEmpty(t, "pornhub.com")
</s> remove d.checkMatch(t, "test.wmconvirus.narod.ru") </s> add d.checkMatch(t, "test."+matching) </s> remove d := NewForTest(&Config{SafeBrowsingEnabled: true}, nil) defer d.Close() d.checkMatch(t, "wmconvirus.narod.ru") </s> add d := newForTest(&Config{SafeBrowsingEnabled: true}, nil) t.Cleanup(d.Close) matching := "wmconvirus.narod.ru" d.safeBrowsingUpstream = &testSbUpstream{ hostname: matching, block: true, } d.checkMatch(t, matching) </s> remove d := NewForTest(&Config{ParentalEnabled: true}, nil) defer d.Close() d.checkMatch(t, "pornhub.com") assert.Contains(t, logOutput.String(), "Parental lookup for pornhub.com") d.checkMatch(t, "www.pornhub.com") </s> add d := newForTest(&Config{ParentalEnabled: true}, nil) t.Cleanup(d.Close) matching := "pornhub.com" d.parentalUpstream = &testSbUpstream{ hostname: matching, block: true, } d.checkMatch(t, matching) assert.Contains(t, logOutput.String(), "Parental lookup for "+matching) d.checkMatch(t, "www."+matching) </s> remove // test cached result </s> add // Cached result. </s> remove d.checkMatch(t, "wmconvirus.narod.ru") d.checkMatch(t, "test.wmconvirus.narod.ru") </s> add d.checkMatch(t, matching) d.checkMatch(t, "test."+matching)
assert.Contains(t, logOutput.String(), "SafeBrowsing lookup for "+matching)
d := NewForTest(&Config{SafeBrowsingEnabled: true}, nil) defer d.Close() d.checkMatch(t, "wmconvirus.narod.ru") assert.Contains(t, logOutput.String(), "SafeBrowsing lookup for "+matching) d.checkMatch(t, "test.wmconvirus.narod.ru") d.checkMatchEmpty(t, "yandex.ru") d.checkMatchEmpty(t, "pornhub.com")
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
d.checkMatch(t, "wmconvirus.narod.ru") assert.Contains(t, logOutput.String(), "SafeBrowsing lookup for wmconvirus.narod.ru") d.checkMatch(t, "test.wmconvirus.narod.ru") d.checkMatchEmpty(t, "yandex.ru") d.checkMatchEmpty(t, "pornhub.com") // test cached result d.safeBrowsingServer = "127.0.0.1"
</s> remove // test cached result </s> add // Cached result. </s> remove assert.Contains(t, logOutput.String(), "SafeBrowsing lookup for wmconvirus.narod.ru") </s> add assert.Contains(t, logOutput.String(), "SafeBrowsing lookup for "+matching) </s> remove d.checkMatch(t, "wmconvirus.narod.ru") </s> add d.checkMatch(t, matching) </s> remove d := NewForTest(&Config{ParentalEnabled: true}, nil) defer d.Close() d.checkMatch(t, "pornhub.com") assert.Contains(t, logOutput.String(), "Parental lookup for pornhub.com") d.checkMatch(t, "www.pornhub.com") </s> add d := newForTest(&Config{ParentalEnabled: true}, nil) t.Cleanup(d.Close) matching := "pornhub.com" d.parentalUpstream = &testSbUpstream{ hostname: matching, block: true, } d.checkMatch(t, matching) assert.Contains(t, logOutput.String(), "Parental lookup for "+matching) d.checkMatch(t, "www."+matching) </s> remove d.checkMatch(t, "pornhub.com") </s> add d.checkMatch(t, matching)
d.checkMatch(t, "test."+matching)
d.checkMatch(t, "wmconvirus.narod.ru") assert.Contains(t, logOutput.String(), "SafeBrowsing lookup for wmconvirus.narod.ru") d.checkMatch(t, "test."+matching) d.checkMatchEmpty(t, "yandex.ru") d.checkMatchEmpty(t, "pornhub.com") // test cached result d.safeBrowsingServer = "127.0.0.1"
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
d.checkMatch(t, "test.wmconvirus.narod.ru") d.checkMatchEmpty(t, "yandex.ru") d.checkMatchEmpty(t, "pornhub.com") // test cached result d.safeBrowsingServer = "127.0.0.1" d.checkMatch(t, "wmconvirus.narod.ru") d.checkMatchEmpty(t, "pornhub.com") d.safeBrowsingServer = defaultSafebrowsingServer }
</s> remove d.checkMatch(t, "wmconvirus.narod.ru") </s> add d.checkMatch(t, matching) </s> remove d.checkMatch(t, "test.wmconvirus.narod.ru") </s> add d.checkMatch(t, "test."+matching) </s> remove d.checkMatch(t, "pornhub.com") </s> add d.checkMatch(t, matching) </s> remove d.checkMatch(t, "wmconvirus.narod.ru") d.checkMatch(t, "test.wmconvirus.narod.ru") </s> add d.checkMatch(t, matching) d.checkMatch(t, "test."+matching) </s> remove d := NewForTest(&Config{ParentalEnabled: true}, nil) defer d.Close() d.checkMatch(t, "pornhub.com") assert.Contains(t, logOutput.String(), "Parental lookup for pornhub.com") d.checkMatch(t, "www.pornhub.com") </s> add d := newForTest(&Config{ParentalEnabled: true}, nil) t.Cleanup(d.Close) matching := "pornhub.com" d.parentalUpstream = &testSbUpstream{ hostname: matching, block: true, } d.checkMatch(t, matching) assert.Contains(t, logOutput.String(), "Parental lookup for "+matching) d.checkMatch(t, "www."+matching)
// Cached result.
d.checkMatch(t, "test.wmconvirus.narod.ru") d.checkMatchEmpty(t, "yandex.ru") d.checkMatchEmpty(t, "pornhub.com") // Cached result. d.safeBrowsingServer = "127.0.0.1" d.checkMatch(t, "wmconvirus.narod.ru") d.checkMatchEmpty(t, "pornhub.com") d.safeBrowsingServer = defaultSafebrowsingServer }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
d.checkMatchEmpty(t, "pornhub.com") // test cached result d.safeBrowsingServer = "127.0.0.1" d.checkMatch(t, "wmconvirus.narod.ru") d.checkMatchEmpty(t, "pornhub.com") d.safeBrowsingServer = defaultSafebrowsingServer } func TestParallelSB(t *testing.T) {
</s> remove // test cached result </s> add // Cached result. </s> remove d.checkMatch(t, "test.wmconvirus.narod.ru") </s> add d.checkMatch(t, "test."+matching) </s> remove d.checkMatch(t, "pornhub.com") </s> add d.checkMatch(t, matching) </s> remove d := NewForTest(&Config{ParentalEnabled: true}, nil) defer d.Close() d.checkMatch(t, "pornhub.com") assert.Contains(t, logOutput.String(), "Parental lookup for pornhub.com") d.checkMatch(t, "www.pornhub.com") </s> add d := newForTest(&Config{ParentalEnabled: true}, nil) t.Cleanup(d.Close) matching := "pornhub.com" d.parentalUpstream = &testSbUpstream{ hostname: matching, block: true, } d.checkMatch(t, matching) assert.Contains(t, logOutput.String(), "Parental lookup for "+matching) d.checkMatch(t, "www."+matching) </s> remove d := NewForTest(&Config{SafeBrowsingEnabled: true}, nil) defer d.Close() </s> add d := newForTest(&Config{SafeBrowsingEnabled: true}, nil) t.Cleanup(d.Close) matching := "wmconvirus.narod.ru" d.safeBrowsingUpstream = &testSbUpstream{ hostname: matching, block: true, }
d.checkMatch(t, matching)
d.checkMatchEmpty(t, "pornhub.com") // test cached result d.safeBrowsingServer = "127.0.0.1" d.checkMatch(t, matching) d.checkMatchEmpty(t, "pornhub.com") d.safeBrowsingServer = defaultSafebrowsingServer } func TestParallelSB(t *testing.T) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
d.safeBrowsingServer = defaultSafebrowsingServer } func TestParallelSB(t *testing.T) { d := NewForTest(&Config{SafeBrowsingEnabled: true}, nil) defer d.Close() t.Run("group", func(t *testing.T) { for i := 0; i < 100; i++ { t.Run(fmt.Sprintf("aaa%d", i), func(t *testing.T) { t.Parallel() d.checkMatch(t, "wmconvirus.narod.ru")
</s> remove d.checkMatch(t, "wmconvirus.narod.ru") d.checkMatch(t, "test.wmconvirus.narod.ru") </s> add d.checkMatch(t, matching) d.checkMatch(t, "test."+matching) </s> remove d.checkMatch(t, "wmconvirus.narod.ru") </s> add d.checkMatch(t, matching) </s> remove ip := ips[0] for _, i := range ips { if i.To4() != nil { ip = i </s> add ip := ipAddrs[0].IP for _, ipAddr := range ipAddrs { if ipAddr.IP.To4() != nil { ip = ipAddr.IP </s> remove // BENCHMARKS </s> add // Benchmarks. </s> remove // blocked by parental r, _ = d.CheckHost("pornhub.com", dns.TypeA, &setts) if !r.IsFiltered || r.Reason != FilteredParental { t.Fatalf("CheckHost FilteredParental") </s> add makeTester := func(tc testCase, before bool) func(t *testing.T) { return func(t *testing.T) { r, _ := d.CheckHost(tc.host, dns.TypeA, &setts) if before { assert.True(t, r.IsFiltered) assert.Equal(t, tc.wantReason, r.Reason) } else { assert.False(t, r.IsFiltered) } }
d := newForTest(&Config{SafeBrowsingEnabled: true}, nil) t.Cleanup(d.Close) matching := "wmconvirus.narod.ru" d.safeBrowsingUpstream = &testSbUpstream{ hostname: matching, block: true, }
d.safeBrowsingServer = defaultSafebrowsingServer } func TestParallelSB(t *testing.T) { d := newForTest(&Config{SafeBrowsingEnabled: true}, nil) t.Cleanup(d.Close) matching := "wmconvirus.narod.ru" d.safeBrowsingUpstream = &testSbUpstream{ hostname: matching, block: true, } d := newForTest(&Config{SafeBrowsingEnabled: true}, nil) t.Cleanup(d.Close) matching := "wmconvirus.narod.ru" d.safeBrowsingUpstream = &testSbUpstream{ hostname: matching, block: true, } t.Run("group", func(t *testing.T) { for i := 0; i < 100; i++ { t.Run(fmt.Sprintf("aaa%d", i), func(t *testing.T) { t.Parallel() d.checkMatch(t, "wmconvirus.narod.ru")
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
t.Run("group", func(t *testing.T) { for i := 0; i < 100; i++ { t.Run(fmt.Sprintf("aaa%d", i), func(t *testing.T) { t.Parallel() d.checkMatch(t, "wmconvirus.narod.ru") d.checkMatch(t, "test.wmconvirus.narod.ru") d.checkMatchEmpty(t, "yandex.ru") d.checkMatchEmpty(t, "pornhub.com") }) } })
</s> remove d := NewForTest(&Config{SafeBrowsingEnabled: true}, nil) defer d.Close() </s> add d := newForTest(&Config{SafeBrowsingEnabled: true}, nil) t.Cleanup(d.Close) matching := "wmconvirus.narod.ru" d.safeBrowsingUpstream = &testSbUpstream{ hostname: matching, block: true, } </s> remove // test cached result </s> add // Cached result. </s> remove d.checkMatch(t, "test.wmconvirus.narod.ru") </s> add d.checkMatch(t, "test."+matching) </s> remove d.checkMatch(t, "wmconvirus.narod.ru") </s> add d.checkMatch(t, matching) </s> remove assert.Contains(t, logOutput.String(), "SafeBrowsing lookup for wmconvirus.narod.ru") </s> add assert.Contains(t, logOutput.String(), "SafeBrowsing lookup for "+matching)
d.checkMatch(t, matching) d.checkMatch(t, "test."+matching)
t.Run("group", func(t *testing.T) { for i := 0; i < 100; i++ { t.Run(fmt.Sprintf("aaa%d", i), func(t *testing.T) { t.Parallel() d.checkMatch(t, matching) d.checkMatch(t, "test."+matching) d.checkMatch(t, matching) d.checkMatch(t, "test."+matching) d.checkMatchEmpty(t, "yandex.ru") d.checkMatchEmpty(t, "pornhub.com") }) } })
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
} }) } // SAFE SEARCH func TestSafeSearch(t *testing.T) { d := NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() val, ok := d.SafeSearchDomain("www.google.com")
</s> remove d := NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() </s> add d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) </s> remove if !ok { t.Errorf("Expected safesearch to find result for www.google.com") } if val != "forcesafesearch.google.com" { t.Errorf("Expected safesearch for google.com to be forcesafesearch.google.com") } </s> add assert.True(t, ok, "Expected safesearch to find result for www.google.com") assert.Equal(t, "forcesafesearch.google.com", val, "Expected safesearch for google.com to be forcesafesearch.google.com") </s> remove d := NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() </s> add d := newForTest(&Config{SafeSearchEnabled: true}, nil) b.Cleanup(d.Close) </s> remove d := NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() </s> add d := newForTest(&Config{SafeSearchEnabled: true}, nil) b.Cleanup(d.Close) </s> remove if !ok { b.Errorf("Expected safesearch to find result for www.google.com") } if val != "forcesafesearch.google.com" { b.Errorf("Expected safesearch for google.com to be forcesafesearch.google.com") } </s> add assert.True(b, ok, "Expected safesearch to find result for www.google.com") assert.Equal(b, "forcesafesearch.google.com", val, "Expected safesearch for google.com to be forcesafesearch.google.com")
// Safe Search.
} }) } // Safe Search. func TestSafeSearch(t *testing.T) { d := NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() val, ok := d.SafeSearchDomain("www.google.com")
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
// SAFE SEARCH func TestSafeSearch(t *testing.T) { d := NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() val, ok := d.SafeSearchDomain("www.google.com") if !ok { t.Errorf("Expected safesearch to find result for www.google.com") } if val != "forcesafesearch.google.com" {
</s> remove if !ok { t.Errorf("Expected safesearch to find result for www.google.com") } if val != "forcesafesearch.google.com" { t.Errorf("Expected safesearch for google.com to be forcesafesearch.google.com") } </s> add assert.True(t, ok, "Expected safesearch to find result for www.google.com") assert.Equal(t, "forcesafesearch.google.com", val, "Expected safesearch for google.com to be forcesafesearch.google.com") </s> remove if !ok { b.Errorf("Expected safesearch to find result for www.google.com") } if val != "forcesafesearch.google.com" { b.Errorf("Expected safesearch for google.com to be forcesafesearch.google.com") } </s> add assert.True(b, ok, "Expected safesearch to find result for www.google.com") assert.Equal(b, "forcesafesearch.google.com", val, "Expected safesearch for google.com to be forcesafesearch.google.com") </s> remove if !ok { b.Errorf("Expected safesearch to find result for www.google.com") } if val != "forcesafesearch.google.com" { b.Errorf("Expected safesearch for google.com to be forcesafesearch.google.com") } </s> add assert.True(b, ok, "Expected safesearch to find result for www.google.com") assert.Equal(b, "forcesafesearch.google.com", val, "Expected safesearch for google.com to be forcesafesearch.google.com") </s> remove d := NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() </s> add d := newForTest(&Config{SafeSearchEnabled: true}, nil) b.Cleanup(d.Close) </s> remove d := NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() </s> add d := newForTest(&Config{SafeSearchEnabled: true}, nil) b.Cleanup(d.Close)
d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close)
// SAFE SEARCH func TestSafeSearch(t *testing.T) { d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) val, ok := d.SafeSearchDomain("www.google.com") if !ok { t.Errorf("Expected safesearch to find result for www.google.com") } if val != "forcesafesearch.google.com" {
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
func TestSafeSearch(t *testing.T) { d := NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() val, ok := d.SafeSearchDomain("www.google.com") if !ok { t.Errorf("Expected safesearch to find result for www.google.com") } if val != "forcesafesearch.google.com" { t.Errorf("Expected safesearch for google.com to be forcesafesearch.google.com") } } func TestCheckHostSafeSearchYandex(t *testing.T) { d := NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close()
</s> remove if !ok { b.Errorf("Expected safesearch to find result for www.google.com") } if val != "forcesafesearch.google.com" { b.Errorf("Expected safesearch for google.com to be forcesafesearch.google.com") } </s> add assert.True(b, ok, "Expected safesearch to find result for www.google.com") assert.Equal(b, "forcesafesearch.google.com", val, "Expected safesearch for google.com to be forcesafesearch.google.com") </s> remove d := NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() </s> add d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) </s> remove if !ok { b.Errorf("Expected safesearch to find result for www.google.com") } if val != "forcesafesearch.google.com" { b.Errorf("Expected safesearch for google.com to be forcesafesearch.google.com") } </s> add assert.True(b, ok, "Expected safesearch to find result for www.google.com") assert.Equal(b, "forcesafesearch.google.com", val, "Expected safesearch for google.com to be forcesafesearch.google.com") </s> remove d := NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() </s> add d := newForTest(&Config{SafeSearchEnabled: true}, nil) b.Cleanup(d.Close) </s> remove d := NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() </s> add d := newForTest(&Config{SafeSearchEnabled: true}, nil) b.Cleanup(d.Close)
assert.True(t, ok, "Expected safesearch to find result for www.google.com") assert.Equal(t, "forcesafesearch.google.com", val, "Expected safesearch for google.com to be forcesafesearch.google.com")
func TestSafeSearch(t *testing.T) { d := NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() val, ok := d.SafeSearchDomain("www.google.com") assert.True(t, ok, "Expected safesearch to find result for www.google.com") assert.Equal(t, "forcesafesearch.google.com", val, "Expected safesearch for google.com to be forcesafesearch.google.com") assert.True(t, ok, "Expected safesearch to find result for www.google.com") assert.Equal(t, "forcesafesearch.google.com", val, "Expected safesearch for google.com to be forcesafesearch.google.com") assert.True(t, ok, "Expected safesearch to find result for www.google.com") assert.Equal(t, "forcesafesearch.google.com", val, "Expected safesearch for google.com to be forcesafesearch.google.com") assert.True(t, ok, "Expected safesearch to find result for www.google.com") assert.Equal(t, "forcesafesearch.google.com", val, "Expected safesearch for google.com to be forcesafesearch.google.com") assert.True(t, ok, "Expected safesearch to find result for www.google.com") assert.Equal(t, "forcesafesearch.google.com", val, "Expected safesearch for google.com to be forcesafesearch.google.com") assert.True(t, ok, "Expected safesearch to find result for www.google.com") assert.Equal(t, "forcesafesearch.google.com", val, "Expected safesearch for google.com to be forcesafesearch.google.com") } func TestCheckHostSafeSearchYandex(t *testing.T) { d := NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close()
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
} } func TestCheckHostSafeSearchYandex(t *testing.T) { d := NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() // Slice of yandex domains yandex := []string{"yAndeX.ru", "YANdex.COM", "yandex.ua", "yandex.by", "yandex.kz", "www.yandex.com"} // Check host for each domain for _, host := range yandex { res, err := d.CheckHost(host, dns.TypeA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) if assert.Len(t, res.Rules, 1) { assert.Equal(t, res.Rules[0].IP.String(), "213.180.193.56")
</s> remove // Check host for each domain for _, host := range googleDomains { res, err := d.CheckHost(host, dns.TypeA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) if assert.Len(t, res.Rules, 1) { assert.NotEqual(t, res.Rules[0].IP.String(), "0.0.0.0") } </s> add func TestCheckHostSafeSearchGoogle(t *testing.T) { d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) d.resolver = &testResolver{} // Check host for each domain. for _, host := range []string{ "www.google.com", "www.google.im", "www.google.co.in", "www.google.iq", "www.google.is", "www.google.it", "www.google.je", } { t.Run(host, func(t *testing.T) { res, err := d.CheckHost(host, dns.TypeA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) assert.Len(t, res.Rules, 1) }) </s> remove func TestCheckHostSafeSearchGoogle(t *testing.T) { d := NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() // Slice of google domains googleDomains := []string{"www.google.com", "www.google.im", "www.google.co.in", "www.google.iq", "www.google.is", "www.google.it", "www.google.je"} </s> add // testResolver is a Resolver for tests. type testResolver struct{} // LookupIP implements Resolver interface for *testResolver. func (r *testResolver) LookupIPAddr(_ context.Context, host string) (ips []net.IPAddr, err error) { hash := sha256.Sum256([]byte(host)) addrs := []net.IPAddr{{ IP: net.IP(hash[:4]), Zone: "somezone", }, { IP: net.IP(hash[4:20]), Zone: "somezone", }} return addrs, nil } </s> remove // For yandex we already know valid ip. </s> add // For yandex we already know valid IP. </s> remove assert.Equal(t, res.Rules[0].IP.String(), "213.180.193.56") </s> add assert.Equal(t, res.Rules[0].IP, net.IPv4(213, 180, 193, 56)) </s> remove assert.Equal(t, res.Rules[0].IP.String(), "213.180.193.56") </s> add assert.Equal(t, res.Rules[0].IP, net.IPv4(213, 180, 193, 56))
d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) // Check host for each domain. for _, host := range []string{ "yAndeX.ru", "YANdex.COM", "yandex.ua", "yandex.by", "yandex.kz", "www.yandex.com", } {
} } func TestCheckHostSafeSearchYandex(t *testing.T) { d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) // Check host for each domain. for _, host := range []string{ "yAndeX.ru", "YANdex.COM", "yandex.ua", "yandex.by", "yandex.kz", "www.yandex.com", } { d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) // Check host for each domain. for _, host := range []string{ "yAndeX.ru", "YANdex.COM", "yandex.ua", "yandex.by", "yandex.kz", "www.yandex.com", } { d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) // Check host for each domain. for _, host := range []string{ "yAndeX.ru", "YANdex.COM", "yandex.ua", "yandex.by", "yandex.kz", "www.yandex.com", } { d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) // Check host for each domain. for _, host := range []string{ "yAndeX.ru", "YANdex.COM", "yandex.ua", "yandex.by", "yandex.kz", "www.yandex.com", } { d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) // Check host for each domain. for _, host := range []string{ "yAndeX.ru", "YANdex.COM", "yandex.ua", "yandex.by", "yandex.kz", "www.yandex.com", } { d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) // Check host for each domain. for _, host := range []string{ "yAndeX.ru", "YANdex.COM", "yandex.ua", "yandex.by", "yandex.kz", "www.yandex.com", } { d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) // Check host for each domain. for _, host := range []string{ "yAndeX.ru", "YANdex.COM", "yandex.ua", "yandex.by", "yandex.kz", "www.yandex.com", } { d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) // Check host for each domain. for _, host := range []string{ "yAndeX.ru", "YANdex.COM", "yandex.ua", "yandex.by", "yandex.kz", "www.yandex.com", } { res, err := d.CheckHost(host, dns.TypeA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) if assert.Len(t, res.Rules, 1) { assert.Equal(t, res.Rules[0].IP.String(), "213.180.193.56")
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
res, err := d.CheckHost(host, dns.TypeA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) if assert.Len(t, res.Rules, 1) { assert.Equal(t, res.Rules[0].IP.String(), "213.180.193.56") } } } func TestCheckHostSafeSearchGoogle(t *testing.T) {
</s> remove // Check host for each domain for _, host := range googleDomains { res, err := d.CheckHost(host, dns.TypeA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) if assert.Len(t, res.Rules, 1) { assert.NotEqual(t, res.Rules[0].IP.String(), "0.0.0.0") } </s> add func TestCheckHostSafeSearchGoogle(t *testing.T) { d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) d.resolver = &testResolver{} // Check host for each domain. for _, host := range []string{ "www.google.com", "www.google.im", "www.google.co.in", "www.google.iq", "www.google.is", "www.google.it", "www.google.je", } { t.Run(host, func(t *testing.T) { res, err := d.CheckHost(host, dns.TypeA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) assert.Len(t, res.Rules, 1) }) </s> remove d := NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() // Slice of yandex domains yandex := []string{"yAndeX.ru", "YANdex.COM", "yandex.ua", "yandex.by", "yandex.kz", "www.yandex.com"} // Check host for each domain for _, host := range yandex { </s> add d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) // Check host for each domain. for _, host := range []string{ "yAndeX.ru", "YANdex.COM", "yandex.ua", "yandex.by", "yandex.kz", "www.yandex.com", } { </s> remove assert.Equal(t, res.Rules[0].IP.String(), "213.180.193.56") </s> add assert.Equal(t, res.Rules[0].IP, net.IPv4(213, 180, 193, 56)) </s> remove loopback4 := net.IP{0, 0, 0, 1} assert.Equal(t, res.Rules[0].IP, loopback4) </s> add assert.Equal(t, res.Rules[0].IP, net.IP{0, 0, 0, 1}) </s> remove // not matched by white filter, but matched by block filter </s> add // Not matched by white filter, but matched by block filter.
assert.Equal(t, res.Rules[0].IP, net.IPv4(213, 180, 193, 56))
res, err := d.CheckHost(host, dns.TypeA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) if assert.Len(t, res.Rules, 1) { assert.Equal(t, res.Rules[0].IP, net.IPv4(213, 180, 193, 56)) } } } func TestCheckHostSafeSearchGoogle(t *testing.T) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
} } } func TestCheckHostSafeSearchGoogle(t *testing.T) { d := NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() // Slice of google domains googleDomains := []string{"www.google.com", "www.google.im", "www.google.co.in", "www.google.iq", "www.google.is", "www.google.it", "www.google.je"} // Check host for each domain for _, host := range googleDomains { res, err := d.CheckHost(host, dns.TypeA, &setts) assert.Nil(t, err)
</s> remove // Check host for each domain for _, host := range googleDomains { res, err := d.CheckHost(host, dns.TypeA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) if assert.Len(t, res.Rules, 1) { assert.NotEqual(t, res.Rules[0].IP.String(), "0.0.0.0") } </s> add func TestCheckHostSafeSearchGoogle(t *testing.T) { d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) d.resolver = &testResolver{} // Check host for each domain. for _, host := range []string{ "www.google.com", "www.google.im", "www.google.co.in", "www.google.iq", "www.google.is", "www.google.it", "www.google.je", } { t.Run(host, func(t *testing.T) { res, err := d.CheckHost(host, dns.TypeA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) assert.Len(t, res.Rules, 1) }) </s> remove d := NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() // Slice of yandex domains yandex := []string{"yAndeX.ru", "YANdex.COM", "yandex.ua", "yandex.by", "yandex.kz", "www.yandex.com"} // Check host for each domain for _, host := range yandex { </s> add d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) // Check host for each domain. for _, host := range []string{ "yAndeX.ru", "YANdex.COM", "yandex.ua", "yandex.by", "yandex.kz", "www.yandex.com", } { </s> remove d := NewForTest(nil, nil) defer d.Close() </s> add d := newForTest(nil, nil) t.Cleanup(d.Close) </s> remove assert.Equal(t, res.Rules[0].IP.String(), "213.180.193.56") </s> add assert.Equal(t, res.Rules[0].IP, net.IPv4(213, 180, 193, 56)) </s> remove hostname := "wmconvirus.narod.ru" res, err := d.CheckHost(hostname, dns.TypeA, &setts) if err != nil { b.Errorf("Error while matching host %s: %s", hostname, err) } if !res.IsFiltered { b.Errorf("Expected hostname %s to match", hostname) } </s> add res, err := d.CheckHost(blocked, dns.TypeA, &setts) assert.Nilf(b, err, "Error while matching host %s: %s", blocked, err) assert.True(b, res.IsFiltered, "Expected hostname %s to match", blocked)
// testResolver is a Resolver for tests. type testResolver struct{} // LookupIP implements Resolver interface for *testResolver. func (r *testResolver) LookupIPAddr(_ context.Context, host string) (ips []net.IPAddr, err error) { hash := sha256.Sum256([]byte(host)) addrs := []net.IPAddr{{ IP: net.IP(hash[:4]), Zone: "somezone", }, { IP: net.IP(hash[4:20]), Zone: "somezone", }} return addrs, nil }
} } } // testResolver is a Resolver for tests. type testResolver struct{} // LookupIP implements Resolver interface for *testResolver. func (r *testResolver) LookupIPAddr(_ context.Context, host string) (ips []net.IPAddr, err error) { hash := sha256.Sum256([]byte(host)) addrs := []net.IPAddr{{ IP: net.IP(hash[:4]), Zone: "somezone", }, { IP: net.IP(hash[4:20]), Zone: "somezone", }} return addrs, nil } // testResolver is a Resolver for tests. type testResolver struct{} // LookupIP implements Resolver interface for *testResolver. func (r *testResolver) LookupIPAddr(_ context.Context, host string) (ips []net.IPAddr, err error) { hash := sha256.Sum256([]byte(host)) addrs := []net.IPAddr{{ IP: net.IP(hash[:4]), Zone: "somezone", }, { IP: net.IP(hash[4:20]), Zone: "somezone", }} return addrs, nil } // testResolver is a Resolver for tests. type testResolver struct{} // LookupIP implements Resolver interface for *testResolver. func (r *testResolver) LookupIPAddr(_ context.Context, host string) (ips []net.IPAddr, err error) { hash := sha256.Sum256([]byte(host)) addrs := []net.IPAddr{{ IP: net.IP(hash[:4]), Zone: "somezone", }, { IP: net.IP(hash[4:20]), Zone: "somezone", }} return addrs, nil } // testResolver is a Resolver for tests. type testResolver struct{} // LookupIP implements Resolver interface for *testResolver. func (r *testResolver) LookupIPAddr(_ context.Context, host string) (ips []net.IPAddr, err error) { hash := sha256.Sum256([]byte(host)) addrs := []net.IPAddr{{ IP: net.IP(hash[:4]), Zone: "somezone", }, { IP: net.IP(hash[4:20]), Zone: "somezone", }} return addrs, nil } // testResolver is a Resolver for tests. type testResolver struct{} // LookupIP implements Resolver interface for *testResolver. func (r *testResolver) LookupIPAddr(_ context.Context, host string) (ips []net.IPAddr, err error) { hash := sha256.Sum256([]byte(host)) addrs := []net.IPAddr{{ IP: net.IP(hash[:4]), Zone: "somezone", }, { IP: net.IP(hash[4:20]), Zone: "somezone", }} return addrs, nil } // testResolver is a Resolver for tests. type testResolver struct{} // LookupIP implements Resolver interface for *testResolver. func (r *testResolver) LookupIPAddr(_ context.Context, host string) (ips []net.IPAddr, err error) { hash := sha256.Sum256([]byte(host)) addrs := []net.IPAddr{{ IP: net.IP(hash[:4]), Zone: "somezone", }, { IP: net.IP(hash[4:20]), Zone: "somezone", }} return addrs, nil } // Check host for each domain for _, host := range googleDomains { res, err := d.CheckHost(host, dns.TypeA, &setts) assert.Nil(t, err)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
// Slice of google domains googleDomains := []string{"www.google.com", "www.google.im", "www.google.co.in", "www.google.iq", "www.google.is", "www.google.it", "www.google.je"} // Check host for each domain for _, host := range googleDomains { res, err := d.CheckHost(host, dns.TypeA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) if assert.Len(t, res.Rules, 1) { assert.NotEqual(t, res.Rules[0].IP.String(), "0.0.0.0") } } } func TestSafeSearchCacheYandex(t *testing.T) { d := NewForTest(nil, nil)
</s> remove func TestCheckHostSafeSearchGoogle(t *testing.T) { d := NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() // Slice of google domains googleDomains := []string{"www.google.com", "www.google.im", "www.google.co.in", "www.google.iq", "www.google.is", "www.google.it", "www.google.je"} </s> add // testResolver is a Resolver for tests. type testResolver struct{} // LookupIP implements Resolver interface for *testResolver. func (r *testResolver) LookupIPAddr(_ context.Context, host string) (ips []net.IPAddr, err error) { hash := sha256.Sum256([]byte(host)) addrs := []net.IPAddr{{ IP: net.IP(hash[:4]), Zone: "somezone", }, { IP: net.IP(hash[4:20]), Zone: "somezone", }} return addrs, nil } </s> remove d := NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() // Slice of yandex domains yandex := []string{"yAndeX.ru", "YANdex.COM", "yandex.ua", "yandex.by", "yandex.kz", "www.yandex.com"} // Check host for each domain for _, host := range yandex { </s> add d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) // Check host for each domain. for _, host := range []string{ "yAndeX.ru", "YANdex.COM", "yandex.ua", "yandex.by", "yandex.kz", "www.yandex.com", } { </s> remove d := NewForTest(nil, nil) defer d.Close() </s> add d := newForTest(nil, nil) t.Cleanup(d.Close) </s> remove assert.Equal(t, res.Rules[0].IP.String(), "213.180.193.56") </s> add assert.Equal(t, res.Rules[0].IP, net.IPv4(213, 180, 193, 56)) </s> remove assert.Equal(t, cachedValue.Rules[0].IP.String(), "213.180.193.56") </s> add assert.Equal(t, cachedValue.Rules[0].IP, net.IPv4(213, 180, 193, 56))
func TestCheckHostSafeSearchGoogle(t *testing.T) { d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) d.resolver = &testResolver{} // Check host for each domain. for _, host := range []string{ "www.google.com", "www.google.im", "www.google.co.in", "www.google.iq", "www.google.is", "www.google.it", "www.google.je", } { t.Run(host, func(t *testing.T) { res, err := d.CheckHost(host, dns.TypeA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) assert.Len(t, res.Rules, 1) })
// Slice of google domains googleDomains := []string{"www.google.com", "www.google.im", "www.google.co.in", "www.google.iq", "www.google.is", "www.google.it", "www.google.je"} func TestCheckHostSafeSearchGoogle(t *testing.T) { d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) d.resolver = &testResolver{} // Check host for each domain. for _, host := range []string{ "www.google.com", "www.google.im", "www.google.co.in", "www.google.iq", "www.google.is", "www.google.it", "www.google.je", } { t.Run(host, func(t *testing.T) { res, err := d.CheckHost(host, dns.TypeA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) assert.Len(t, res.Rules, 1) }) func TestCheckHostSafeSearchGoogle(t *testing.T) { d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) d.resolver = &testResolver{} // Check host for each domain. for _, host := range []string{ "www.google.com", "www.google.im", "www.google.co.in", "www.google.iq", "www.google.is", "www.google.it", "www.google.je", } { t.Run(host, func(t *testing.T) { res, err := d.CheckHost(host, dns.TypeA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) assert.Len(t, res.Rules, 1) }) func TestCheckHostSafeSearchGoogle(t *testing.T) { d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) d.resolver = &testResolver{} // Check host for each domain. for _, host := range []string{ "www.google.com", "www.google.im", "www.google.co.in", "www.google.iq", "www.google.is", "www.google.it", "www.google.je", } { t.Run(host, func(t *testing.T) { res, err := d.CheckHost(host, dns.TypeA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) assert.Len(t, res.Rules, 1) }) func TestCheckHostSafeSearchGoogle(t *testing.T) { d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) d.resolver = &testResolver{} // Check host for each domain. for _, host := range []string{ "www.google.com", "www.google.im", "www.google.co.in", "www.google.iq", "www.google.is", "www.google.it", "www.google.je", } { t.Run(host, func(t *testing.T) { res, err := d.CheckHost(host, dns.TypeA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) assert.Len(t, res.Rules, 1) }) func TestCheckHostSafeSearchGoogle(t *testing.T) { d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) d.resolver = &testResolver{} // Check host for each domain. for _, host := range []string{ "www.google.com", "www.google.im", "www.google.co.in", "www.google.iq", "www.google.is", "www.google.it", "www.google.je", } { t.Run(host, func(t *testing.T) { res, err := d.CheckHost(host, dns.TypeA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) assert.Len(t, res.Rules, 1) }) func TestCheckHostSafeSearchGoogle(t *testing.T) { d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) d.resolver = &testResolver{} // Check host for each domain. for _, host := range []string{ "www.google.com", "www.google.im", "www.google.co.in", "www.google.iq", "www.google.is", "www.google.it", "www.google.je", } { t.Run(host, func(t *testing.T) { res, err := d.CheckHost(host, dns.TypeA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) assert.Len(t, res.Rules, 1) }) func TestCheckHostSafeSearchGoogle(t *testing.T) { d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) d.resolver = &testResolver{} // Check host for each domain. for _, host := range []string{ "www.google.com", "www.google.im", "www.google.co.in", "www.google.iq", "www.google.is", "www.google.it", "www.google.je", } { t.Run(host, func(t *testing.T) { res, err := d.CheckHost(host, dns.TypeA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) assert.Len(t, res.Rules, 1) }) func TestCheckHostSafeSearchGoogle(t *testing.T) { d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) d.resolver = &testResolver{} // Check host for each domain. for _, host := range []string{ "www.google.com", "www.google.im", "www.google.co.in", "www.google.iq", "www.google.is", "www.google.it", "www.google.je", } { t.Run(host, func(t *testing.T) { res, err := d.CheckHost(host, dns.TypeA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) assert.Len(t, res.Rules, 1) }) } } func TestSafeSearchCacheYandex(t *testing.T) { d := NewForTest(nil, nil)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
} } func TestSafeSearchCacheYandex(t *testing.T) { d := NewForTest(nil, nil) defer d.Close() domain := "yandex.ru" // Check host with disabled safesearch. res, err := d.CheckHost(domain, dns.TypeA, &setts) assert.Nil(t, err)
</s> remove // Check host for each domain for _, host := range googleDomains { res, err := d.CheckHost(host, dns.TypeA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) if assert.Len(t, res.Rules, 1) { assert.NotEqual(t, res.Rules[0].IP.String(), "0.0.0.0") } </s> add func TestCheckHostSafeSearchGoogle(t *testing.T) { d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) d.resolver = &testResolver{} // Check host for each domain. for _, host := range []string{ "www.google.com", "www.google.im", "www.google.co.in", "www.google.iq", "www.google.is", "www.google.it", "www.google.je", } { t.Run(host, func(t *testing.T) { res, err := d.CheckHost(host, dns.TypeA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) assert.Len(t, res.Rules, 1) }) </s> remove d := NewForTest(nil, nil) defer d.Close() </s> add d := newForTest(nil, nil) t.Cleanup(d.Close) resolver := &testResolver{} d.resolver = resolver </s> remove d := NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() // Slice of yandex domains yandex := []string{"yAndeX.ru", "YANdex.COM", "yandex.ua", "yandex.by", "yandex.kz", "www.yandex.com"} // Check host for each domain for _, host := range yandex { </s> add d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) // Check host for each domain. for _, host := range []string{ "yAndeX.ru", "YANdex.COM", "yandex.ua", "yandex.by", "yandex.kz", "www.yandex.com", } { </s> remove func TestCheckHostSafeSearchGoogle(t *testing.T) { d := NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() // Slice of google domains googleDomains := []string{"www.google.com", "www.google.im", "www.google.co.in", "www.google.iq", "www.google.is", "www.google.it", "www.google.je"} </s> add // testResolver is a Resolver for tests. type testResolver struct{} // LookupIP implements Resolver interface for *testResolver. func (r *testResolver) LookupIPAddr(_ context.Context, host string) (ips []net.IPAddr, err error) { hash := sha256.Sum256([]byte(host)) addrs := []net.IPAddr{{ IP: net.IP(hash[:4]), Zone: "somezone", }, { IP: net.IP(hash[4:20]), Zone: "somezone", }} return addrs, nil } </s> remove hostname := "wmconvirus.narod.ru" res, err := d.CheckHost(hostname, dns.TypeA, &setts) if err != nil { b.Errorf("Error while matching host %s: %s", hostname, err) } if !res.IsFiltered { b.Errorf("Expected hostname %s to match", hostname) } </s> add res, err := d.CheckHost(blocked, dns.TypeA, &setts) assert.Nilf(b, err, "Error while matching host %s: %s", blocked, err) assert.True(b, res.IsFiltered, "Expected hostname %s to match", blocked)
d := newForTest(nil, nil) t.Cleanup(d.Close)
} } func TestSafeSearchCacheYandex(t *testing.T) { d := newForTest(nil, nil) t.Cleanup(d.Close) d := newForTest(nil, nil) t.Cleanup(d.Close) domain := "yandex.ru" // Check host with disabled safesearch. res, err := d.CheckHost(domain, dns.TypeA, &setts) assert.Nil(t, err)
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
assert.Nil(t, err) assert.False(t, res.IsFiltered) assert.Empty(t, res.Rules) d = NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() res, err = d.CheckHost(domain, dns.TypeA, &setts) if err != nil { t.Fatalf("CheckHost for safesearh domain %s failed cause %s", domain, err) }
</s> remove if err != nil { t.Fatalf("CheckHost for safesearh domain %s failed cause %s", domain, err) } </s> add assert.Nilf(t, err, "CheckHost for safesearh domain %s failed cause %s", domain, err) </s> remove // For yandex we already know valid ip. </s> add // For yandex we already know valid IP. </s> remove d := NewForTest(nil, nil) defer d.Close() </s> add d := newForTest(nil, nil) t.Cleanup(d.Close) resolver := &testResolver{} d.resolver = resolver </s> remove d = NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() </s> add d = newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) d.resolver = resolver </s> remove // TODO this address should be resolved with upstream that was configured in dnsforward ips, err := net.LookupIP(safeHost) </s> add ipAddrs, err := d.resolver.LookupIPAddr(context.Background(), safeHost)
d = newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close)
assert.Nil(t, err) assert.False(t, res.IsFiltered) assert.Empty(t, res.Rules) d = newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) d = newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) res, err = d.CheckHost(domain, dns.TypeA, &setts) if err != nil { t.Fatalf("CheckHost for safesearh domain %s failed cause %s", domain, err) }
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
d = NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() res, err = d.CheckHost(domain, dns.TypeA, &setts) if err != nil { t.Fatalf("CheckHost for safesearh domain %s failed cause %s", domain, err) } // For yandex we already know valid ip. if assert.Len(t, res.Rules, 1) { assert.Equal(t, res.Rules[0].IP.String(), "213.180.193.56") }
</s> remove // For yandex we already know valid ip. </s> add // For yandex we already know valid IP. </s> remove assert.Equal(t, res.Rules[0].IP.String(), "213.180.193.56") </s> add assert.Equal(t, res.Rules[0].IP, net.IPv4(213, 180, 193, 56)) </s> remove d = NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() </s> add d = newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) </s> remove d := NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() // Slice of yandex domains yandex := []string{"yAndeX.ru", "YANdex.COM", "yandex.ua", "yandex.by", "yandex.kz", "www.yandex.com"} // Check host for each domain for _, host := range yandex { </s> add d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) // Check host for each domain. for _, host := range []string{ "yAndeX.ru", "YANdex.COM", "yandex.ua", "yandex.by", "yandex.kz", "www.yandex.com", } { </s> remove assert.Equal(t, res.Rules[0].IP.String(), "213.180.193.56") </s> add assert.Equal(t, res.Rules[0].IP, net.IPv4(213, 180, 193, 56))
assert.Nilf(t, err, "CheckHost for safesearh domain %s failed cause %s", domain, err)
d = NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() res, err = d.CheckHost(domain, dns.TypeA, &setts) assert.Nilf(t, err, "CheckHost for safesearh domain %s failed cause %s", domain, err) assert.Nilf(t, err, "CheckHost for safesearh domain %s failed cause %s", domain, err) assert.Nilf(t, err, "CheckHost for safesearh domain %s failed cause %s", domain, err) // For yandex we already know valid ip. if assert.Len(t, res.Rules, 1) { assert.Equal(t, res.Rules[0].IP.String(), "213.180.193.56") }
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
if err != nil { t.Fatalf("CheckHost for safesearh domain %s failed cause %s", domain, err) } // For yandex we already know valid ip. if assert.Len(t, res.Rules, 1) { assert.Equal(t, res.Rules[0].IP.String(), "213.180.193.56") } // Check cache.
</s> remove if err != nil { t.Fatalf("CheckHost for safesearh domain %s failed cause %s", domain, err) } </s> add assert.Nilf(t, err, "CheckHost for safesearh domain %s failed cause %s", domain, err) </s> remove assert.Equal(t, res.Rules[0].IP.String(), "213.180.193.56") </s> add assert.Equal(t, res.Rules[0].IP, net.IPv4(213, 180, 193, 56)) </s> remove d = NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() </s> add d = newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) </s> remove d := NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() // Slice of yandex domains yandex := []string{"yAndeX.ru", "YANdex.COM", "yandex.ua", "yandex.by", "yandex.kz", "www.yandex.com"} // Check host for each domain for _, host := range yandex { </s> add d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) // Check host for each domain. for _, host := range []string{ "yAndeX.ru", "YANdex.COM", "yandex.ua", "yandex.by", "yandex.kz", "www.yandex.com", } { </s> remove assert.Equal(t, cachedValue.Rules[0].IP.String(), "213.180.193.56") </s> add assert.Equal(t, cachedValue.Rules[0].IP, net.IPv4(213, 180, 193, 56))
// For yandex we already know valid IP.
if err != nil { t.Fatalf("CheckHost for safesearh domain %s failed cause %s", domain, err) } // For yandex we already know valid IP. if assert.Len(t, res.Rules, 1) { assert.Equal(t, res.Rules[0].IP.String(), "213.180.193.56") } // Check cache.
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
} // For yandex we already know valid ip. if assert.Len(t, res.Rules, 1) { assert.Equal(t, res.Rules[0].IP.String(), "213.180.193.56") } // Check cache. cachedValue, isFound := getCachedResult(gctx.safeSearchCache, domain) assert.True(t, isFound)
</s> remove // For yandex we already know valid ip. </s> add // For yandex we already know valid IP. </s> remove assert.Equal(t, cachedValue.Rules[0].IP.String(), "213.180.193.56") </s> add assert.Equal(t, cachedValue.Rules[0].IP, net.IPv4(213, 180, 193, 56)) </s> remove if err != nil { t.Fatalf("CheckHost for safesearh domain %s failed cause %s", domain, err) } </s> add assert.Nilf(t, err, "CheckHost for safesearh domain %s failed cause %s", domain, err) </s> remove d := NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() // Slice of yandex domains yandex := []string{"yAndeX.ru", "YANdex.COM", "yandex.ua", "yandex.by", "yandex.kz", "www.yandex.com"} // Check host for each domain for _, host := range yandex { </s> add d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) // Check host for each domain. for _, host := range []string{ "yAndeX.ru", "YANdex.COM", "yandex.ua", "yandex.by", "yandex.kz", "www.yandex.com", } { </s> remove assert.Equal(t, res.Rules[0].IP.String(), "213.180.193.56") </s> add assert.Equal(t, res.Rules[0].IP, net.IPv4(213, 180, 193, 56))
assert.Equal(t, res.Rules[0].IP, net.IPv4(213, 180, 193, 56))
} // For yandex we already know valid ip. if assert.Len(t, res.Rules, 1) { assert.Equal(t, res.Rules[0].IP, net.IPv4(213, 180, 193, 56)) } // Check cache. cachedValue, isFound := getCachedResult(gctx.safeSearchCache, domain) assert.True(t, isFound)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
// Check cache. cachedValue, isFound := getCachedResult(gctx.safeSearchCache, domain) assert.True(t, isFound) if assert.Len(t, cachedValue.Rules, 1) { assert.Equal(t, cachedValue.Rules[0].IP.String(), "213.180.193.56") } } func TestSafeSearchCacheGoogle(t *testing.T) { d := NewForTest(nil, nil)
</s> remove assert.Equal(t, res.Rules[0].IP.String(), "213.180.193.56") </s> add assert.Equal(t, res.Rules[0].IP, net.IPv4(213, 180, 193, 56)) </s> remove // For yandex we already know valid ip. </s> add // For yandex we already know valid IP. </s> remove d := NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() // Slice of yandex domains yandex := []string{"yAndeX.ru", "YANdex.COM", "yandex.ua", "yandex.by", "yandex.kz", "www.yandex.com"} // Check host for each domain for _, host := range yandex { </s> add d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) // Check host for each domain. for _, host := range []string{ "yAndeX.ru", "YANdex.COM", "yandex.ua", "yandex.by", "yandex.kz", "www.yandex.com", } { </s> remove // Check host for each domain for _, host := range googleDomains { res, err := d.CheckHost(host, dns.TypeA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) if assert.Len(t, res.Rules, 1) { assert.NotEqual(t, res.Rules[0].IP.String(), "0.0.0.0") } </s> add func TestCheckHostSafeSearchGoogle(t *testing.T) { d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) d.resolver = &testResolver{} // Check host for each domain. for _, host := range []string{ "www.google.com", "www.google.im", "www.google.co.in", "www.google.iq", "www.google.is", "www.google.it", "www.google.je", } { t.Run(host, func(t *testing.T) { res, err := d.CheckHost(host, dns.TypeA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) assert.Len(t, res.Rules, 1) }) </s> remove assert.Equal(t, res.Rules[0].IP.String(), "213.180.193.56") </s> add assert.Equal(t, res.Rules[0].IP, net.IPv4(213, 180, 193, 56))
assert.Equal(t, cachedValue.Rules[0].IP, net.IPv4(213, 180, 193, 56))
// Check cache. cachedValue, isFound := getCachedResult(gctx.safeSearchCache, domain) assert.True(t, isFound) if assert.Len(t, cachedValue.Rules, 1) { assert.Equal(t, cachedValue.Rules[0].IP, net.IPv4(213, 180, 193, 56)) } } func TestSafeSearchCacheGoogle(t *testing.T) { d := NewForTest(nil, nil)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
} } func TestSafeSearchCacheGoogle(t *testing.T) { d := NewForTest(nil, nil) defer d.Close() domain := "www.google.ru" res, err := d.CheckHost(domain, dns.TypeA, &setts) assert.Nil(t, err) assert.False(t, res.IsFiltered) assert.Empty(t, res.Rules)
</s> remove d = NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() </s> add d = newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) </s> remove d := NewForTest(nil, nil) defer d.Close() </s> add d := newForTest(nil, nil) t.Cleanup(d.Close) </s> remove d = NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() </s> add d = newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) d.resolver = resolver </s> remove // Check host for each domain for _, host := range googleDomains { res, err := d.CheckHost(host, dns.TypeA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) if assert.Len(t, res.Rules, 1) { assert.NotEqual(t, res.Rules[0].IP.String(), "0.0.0.0") } </s> add func TestCheckHostSafeSearchGoogle(t *testing.T) { d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) d.resolver = &testResolver{} // Check host for each domain. for _, host := range []string{ "www.google.com", "www.google.im", "www.google.co.in", "www.google.iq", "www.google.is", "www.google.it", "www.google.je", } { t.Run(host, func(t *testing.T) { res, err := d.CheckHost(host, dns.TypeA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) assert.Len(t, res.Rules, 1) }) </s> remove defer d.Close() </s> add t.Cleanup(d.Close)
d := newForTest(nil, nil) t.Cleanup(d.Close) resolver := &testResolver{} d.resolver = resolver
} } func TestSafeSearchCacheGoogle(t *testing.T) { d := newForTest(nil, nil) t.Cleanup(d.Close) resolver := &testResolver{} d.resolver = resolver d := newForTest(nil, nil) t.Cleanup(d.Close) resolver := &testResolver{} d.resolver = resolver domain := "www.google.ru" res, err := d.CheckHost(domain, dns.TypeA, &setts) assert.Nil(t, err) assert.False(t, res.IsFiltered) assert.Empty(t, res.Rules)
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
assert.Nil(t, err) assert.False(t, res.IsFiltered) assert.Empty(t, res.Rules) d = NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() // Let's lookup for safesearch domain safeDomain, ok := d.SafeSearchDomain(domain) if !ok { t.Fatalf("Failed to get safesearch domain for %s", domain)
</s> remove // Let's lookup for safesearch domain </s> add // Lookup for safesearch domain. </s> remove if !ok { t.Fatalf("Failed to get safesearch domain for %s", domain) } </s> add assert.Truef(t, ok, "Failed to get safesearch domain for %s", domain) </s> remove ips, err := net.LookupIP(safeDomain) </s> add ipAddrs, err := resolver.LookupIPAddr(context.Background(), safeDomain) </s> remove d = NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() </s> add d = newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) </s> remove d := NewForTest(nil, nil) defer d.Close() </s> add d := newForTest(nil, nil) t.Cleanup(d.Close) resolver := &testResolver{} d.resolver = resolver
d = newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) d.resolver = resolver
assert.Nil(t, err) assert.False(t, res.IsFiltered) assert.Empty(t, res.Rules) d = newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) d.resolver = resolver d = newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) d.resolver = resolver // Let's lookup for safesearch domain safeDomain, ok := d.SafeSearchDomain(domain) if !ok { t.Fatalf("Failed to get safesearch domain for %s", domain)
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
d = NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() // Let's lookup for safesearch domain safeDomain, ok := d.SafeSearchDomain(domain) if !ok { t.Fatalf("Failed to get safesearch domain for %s", domain) }
</s> remove if !ok { t.Fatalf("Failed to get safesearch domain for %s", domain) } </s> add assert.Truef(t, ok, "Failed to get safesearch domain for %s", domain) </s> remove d = NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() </s> add d = newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) d.resolver = resolver </s> remove ips, err := net.LookupIP(safeDomain) </s> add ipAddrs, err := resolver.LookupIPAddr(context.Background(), safeDomain) </s> remove if !ok { t.Errorf("Expected safesearch to find result for www.google.com") } if val != "forcesafesearch.google.com" { t.Errorf("Expected safesearch for google.com to be forcesafesearch.google.com") } </s> add assert.True(t, ok, "Expected safesearch to find result for www.google.com") assert.Equal(t, "forcesafesearch.google.com", val, "Expected safesearch for google.com to be forcesafesearch.google.com") </s> remove if !ok { b.Errorf("Expected safesearch to find result for www.google.com") } if val != "forcesafesearch.google.com" { b.Errorf("Expected safesearch for google.com to be forcesafesearch.google.com") } </s> add assert.True(b, ok, "Expected safesearch to find result for www.google.com") assert.Equal(b, "forcesafesearch.google.com", val, "Expected safesearch for google.com to be forcesafesearch.google.com")
// Lookup for safesearch domain.
d = NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() // Lookup for safesearch domain. safeDomain, ok := d.SafeSearchDomain(domain) if !ok { t.Fatalf("Failed to get safesearch domain for %s", domain) }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
defer d.Close() // Let's lookup for safesearch domain safeDomain, ok := d.SafeSearchDomain(domain) if !ok { t.Fatalf("Failed to get safesearch domain for %s", domain) } ips, err := net.LookupIP(safeDomain) if err != nil { t.Fatalf("Failed to lookup for %s", safeDomain) }
</s> remove ips, err := net.LookupIP(safeDomain) </s> add ipAddrs, err := resolver.LookupIPAddr(context.Background(), safeDomain) </s> remove // Let's lookup for safesearch domain </s> add // Lookup for safesearch domain. </s> remove d = NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() </s> add d = newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) d.resolver = resolver </s> remove ip := ips[0] for _, i := range ips { if i.To4() != nil { ip = i </s> add ip := ipAddrs[0].IP for _, ipAddr := range ipAddrs { if ipAddr.IP.To4() != nil { ip = ipAddr.IP </s> remove if !ok { b.Errorf("Expected safesearch to find result for www.google.com") } if val != "forcesafesearch.google.com" { b.Errorf("Expected safesearch for google.com to be forcesafesearch.google.com") } </s> add assert.True(b, ok, "Expected safesearch to find result for www.google.com") assert.Equal(b, "forcesafesearch.google.com", val, "Expected safesearch for google.com to be forcesafesearch.google.com")
assert.Truef(t, ok, "Failed to get safesearch domain for %s", domain)
defer d.Close() // Let's lookup for safesearch domain safeDomain, ok := d.SafeSearchDomain(domain) assert.Truef(t, ok, "Failed to get safesearch domain for %s", domain) assert.Truef(t, ok, "Failed to get safesearch domain for %s", domain) assert.Truef(t, ok, "Failed to get safesearch domain for %s", domain) ips, err := net.LookupIP(safeDomain) if err != nil { t.Fatalf("Failed to lookup for %s", safeDomain) }
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
if !ok { t.Fatalf("Failed to get safesearch domain for %s", domain) } ips, err := net.LookupIP(safeDomain) if err != nil { t.Fatalf("Failed to lookup for %s", safeDomain) } ip := ips[0]
</s> remove if !ok { t.Fatalf("Failed to get safesearch domain for %s", domain) } </s> add assert.Truef(t, ok, "Failed to get safesearch domain for %s", domain) </s> remove ip := ips[0] for _, i := range ips { if i.To4() != nil { ip = i </s> add ip := ipAddrs[0].IP for _, ipAddr := range ipAddrs { if ipAddr.IP.To4() != nil { ip = ipAddr.IP </s> remove // Let's lookup for safesearch domain </s> add // Lookup for safesearch domain. </s> remove d = NewForTest(&Config{SafeSearchEnabled: true}, nil) defer d.Close() </s> add d = newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) d.resolver = resolver </s> remove if err != nil { t.Errorf("Error while matching host %s: %s", hostname, err) } if !res.IsFiltered { t.Errorf("Expected hostname %s to match", hostname) } if len(res.Rules) == 0 { t.Errorf("Expected result to have rules") return } r := res.Rules[0] if r.IP == nil || r.IP.String() != ip { t.Errorf("Expected ip %s to match, actual: %v", ip, r.IP) </s> add assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Truef(t, res.IsFiltered, "Expected hostname %s to match", hostname) if assert.NotEmpty(t, res.Rules, "Expected result to have rules") { r := res.Rules[0] assert.NotNilf(t, r.IP, "Expected ip %s to match, actual: %v", ip, r.IP) assert.Equalf(t, ip, r.IP.String(), "Expected ip %s to match, actual: %v", ip, r.IP)
ipAddrs, err := resolver.LookupIPAddr(context.Background(), safeDomain)
if !ok { t.Fatalf("Failed to get safesearch domain for %s", domain) } ipAddrs, err := resolver.LookupIPAddr(context.Background(), safeDomain) if err != nil { t.Fatalf("Failed to lookup for %s", safeDomain) } ip := ips[0]
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
if err != nil { t.Fatalf("Failed to lookup for %s", safeDomain) } ip := ips[0] for _, i := range ips { if i.To4() != nil { ip = i break } } res, err = d.CheckHost(domain, dns.TypeA, &setts)
</s> remove ips, err := net.LookupIP(safeDomain) </s> add ipAddrs, err := resolver.LookupIPAddr(context.Background(), safeDomain) </s> remove for _, ip := range ips { if ipv4 := ip.To4(); ipv4 != nil { </s> add for _, ipAddr := range ipAddrs { if ipv4 := ipAddr.IP.To4(); ipv4 != nil { </s> remove if !ok { t.Fatalf("Failed to get safesearch domain for %s", domain) } </s> add assert.Truef(t, ok, "Failed to get safesearch domain for %s", domain) </s> remove if err != nil { t.Errorf("Error while matching host %s: %s", hostname, err) } if !res.IsFiltered { t.Errorf("Expected hostname %s to match", hostname) } if len(res.Rules) == 0 { t.Errorf("Expected result to have rules") return } r := res.Rules[0] if r.IP == nil || r.IP.String() != ip { t.Errorf("Expected ip %s to match, actual: %v", ip, r.IP) </s> add assert.Nilf(t, err, "Error while matching host %s: %s", hostname, err) assert.Truef(t, res.IsFiltered, "Expected hostname %s to match", hostname) if assert.NotEmpty(t, res.Rules, "Expected result to have rules") { r := res.Rules[0] assert.NotNilf(t, r.IP, "Expected ip %s to match, actual: %v", ip, r.IP) assert.Equalf(t, ip, r.IP.String(), "Expected ip %s to match, actual: %v", ip, r.IP) </s> remove if gctx.safebrowsingCache != nil { gctx.safebrowsingCache.Clear() } if gctx.parentalCache != nil { gctx.parentalCache.Clear() } if gctx.safeSearchCache != nil { gctx.safeSearchCache.Clear() </s> add for _, c := range []cache.Cache{ gctx.safebrowsingCache, gctx.parentalCache, gctx.safeSearchCache, } { if c != nil { c.Clear() }
ip := ipAddrs[0].IP for _, ipAddr := range ipAddrs { if ipAddr.IP.To4() != nil { ip = ipAddr.IP
if err != nil { t.Fatalf("Failed to lookup for %s", safeDomain) } ip := ipAddrs[0].IP for _, ipAddr := range ipAddrs { if ipAddr.IP.To4() != nil { ip = ipAddr.IP ip := ipAddrs[0].IP for _, ipAddr := range ipAddrs { if ipAddr.IP.To4() != nil { ip = ipAddr.IP ip := ipAddrs[0].IP for _, ipAddr := range ipAddrs { if ipAddr.IP.To4() != nil { ip = ipAddr.IP ip := ipAddrs[0].IP for _, ipAddr := range ipAddrs { if ipAddr.IP.To4() != nil { ip = ipAddr.IP break } } res, err = d.CheckHost(domain, dns.TypeA, &setts)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
assert.True(t, cachedValue.Rules[0].IP.Equal(ip)) } } // PARENTAL func TestParentalControl(t *testing.T) { logOutput := &bytes.Buffer{} testutil.ReplaceLogWriter(t, logOutput) testutil.ReplaceLogLevel(t, log.DEBUG)
</s> remove // SAFE BROWSING </s> add // Safe Browsing. </s> remove d := NewForTest(&Config{SafeBrowsingEnabled: true}, nil) defer d.Close() d.checkMatch(t, "wmconvirus.narod.ru") </s> add d := newForTest(&Config{SafeBrowsingEnabled: true}, nil) t.Cleanup(d.Close) matching := "wmconvirus.narod.ru" d.safeBrowsingUpstream = &testSbUpstream{ hostname: matching, block: true, } d.checkMatch(t, matching) </s> remove d := NewForTest(&Config{ParentalEnabled: true}, nil) defer d.Close() d.checkMatch(t, "pornhub.com") assert.Contains(t, logOutput.String(), "Parental lookup for pornhub.com") d.checkMatch(t, "www.pornhub.com") </s> add d := newForTest(&Config{ParentalEnabled: true}, nil) t.Cleanup(d.Close) matching := "pornhub.com" d.parentalUpstream = &testSbUpstream{ hostname: matching, block: true, } d.checkMatch(t, matching) assert.Contains(t, logOutput.String(), "Parental lookup for "+matching) d.checkMatch(t, "www."+matching) </s> remove // HELPERS // SAFE BROWSING // SAFE SEARCH // PARENTAL // FILTERING // BENCHMARKS // HELPERS </s> add // Helpers. </s> remove // Check host for each domain for _, host := range googleDomains { res, err := d.CheckHost(host, dns.TypeA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) if assert.Len(t, res.Rules, 1) { assert.NotEqual(t, res.Rules[0].IP.String(), "0.0.0.0") } </s> add func TestCheckHostSafeSearchGoogle(t *testing.T) { d := newForTest(&Config{SafeSearchEnabled: true}, nil) t.Cleanup(d.Close) d.resolver = &testResolver{} // Check host for each domain. for _, host := range []string{ "www.google.com", "www.google.im", "www.google.co.in", "www.google.iq", "www.google.is", "www.google.it", "www.google.je", } { t.Run(host, func(t *testing.T) { res, err := d.CheckHost(host, dns.TypeA, &setts) assert.Nil(t, err) assert.True(t, res.IsFiltered) assert.Len(t, res.Rules, 1) })
// Parental.
assert.True(t, cachedValue.Rules[0].IP.Equal(ip)) } } // Parental. func TestParentalControl(t *testing.T) { logOutput := &bytes.Buffer{} testutil.ReplaceLogWriter(t, logOutput) testutil.ReplaceLogLevel(t, log.DEBUG)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
logOutput := &bytes.Buffer{} testutil.ReplaceLogWriter(t, logOutput) testutil.ReplaceLogLevel(t, log.DEBUG) d := NewForTest(&Config{ParentalEnabled: true}, nil) defer d.Close() d.checkMatch(t, "pornhub.com") assert.Contains(t, logOutput.String(), "Parental lookup for pornhub.com") d.checkMatch(t, "www.pornhub.com") d.checkMatchEmpty(t, "www.yandex.ru") d.checkMatchEmpty(t, "yandex.ru") d.checkMatchEmpty(t, "api.jquery.com") // test cached result
</s> remove d := NewForTest(&Config{SafeBrowsingEnabled: true}, nil) defer d.Close() d.checkMatch(t, "wmconvirus.narod.ru") </s> add d := newForTest(&Config{SafeBrowsingEnabled: true}, nil) t.Cleanup(d.Close) matching := "wmconvirus.narod.ru" d.safeBrowsingUpstream = &testSbUpstream{ hostname: matching, block: true, } d.checkMatch(t, matching) </s> remove d.checkMatch(t, "test.wmconvirus.narod.ru") </s> add d.checkMatch(t, "test."+matching) </s> remove assert.Contains(t, logOutput.String(), "SafeBrowsing lookup for wmconvirus.narod.ru") </s> add assert.Contains(t, logOutput.String(), "SafeBrowsing lookup for "+matching) </s> remove d.checkMatch(t, "pornhub.com") </s> add d.checkMatch(t, matching) </s> remove // test cached result </s> add // Cached result.
d := newForTest(&Config{ParentalEnabled: true}, nil) t.Cleanup(d.Close) matching := "pornhub.com" d.parentalUpstream = &testSbUpstream{ hostname: matching, block: true, } d.checkMatch(t, matching) assert.Contains(t, logOutput.String(), "Parental lookup for "+matching) d.checkMatch(t, "www."+matching)
logOutput := &bytes.Buffer{} testutil.ReplaceLogWriter(t, logOutput) testutil.ReplaceLogLevel(t, log.DEBUG) d := newForTest(&Config{ParentalEnabled: true}, nil) t.Cleanup(d.Close) matching := "pornhub.com" d.parentalUpstream = &testSbUpstream{ hostname: matching, block: true, } d.checkMatch(t, matching) assert.Contains(t, logOutput.String(), "Parental lookup for "+matching) d.checkMatch(t, "www."+matching) d := newForTest(&Config{ParentalEnabled: true}, nil) t.Cleanup(d.Close) matching := "pornhub.com" d.parentalUpstream = &testSbUpstream{ hostname: matching, block: true, } d.checkMatch(t, matching) assert.Contains(t, logOutput.String(), "Parental lookup for "+matching) d.checkMatch(t, "www."+matching) d := newForTest(&Config{ParentalEnabled: true}, nil) t.Cleanup(d.Close) matching := "pornhub.com" d.parentalUpstream = &testSbUpstream{ hostname: matching, block: true, } d.checkMatch(t, matching) assert.Contains(t, logOutput.String(), "Parental lookup for "+matching) d.checkMatch(t, "www."+matching) d := newForTest(&Config{ParentalEnabled: true}, nil) t.Cleanup(d.Close) matching := "pornhub.com" d.parentalUpstream = &testSbUpstream{ hostname: matching, block: true, } d.checkMatch(t, matching) assert.Contains(t, logOutput.String(), "Parental lookup for "+matching) d.checkMatch(t, "www."+matching) d := newForTest(&Config{ParentalEnabled: true}, nil) t.Cleanup(d.Close) matching := "pornhub.com" d.parentalUpstream = &testSbUpstream{ hostname: matching, block: true, } d.checkMatch(t, matching) assert.Contains(t, logOutput.String(), "Parental lookup for "+matching) d.checkMatch(t, "www."+matching) d.checkMatchEmpty(t, "www.yandex.ru") d.checkMatchEmpty(t, "yandex.ru") d.checkMatchEmpty(t, "api.jquery.com") // test cached result
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go
d.checkMatchEmpty(t, "api.jquery.com") // test cached result d.parentalServer = "127.0.0.1" d.checkMatch(t, "pornhub.com") d.checkMatchEmpty(t, "yandex.ru") d.parentalServer = defaultParentalServer } // FILTERING
</s> remove // test cached result </s> add // Cached result. </s> remove d.checkMatch(t, "test.wmconvirus.narod.ru") </s> add d.checkMatch(t, "test."+matching) </s> remove d.checkMatch(t, "wmconvirus.narod.ru") </s> add d.checkMatch(t, matching) </s> remove d := NewForTest(&Config{ParentalEnabled: true}, nil) defer d.Close() d.checkMatch(t, "pornhub.com") assert.Contains(t, logOutput.String(), "Parental lookup for pornhub.com") d.checkMatch(t, "www.pornhub.com") </s> add d := newForTest(&Config{ParentalEnabled: true}, nil) t.Cleanup(d.Close) matching := "pornhub.com" d.parentalUpstream = &testSbUpstream{ hostname: matching, block: true, } d.checkMatch(t, matching) assert.Contains(t, logOutput.String(), "Parental lookup for "+matching) d.checkMatch(t, "www."+matching) </s> remove d.checkMatch(t, "wmconvirus.narod.ru") d.checkMatch(t, "test.wmconvirus.narod.ru") </s> add d.checkMatch(t, matching) d.checkMatch(t, "test."+matching)
d.checkMatch(t, matching)
d.checkMatchEmpty(t, "api.jquery.com") // test cached result d.parentalServer = "127.0.0.1" d.checkMatch(t, matching) d.checkMatchEmpty(t, "yandex.ru") d.parentalServer = defaultParentalServer } // FILTERING
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2574 external tests vol.1 Merge in DNS/adguard-home from 2574-external-tests to master Updates #2574. Squashed commit of the following: commit cb7017aa7fc1c81c014c1fa7e0972b06748aff29 Merge: 2a073431 eeeb0383 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:43:41 2021 +0300 Merge branch 'master' into 2574-external-tests commit 2a0734311c5a6ddd2d9c3f56a4494a20b4197955 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 15:16:40 2021 +0300 dnsfilter: imp docs commit 49aff871282e2739d27fcbceefdf1bd005c21174 Author: Eugene Burkov <[email protected]> Date: Fri Jan 29 14:10:56 2021 +0300 dnsfilter: imp docs commit 11be89a5378c0e451f1b88dc48a2e8827ba38358 Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 21:20:55 2021 +0300 dnsfilter: fix go version trouble commit 1ba4afd95bd739c18818ab0bea0ae70d59b880dc Author: Eugene Burkov <[email protected]> Date: Thu Jan 28 17:42:29 2021 +0300 dnsfilter: imp tests
https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc
internal/dnsfilter/dnsfilter_test.go