docstring_tokens
stringlengths 18
16.9k
| code_tokens
stringlengths 75
1.81M
| html_url
stringlengths 74
116
| file_name
stringlengths 3
311
|
---|---|---|---|
keep keep keep keep replace replace keep keep keep keep keep | <mask> upstreams = stringutil.FilterOut(upstreams, IsCommentOrEmpty)
<mask> upstreamConfig, err := proxy.ParseUpstreamsConfig(
<mask> upstreams,
<mask> &upstream.Options{
<mask> Bootstrap: s.conf.BootstrapDNS,
<mask> Timeout: s.conf.UpstreamTimeout,
<mask> },
<mask> )
<mask> if err != nil {
<mask> return fmt.Errorf("parsing upstream config: %w", err)
<mask> }
</s> 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 </s> add httpVersions := UpstreamHTTPVersions(s.conf.UseHTTP3Upstreams) </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: 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 &upstream.Options{Bootstrap: []string{}, Timeout: DefaultTimeout},
</s> add &upstream.Options{
Bootstrap: []string{},
Timeout: DefaultTimeout,
}, </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) | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/dnsforward/config.go |
keep keep keep keep replace replace keep keep keep keep keep | <mask> var uc *proxy.UpstreamConfig
<mask> uc, err = proxy.ParseUpstreamsConfig(
<mask> defaultDNS,
<mask> &upstream.Options{
<mask> Bootstrap: s.conf.BootstrapDNS,
<mask> Timeout: s.conf.UpstreamTimeout,
<mask> },
<mask> )
<mask> if err != nil {
<mask> return fmt.Errorf("parsing default upstreams: %w", err)
<mask> }
</s> 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 </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: 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 &upstream.Options{Bootstrap: []string{}, Timeout: DefaultTimeout},
</s> add &upstream.Options{
Bootstrap: []string{},
Timeout: DefaultTimeout,
}, </s> add httpVersions := UpstreamHTTPVersions(s.conf.UseHTTP3Upstreams) </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) | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/dnsforward/config.go |
keep keep keep keep replace keep keep keep keep keep | <mask> return &res, err
<mask> }
<mask>
<mask> // filterDNSResponse checks each resource record of the response's answer
<mask> // section from pctx and returns a non-nil res if at least one of canonnical
<mask> // names or IP addresses in it matches the filtering rules.
<mask> func (s *Server) filterDNSResponse(
<mask> pctx *proxy.DNSContext,
<mask> setts *filtering.Settings,
<mask> ) (res *filtering.Result, err error) {
</s> 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 </s> add // UpstreamHTTPVersions returns the HTTP versions for upstream configuration
// depending on configuration.
func UpstreamHTTPVersions(http3 bool) (v []upstream.HTTPVersion) {
if !http3 {
return upstream.DefaultHTTPVersions
}
return []upstream.HTTPVersion{
upstream.HTTPVersion3,
upstream.HTTPVersion2,
upstream.HTTPVersion11,
}
}
</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 != 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> add // LocalPTRResolvers is a slice of addresses to be used as upstreams for
// resolving PTR queries for local addresses.
LocalPTRResolvers []string
</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 // 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") | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/dnsforward/filter.go |
keep keep keep keep replace replace replace replace replace replace replace keep keep keep keep keep | <mask> jsonDNSConfig: *s.getDNSConfig(),
<mask> DefautLocalPTRUpstreams: defLocalPTRUps,
<mask> }
<mask>
<mask> w.Header().Set("Content-Type", "application/json")
<mask>
<mask> if err = json.NewEncoder(w).Encode(resp); err != nil {
<mask> aghhttp.Error(r, w, http.StatusInternalServerError, "json.Encoder: %s", err)
<mask>
<mask> return
<mask> }
<mask> }
<mask>
<mask> func (req *jsonDNSConfig) checkBlockingMode() (err error) {
<mask> if req.BlockingMode == nil {
<mask> return nil
</s> 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 </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 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 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 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 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) | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/dnsforward/http.go |
keep keep keep keep replace keep keep keep keep keep | <mask> }
<mask>
<mask> conf, err = proxy.ParseUpstreamsConfig(
<mask> upstreams,
<mask> &upstream.Options{Bootstrap: []string{}, Timeout: DefaultTimeout},
<mask> )
<mask> if err != nil {
<mask> return nil, err
<mask> } else if len(conf.Upstreams) == 0 {
<mask> return nil, errors.Error("no default upstreams specified")
</s> 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 </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 Bootstrap: s.conf.BootstrapDNS,
Timeout: s.conf.UpstreamTimeout,
</s> add Bootstrap: s.conf.BootstrapDNS,
Timeout: s.conf.UpstreamTimeout,
HTTPVersions: httpVersions, </s> add httpVersions := UpstreamHTTPVersions(s.conf.UseHTTP3Upstreams) </s> remove Bootstrap: s.conf.BootstrapDNS,
Timeout: s.conf.UpstreamTimeout,
</s> add Bootstrap: s.conf.BootstrapDNS,
Timeout: s.conf.UpstreamTimeout,
HTTPVersions: httpVersions, </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 web = CreateWeb(&webConf)
</s> add web = newWeb(&webConf) | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/dnsforward/http.go |
keep keep keep keep replace keep keep keep keep keep | <mask>
<mask> return nil
<mask> }
<mask>
<mask> var protocols = []string{"udp://", "tcp://", "tls://", "https://", "sdns://", "quic://"}
<mask>
<mask> // validateUpstream returns an error if u alongside with domains is not a valid
<mask> // upstream configuration. useDefault is true if the upstream is
<mask> // domain-specific and is configured to point at the default upstream server
<mask> // which is validated separately. The upstream is considered domain-specific
</s> 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 </s> add // UpstreamHTTPVersions returns the HTTP versions for upstream configuration
// depending on configuration.
func UpstreamHTTPVersions(http3 bool) (v []upstream.HTTPVersion) {
if !http3 {
return upstream.DefaultHTTPVersions
}
return []upstream.HTTPVersion{
upstream.HTTPVersion3,
upstream.HTTPVersion2,
upstream.HTTPVersion11,
}
}
</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> add // shutdownSrv shuts srv down and prints error messages to the log. </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 Bootstrap: s.conf.BootstrapDNS,
Timeout: s.conf.UpstreamTimeout,
</s> add Bootstrap: s.conf.BootstrapDNS,
Timeout: s.conf.UpstreamTimeout,
HTTPVersions: httpVersions, </s> remove // section from pctx and returns a non-nil res if at least one of canonnical
</s> add // section from pctx and returns a non-nil res if at least one of canonical | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/dnsforward/http.go |
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep | <mask>
<mask> result[host] = "OK"
<mask> }
<mask>
<mask> jsonVal, err := json.Marshal(result)
<mask> if err != nil {
<mask> aghhttp.Error(
<mask> r,
<mask> w,
<mask> http.StatusInternalServerError,
<mask> "Unable to marshal status json: %s",
<mask> err,
<mask> )
<mask>
<mask> return
<mask> }
<mask>
<mask> w.Header().Set("Content-Type", "application/json")
<mask> _, err = w.Write(jsonVal)
<mask> if err != nil {
<mask> aghhttp.Error(r, w, http.StatusInternalServerError, "Couldn't write body: %s", err)
<mask> }
<mask> }
<mask>
<mask> // handleDoH is the DNS-over-HTTPs handler.
<mask> //
<mask> // Control flow:
</s> 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 </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) </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
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 log.Fatal(err)
</s> add log.Fatalf("web: https: %s", err) | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/dnsforward/http.go |
keep keep keep add keep keep keep keep keep keep | <mask> "path/filepath"
<mask> "strings"
<mask> "testing"
<mask>
<mask> "github.com/AdguardTeam/AdGuardHome/internal/aghnet"
<mask> "github.com/AdguardTeam/AdGuardHome/internal/filtering"
<mask> "github.com/AdguardTeam/golibs/netutil"
<mask> "github.com/AdguardTeam/golibs/testutil"
<mask> "github.com/stretchr/testify/assert"
<mask> "github.com/stretchr/testify/require"
</s> 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 </s> add "github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/http3" </s> remove log.Fatal(err)
</s> add log.Fatalf("web: https: %s", err) </s> remove // section from pctx and returns a non-nil res if at least one of canonnical
</s> add // section from pctx and returns a non-nil res if at least one of canonical </s> add HTTP3: srvConf.ServeHTTP3, </s> add // UpstreamHTTPVersions returns the HTTP versions for upstream configuration
// depending on configuration.
func UpstreamHTTPVersions(http3 bool) (v []upstream.HTTPVersion) {
if !http3 {
return upstream.DefaultHTTPVersions
}
return []upstream.HTTPVersion{
upstream.HTTPVersion3,
upstream.HTTPVersion2,
upstream.HTTPVersion11,
}
}
</s> add httpVersions := UpstreamHTTPVersions(s.conf.UseHTTP3Upstreams) | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/dnsforward/http_test.go |
keep keep keep keep replace keep keep keep keep keep | <mask>
<mask> s.conf = tc.conf()
<mask> s.handleGetConfig(w, nil)
<mask>
<mask> assert.Equal(t, "application/json", w.Header().Get("Content-Type"))
<mask> assert.JSONEq(t, string(caseWant), w.Body.String())
<mask> })
<mask> }
<mask> }
<mask>
</s> 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 </s> add HTTP3: srvConf.ServeHTTP3, </s> remove if err != http.ErrServerClosed {
</s> add if !errors.Is(err, http.ErrServerClosed) { </s> add if web.conf.serveHTTP3 {
go web.mustStartHTTP3(addr)
}
log.Debug("web: starting https server") </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) </s> remove _, _ = w.Write(data)
</s> add _ = aghhttp.WriteJSONResponse(w, r, resp) | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/dnsforward/http_test.go |
keep keep keep keep replace replace keep keep keep keep keep | <mask> var conf *proxy.UpstreamConfig
<mask> conf, err = proxy.ParseUpstreamsConfig(
<mask> upstreams,
<mask> &upstream.Options{
<mask> Bootstrap: config.DNS.BootstrapDNS,
<mask> Timeout: config.DNS.UpstreamTimeout.Duration,
<mask> },
<mask> )
<mask> if err != nil {
<mask> return nil, err
<mask> }
</s> 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 </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> add httpVersions := UpstreamHTTPVersions(s.conf.UseHTTP3Upstreams) </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) | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/home/clients.go |
keep keep add keep keep keep keep keep keep | <mask> // LocalPTRResolvers is the slice of addresses to be used as upstreams
<mask> // for PTR queries for locally-served networks.
<mask> LocalPTRResolvers []string `yaml:"local_ptr_upstreams"`
<mask> }
<mask>
<mask> type tlsConfigSettings struct {
<mask> Enabled bool `yaml:"enabled" json:"enabled"` // Enabled is the encryption (DoT/DoH/HTTPS) status
<mask> ServerName string `yaml:"server_name" json:"server_name,omitempty"` // ServerName is the hostname of your HTTPS/TLS server
<mask> ForceHTTPS bool `yaml:"force_https" json:"force_https"` // ForceHTTPS: if true, forces HTTP->HTTPS redirect
</s> 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 </s> add // LocalPTRResolvers is a slice of addresses to be used as upstreams for
// resolving PTR queries for local addresses.
LocalPTRResolvers []string
</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> add serveHTTP3 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 // 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 | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/home/config.go |
keep keep keep replace keep keep keep keep keep | <mask> package home
<mask>
<mask> import (
<mask> "encoding/json"
<mask> "fmt"
<mask> "net"
<mask> "net/http"
<mask> "net/url"
<mask> "runtime"
</s> 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 </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> add // 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"` </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 assert.Equal(t, "application/json", w.Header().Get("Content-Type"))
</s> add cType := w.Header().Get(aghhttp.HdrNameContentType)
assert.Equal(t, aghhttp.HdrValApplicationJSON, cType) | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/home/control.go |
keep keep keep keep replace keep keep keep keep keep | <mask> Name string `json:"name"`
<mask> }
<mask>
<mask> func handleGetProfile(w http.ResponseWriter, r *http.Request) {
<mask> pj := profileJSON{}
<mask> u := Context.auth.getCurrentUser(r)
<mask>
<mask> pj.Name = u.Name
<mask>
<mask> data, err := json.Marshal(pj)
</s> 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 </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> add httpVersions := UpstreamHTTPVersions(s.conf.UseHTTP3Upstreams) </s> remove log.Fatal(err)
</s> add log.Fatalf("web: https: %s", err) </s> add if web.conf.serveHTTP3 {
go web.mustStartHTTP3(addr)
}
log.Debug("web: starting https server") | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/home/control.go |
keep keep keep keep replace replace replace replace replace replace replace replace keep keep keep keep keep keep keep keep replace keep keep | <mask>
<mask> func handleGetProfile(w http.ResponseWriter, r *http.Request) {
<mask> pj := profileJSON{}
<mask> u := Context.auth.getCurrentUser(r)
<mask>
<mask> pj.Name = u.Name
<mask>
<mask> data, err := json.Marshal(pj)
<mask> if err != nil {
<mask> aghhttp.Error(r, w, http.StatusInternalServerError, "json.Marshal: %s", err)
<mask>
<mask> return
<mask> }
<mask>
<mask> _, _ = w.Write(data)
<mask> }
<mask>
<mask> return
<mask> }
<mask>
<mask> _, _ = w.Write(data)
<mask> }
<mask>
</s> 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 </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) | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/home/control.go |
keep add keep keep keep keep keep keep | <mask> "github.com/AdguardTeam/golibs/errors"
<mask> "github.com/AdguardTeam/golibs/log"
<mask> )
<mask>
<mask> // getAddrsResponse is the response for /install/get_addresses endpoint.
<mask> type getAddrsResponse struct {
<mask> Interfaces map[string]*aghnet.NetInterface `json:"interfaces"`
<mask>
</s> 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 </s> add "github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/http3" </s> add serveHTTP3 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 </s> remove // Web - module object
</s> add // Web is the web UI and API server. </s> add // 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"` | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/home/controlinstall.go |
keep keep keep add keep keep keep keep keep keep | <mask>
<mask> // shutdownTimeout is the timeout for shutting HTTP server down operation.
<mask> const shutdownTimeout = 5 * time.Second
<mask>
<mask> func shutdownSrv(ctx context.Context, srv *http.Server) {
<mask> defer log.OnPanic("")
<mask>
<mask> if srv == nil {
<mask> return
<mask> }
</s> 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 </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> add // UpstreamHTTPVersions returns the HTTP versions for upstream configuration
// depending on configuration.
func UpstreamHTTPVersions(http3 bool) (v []upstream.HTTPVersion) {
if !http3 {
return upstream.DefaultHTTPVersions
}
return []upstream.HTTPVersion{
upstream.HTTPVersion3,
upstream.HTTPVersion2,
upstream.HTTPVersion11,
}
}
</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 = CreateWeb(&webConf)
</s> add web = newWeb(&webConf) | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/home/controlinstall.go |
keep keep keep keep replace replace replace replace replace replace replace keep keep keep keep keep | <mask> return
<mask> }
<mask>
<mask> err := srv.Shutdown(ctx)
<mask> if err != nil {
<mask> const msgFmt = "shutting down http server %q: %s"
<mask> if errors.Is(err, context.Canceled) {
<mask> log.Debug(msgFmt, srv.Addr, err)
<mask> } else {
<mask> log.Error(msgFmt, srv.Addr, err)
<mask> }
<mask> }
<mask> }
<mask>
<mask> // PasswordMinRunes is the minimum length of user's password in runes.
<mask> const PasswordMinRunes = 8
</s> 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 </s> add // shutdownSrv shuts srv down and prints error messages to the log. </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, </s> remove &upstream.Options{Bootstrap: []string{}, Timeout: DefaultTimeout},
</s> add &upstream.Options{
Bootstrap: []string{},
Timeout: DefaultTimeout,
}, | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/home/controlinstall.go |
keep keep keep keep replace replace replace replace replace replace replace keep keep keep keep keep | <mask> nonBetaReqBody := &strings.Builder{}
<mask>
<mask> err = json.NewEncoder(nonBetaReqBody).Encode(nonBetaReqData)
<mask> if err != nil {
<mask> aghhttp.Error(
<mask> r,
<mask> w,
<mask> http.StatusBadRequest,
<mask> "Failed to encode 'check_config' JSON data: %s",
<mask> err,
<mask> )
<mask>
<mask> return
<mask> }
<mask> body := nonBetaReqBody.String()
<mask> r.Body = io.NopCloser(strings.NewReader(body))
</s> 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 </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) { </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()) | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/home/controlinstall.go |
keep keep keep keep replace replace replace replace replace replace replace keep keep keep keep keep | <mask> nonBetaReqBody := &strings.Builder{}
<mask>
<mask> err = json.NewEncoder(nonBetaReqBody).Encode(nonBetaReqData)
<mask> if err != nil {
<mask> aghhttp.Error(
<mask> r,
<mask> w,
<mask> http.StatusBadRequest,
<mask> "Failed to encode 'check_config' JSON data: %s",
<mask> err,
<mask> )
<mask>
<mask> return
<mask> }
<mask> body := nonBetaReqBody.String()
<mask> r.Body = io.NopCloser(strings.NewReader(body))
</s> 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 </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) { </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()) | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/home/controlinstall.go |
keep keep keep keep replace replace keep keep keep keep keep | <mask>
<mask> newConf.FilterHandler = applyAdditionalFiltering
<mask> newConf.GetCustomUpstreamByClient = Context.clients.findUpstreams
<mask>
<mask> newConf.ResolveClients = config.Clients.Sources.RDNS
<mask> newConf.UsePrivateRDNS = dnsConf.UsePrivateRDNS
<mask> newConf.LocalPTRResolvers = dnsConf.LocalPTRResolvers
<mask> newConf.UpstreamTimeout = dnsConf.UpstreamTimeout.Duration
<mask>
<mask> return newConf, nil
<mask> }
</s> 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 </s> add newConf.ResolveClients = config.Clients.Sources.RDNS
newConf.UsePrivateRDNS = dnsConf.UsePrivateRDNS
newConf.ServeHTTP3 = dnsConf.ServeHTTP3
newConf.UseHTTP3Upstreams = dnsConf.UseHTTP3Upstreams
</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) </s> remove &upstream.Options{Bootstrap: []string{}, Timeout: DefaultTimeout},
</s> add &upstream.Options{
Bootstrap: []string{},
Timeout: DefaultTimeout,
}, | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/home/dns.go |
keep keep keep add keep keep keep keep keep | <mask>
<mask> newConf.LocalPTRResolvers = dnsConf.LocalPTRResolvers
<mask> newConf.UpstreamTimeout = dnsConf.UpstreamTimeout.Duration
<mask>
<mask> return newConf, nil
<mask> }
<mask>
<mask> func newDNSCrypt(hosts []net.IP, tlsConf tlsConfigSettings) (dnscc dnsforward.DNSCryptConfig, err error) {
<mask> if tlsConf.DNSCryptConfigFile == "" {
</s> 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 </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) </s> remove log.Debug("Web: applying new TLS configuration")
</s> add log.Debug("web: applying new tls configuration") | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/home/dns.go |
keep keep keep add keep keep keep keep | <mask> WriteTimeout: writeTimeout,
<mask>
<mask> clientFS: clientFS,
<mask> clientBetaFS: clientBetaFS,
<mask> }
<mask>
<mask> web = newWeb(&webConf)
<mask> if web == nil {
</s> 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 </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> add if web.conf.serveHTTP3 {
go web.mustStartHTTP3(addr)
}
log.Debug("web: starting https server") </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 // Web - module object
</s> add // Web is the web UI and API server. | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/home/home.go |
keep keep keep keep replace keep keep keep keep keep | <mask> clientFS: clientFS,
<mask> clientBetaFS: clientBetaFS,
<mask> }
<mask>
<mask> web = CreateWeb(&webConf)
<mask> if web == nil {
<mask> return nil, fmt.Errorf("initializing web: %w", err)
<mask> }
<mask>
<mask> return web, nil
</s> 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 </s> add serveHTTP3: config.DNS.ServeHTTP3, </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, </s> remove Bootstrap: s.conf.BootstrapDNS,
Timeout: s.conf.UpstreamTimeout,
</s> add Bootstrap: s.conf.BootstrapDNS,
Timeout: s.conf.UpstreamTimeout,
HTTPVersions: httpVersions, | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/home/home.go |
keep keep keep keep replace keep keep keep keep keep | <mask> return
<mask> }
<mask> }
<mask>
<mask> if !WebCheckPortAvailable(setts.PortHTTPS) {
<mask> aghhttp.Error(
<mask> r,
<mask> w,
<mask> http.StatusBadRequest,
<mask> "port %d is not available, cannot enable HTTPS on it",
</s> 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 </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) </s> add // UpstreamHTTPVersions returns the HTTP versions for upstream configuration
// depending on configuration.
func UpstreamHTTPVersions(http3 bool) (v []upstream.HTTPVersion) {
if !http3 {
return upstream.DefaultHTTPVersions
}
return []upstream.HTTPVersion{
upstream.HTTPVersion3,
upstream.HTTPVersion2,
upstream.HTTPVersion11,
}
}
</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()) | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/home/tls.go |
keep keep keep keep replace keep keep keep keep keep | <mask> }
<mask> }
<mask>
<mask> // TODO(e.burkov): Investigate and perhaps check other ports.
<mask> if !WebCheckPortAvailable(data.PortHTTPS) {
<mask> aghhttp.Error(
<mask> r,
<mask> w,
<mask> http.StatusBadRequest,
<mask> "port %d is not available, cannot enable HTTPS on it",
</s> 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 </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) { </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()) | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/home/tls.go |
keep keep keep add keep keep keep keep | <mask> "github.com/AdguardTeam/golibs/errors"
<mask> "github.com/AdguardTeam/golibs/log"
<mask> "github.com/AdguardTeam/golibs/netutil"
<mask> "github.com/NYTimes/gziphandler"
<mask> "golang.org/x/net/http2"
<mask> "golang.org/x/net/http2/h2c"
<mask> )
<mask>
</s> 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 </s> add "github.com/lucas-clemente/quic-go/http3" </s> add "github.com/AdguardTeam/AdGuardHome/internal/aghhttp" </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, </s> remove Bootstrap: s.conf.BootstrapDNS,
Timeout: s.conf.UpstreamTimeout,
</s> add Bootstrap: s.conf.BootstrapDNS,
Timeout: s.conf.UpstreamTimeout,
HTTPVersions: httpVersions, | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/home/web.go |
keep keep keep add keep keep keep keep keep | <mask> // appropriate field.
<mask> WriteTimeout time.Duration
<mask>
<mask> firstRun bool
<mask> }
<mask>
<mask> // httpsServer contains the data for the HTTPS server.
<mask> type httpsServer struct {
<mask> // server is the pre-HTTP/3 HTTPS server.
</s> 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 </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) { </s> add // 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"` | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/home/web.go |
keep replace replace replace replace replace replace replace replace keep keep replace keep keep keep keep | <mask>
<mask> // HTTPSServer - HTTPS Server
<mask> type HTTPSServer struct {
<mask> server *http.Server
<mask> cond *sync.Cond
<mask> condLock sync.Mutex
<mask> shutdown bool // if TRUE, don't restart the server
<mask> enabled bool
<mask> cert tls.Certificate
<mask> }
<mask>
<mask> // Web - module object
<mask> type Web struct {
<mask> conf *webConfig
<mask> forceHTTPS bool
<mask> httpServer *http.Server // HTTP module
</s> 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 </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> add serveHTTP3 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") </s> add // 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"` | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/home/web.go |
keep keep keep keep replace replace replace replace keep keep keep keep keep | <mask> }
<mask>
<mask> // Web - module object
<mask> type Web struct {
<mask> conf *webConfig
<mask> forceHTTPS bool
<mask> httpServer *http.Server // HTTP module
<mask> httpsServer HTTPSServer // HTTPS module
<mask>
<mask> // handlerBeta is the handler for new client.
<mask> handlerBeta http.Handler
<mask> // installerBeta is the pre-install handler for new client.
<mask> installerBeta http.Handler
</s> 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 </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") </s> add serveHTTP3 bool </s> add // LocalPTRResolvers is a slice of addresses to be used as upstreams for
// resolving PTR queries for local addresses.
LocalPTRResolvers []string
| https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/home/web.go |
keep replace replace keep keep replace replace replace keep keep keep | <mask>
<mask> // httpServerBeta is a server for new client.
<mask> httpServerBeta *http.Server
<mask> }
<mask>
<mask> // CreateWeb - create module
<mask> func CreateWeb(conf *webConfig) *Web {
<mask> log.Info("Initialize web module")
<mask>
<mask> w := Web{}
<mask> w.conf = conf
</s> 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 </s> remove w := Web{}
w.conf = conf
</s> add w = &Web{
conf: conf,
} </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 </s> remove return &w
</s> add return w | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/home/web.go |
keep keep keep keep replace replace keep keep keep keep keep | <mask> // CreateWeb - create module
<mask> func CreateWeb(conf *webConfig) *Web {
<mask> log.Info("Initialize web module")
<mask>
<mask> w := Web{}
<mask> w.conf = conf
<mask>
<mask> clientFS := http.FileServer(http.FS(conf.clientFS))
<mask> betaClientFS := http.FileServer(http.FS(conf.clientBetaFS))
<mask>
<mask> // if not configured, redirect / to /install.html, otherwise redirect /install.html to /
</s> 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 </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 </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) | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/home/web.go |
keep keep keep keep replace keep keep replace replace replace keep keep keep keep | <mask> registerControlHandlers()
<mask> }
<mask>
<mask> w.httpsServer.cond = sync.NewCond(&w.httpsServer.condLock)
<mask> return &w
<mask> }
<mask>
<mask> // WebCheckPortAvailable - check if port is available
<mask> // BUT: if we are already using this port, no need
<mask> func WebCheckPortAvailable(port int) bool {
<mask> return Context.web.httpsServer.server != nil ||
<mask> aghnet.CheckPort("tcp", config.BindHost, port) == nil
<mask> }
<mask>
</s> 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 </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 if web.httpsServer.shutdown {
</s> add if web.httpsServer.inShutdown { </s> remove web = CreateWeb(&webConf)
</s> add web = newWeb(&webConf) </s> remove &upstream.Options{Bootstrap: []string{}, Timeout: DefaultTimeout},
</s> add &upstream.Options{
Bootstrap: []string{},
Timeout: DefaultTimeout,
}, | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/home/web.go |
keep keep keep keep replace keep keep keep keep keep | <mask>
<mask> // TLSConfigChanged updates the TLS configuration and restarts the HTTPS server
<mask> // if necessary.
<mask> func (web *Web) TLSConfigChanged(ctx context.Context, tlsConf tlsConfigSettings) {
<mask> log.Debug("Web: applying new TLS configuration")
<mask> web.conf.PortHTTPS = tlsConf.PortHTTPS
<mask> web.forceHTTPS = (tlsConf.ForceHTTPS && tlsConf.Enabled && tlsConf.PortHTTPS != 0)
<mask>
<mask> enabled := tlsConf.Enabled &&
<mask> tlsConf.PortHTTPS != 0 &&
</s> 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 </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> add // UpstreamHTTPVersions returns the HTTP versions for upstream configuration
// depending on configuration.
func UpstreamHTTPVersions(http3 bool) (v []upstream.HTTPVersion) {
if !http3 {
return upstream.DefaultHTTPVersions
}
return []upstream.HTTPVersion{
upstream.HTTPVersion3,
upstream.HTTPVersion2,
upstream.HTTPVersion11,
}
}
</s> add // shutdownSrv shuts srv down and prints error messages to the log. </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 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()) | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/home/web.go |
keep keep add keep keep keep keep keep | <mask> var cancel context.CancelFunc
<mask> ctx, cancel = context.WithTimeout(ctx, shutdownTimeout)
<mask> shutdownSrv(ctx, web.httpsServer.server)
<mask> cancel()
<mask> }
<mask>
<mask> web.httpsServer.enabled = enabled
<mask> web.httpsServer.cert = cert
</s> 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 </s> remove web.httpsServer.shutdown = true
</s> add web.httpsServer.inShutdown = true </s> add shutdownSrv3(web.httpsServer.server3) </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://",
} </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), | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/home/web.go |
keep keep keep keep replace keep keep keep keep keep | <mask> // for https, we have a separate goroutine loop
<mask> go web.tlsServerLoop()
<mask>
<mask> // this loop is used as an ability to change listening host and/or port
<mask> for !web.httpsServer.shutdown {
<mask> printHTTPAddresses(aghhttp.SchemeHTTP)
<mask> errs := make(chan error, 2)
<mask>
<mask> // Use an h2c handler to support unencrypted HTTP/2, e.g. for proxies.
<mask> hdlr := h2c.NewHandler(withMiddlewares(Context.mux, limitRequestBody), &http2.Server{})
</s> 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 </s> add // 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.
//
// 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"` </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) { </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 | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/home/web.go |
keep keep keep keep replace keep keep keep keep keep | <mask> func (web *Web) Close(ctx context.Context) {
<mask> log.Info("stopping http server...")
<mask>
<mask> web.httpsServer.cond.L.Lock()
<mask> web.httpsServer.shutdown = true
<mask> web.httpsServer.cond.L.Unlock()
<mask>
<mask> var cancel context.CancelFunc
<mask> ctx, cancel = context.WithTimeout(ctx, shutdownTimeout)
<mask> defer cancel()
</s> 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 </s> add shutdownSrv3(web.httpsServer.server3)
</s> remove if web.httpsServer.shutdown {
</s> add if web.httpsServer.inShutdown { </s> add shutdownSrv3(web.httpsServer.server3) </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") </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) | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/home/web.go |
keep keep add keep keep keep keep keep keep | <mask> defer cancel()
<mask>
<mask> shutdownSrv(ctx, web.httpsServer.server)
<mask> shutdownSrv(ctx, web.httpServer)
<mask> shutdownSrv(ctx, web.httpServerBeta)
<mask>
<mask> log.Info("stopped http server")
<mask> }
<mask>
</s> 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 </s> add shutdownSrv3(web.httpsServer.server3)
</s> remove web.httpsServer.shutdown = true
</s> add web.httpsServer.inShutdown = true </s> add if web.conf.serveHTTP3 {
go web.mustStartHTTP3(addr)
}
log.Debug("web: starting https server") </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> add // shutdownSrv shuts srv down and prints error messages to the log. </s> remove if err != http.ErrServerClosed {
</s> add if !errors.Is(err, http.ErrServerClosed) { | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/home/web.go |
keep keep keep keep replace keep keep keep keep keep | <mask>
<mask> func (web *Web) tlsServerLoop() {
<mask> for {
<mask> web.httpsServer.cond.L.Lock()
<mask> if web.httpsServer.shutdown {
<mask> web.httpsServer.cond.L.Unlock()
<mask> break
<mask> }
<mask>
<mask> // this mechanism doesn't let us through until all conditions are met
</s> 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 </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") </s> add // UpstreamHTTPVersions returns the HTTP versions for upstream configuration
// depending on configuration.
func UpstreamHTTPVersions(http3 bool) (v []upstream.HTTPVersion) {
if !http3 {
return upstream.DefaultHTTPVersions
}
return []upstream.HTTPVersion{
upstream.HTTPVersion3,
upstream.HTTPVersion2,
upstream.HTTPVersion11,
}
}
| https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/home/web.go |
keep keep keep keep replace keep keep keep keep keep | <mask>
<mask> // this mechanism doesn't let us through until all conditions are met
<mask> for !web.httpsServer.enabled { // sleep until necessary data is supplied
<mask> web.httpsServer.cond.Wait()
<mask> if web.httpsServer.shutdown {
<mask> web.httpsServer.cond.L.Unlock()
<mask> return
<mask> }
<mask> }
<mask>
</s> 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 </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) { </s> add serveHTTP3 bool </s> add // UpstreamHTTPVersions returns the HTTP versions for upstream configuration
// depending on configuration.
func UpstreamHTTPVersions(http3 bool) (v []upstream.HTTPVersion) {
if !http3 {
return upstream.DefaultHTTPVersions
}
return []upstream.HTTPVersion{
upstream.HTTPVersion3,
upstream.HTTPVersion2,
upstream.HTTPVersion11,
}
}
</s> remove web.httpsServer.shutdown = true
</s> add web.httpsServer.inShutdown = true | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/home/web.go |
keep replace replace keep keep replace keep keep keep keep | <mask>
<mask> // prepare HTTPS server
<mask> address := netutil.JoinHostPort(web.conf.BindHost.String(), web.conf.PortHTTPS)
<mask> web.httpsServer.server = &http.Server{
<mask> ErrorLog: log.StdLog("web: https", log.DEBUG),
<mask> Addr: address,
<mask> TLSConfig: &tls.Config{
<mask> Certificates: []tls.Certificate{web.httpsServer.cert},
<mask> RootCAs: Context.tlsRoots,
<mask> CipherSuites: aghtls.SaferCipherSuites(),
</s> 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 </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> add serveHTTP3 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") </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 | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/home/web.go |
keep keep keep add keep keep keep keep keep keep | <mask> WriteTimeout: web.conf.WriteTimeout,
<mask> }
<mask>
<mask> printHTTPAddresses(aghhttp.SchemeHTTPS)
<mask> err := web.httpsServer.server.ListenAndServeTLS("", "")
<mask> if !errors.Is(err, http.ErrServerClosed) {
<mask> cleanupAlways()
<mask> log.Fatalf("web: https: %s", err)
<mask> }
<mask> }
</s> 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 </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) </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) | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/home/web.go |
keep keep replace keep replace | <mask> printHTTPAddresses(aghhttp.SchemeHTTPS)
<mask> err := web.httpsServer.server.ListenAndServeTLS("", "")
<mask> if err != http.ErrServerClosed {
<mask> cleanupAlways()
<mask> log.Fatal(err)
</s> 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 </s> add if web.conf.serveHTTP3 {
go web.mustStartHTTP3(addr)
}
log.Debug("web: starting https server") </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 configure: %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 check_config: %s", err) | https://github.com/AdguardTeam/AdGuardHome/commit/0cce420261b1e207e558f884d6c73cbec9d55f60 | internal/home/web.go |
keep add keep keep keep keep keep | <mask> // update Name index
<mask> if old.Name != c.Name {
<mask> clients.list[c.Name] = old
<mask> }
<mask>
<mask> // update upstreams cache
<mask> if old.Name != c.Name {
</s> 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 </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)
} </s> add assert.True(t, clients.list["client1"] == nil) | https://github.com/AdguardTeam/AdGuardHome/commit/0cd25cf598096505f9b77c4d0a64bd1bbf08d6fe | home/clients.go |
keep keep keep keep replace replace keep keep keep keep keep | <mask> clients.list[c.Name] = old
<mask> }
<mask>
<mask> // update upstreams cache
<mask> delete(clients.upstreamsCache, name)
<mask> delete(clients.upstreamsCache, old.Name)
<mask>
<mask> *old = c
<mask> return nil
<mask> }
<mask>
</s> 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 </s> add delete(clients.list, old.Name) </s> add assert.True(t, clients.list["client1"] == nil) | https://github.com/AdguardTeam/AdGuardHome/commit/0cd25cf598096505f9b77c4d0a64bd1bbf08d6fe | home/clients.go |
keep keep add keep keep keep keep keep keep | <mask> c = Client{}
<mask> c, b = clients.Find("1.1.1.2")
<mask> assert.True(t, b && c.Name == "client1-renamed" && c.IDs[0] == "1.1.1.2" && c.UseOwnSettings)
<mask>
<mask> // failed remove - no such name
<mask> if clients.Del("client3") {
<mask> t.Fatalf("Del - no such name")
<mask> }
<mask>
</s> 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 </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)
} </s> add delete(clients.list, old.Name) | https://github.com/AdguardTeam/AdGuardHome/commit/0cd25cf598096505f9b77c4d0a64bd1bbf08d6fe | home/clients_test.go |
keep keep keep keep replace keep keep keep keep keep | <mask> upstreamAddr := ""
<mask> if d.Upstream != nil {
<mask> upstreamAddr = d.Upstream.Address()
<mask> }
<mask> s.queryLog.Add(msg, d.Res, res, elapsed, d.Addr, upstreamAddr)
<mask> }
<mask>
<mask> s.updateStats(d, elapsed, *res)
<mask> s.RUnlock()
<mask>
</s> * QueryLog.Add() now receives net.IP, not net.Addr </s> remove IP: ip,
</s> add IP: ip.String(), </s> remove ip := getIPString(addr)
</s> add </s> add // 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
}
</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) | https://github.com/AdguardTeam/AdGuardHome/commit/0cd6781a9a94bbb0cf1d0bd310fc50d665da4674 | dnsforward/dnsforward.go |
keep add keep keep keep keep keep keep | <mask> }
<mask>
<mask> func (s *Server) updateStats(d *proxy.DNSContext, elapsed time.Duration, res dnsfilter.Result) {
<mask> if s.stats == nil {
<mask> return
<mask> }
<mask>
<mask> e := stats.Entry{}
</s> * QueryLog.Add() now receives net.IP, not net.Addr </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) | https://github.com/AdguardTeam/AdGuardHome/commit/0cd6781a9a94bbb0cf1d0bd310fc50d665da4674 | dnsforward/dnsforward.go |
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep | <mask> Elapsed time.Duration
<mask> Upstream string `json:",omitempty"` // if empty, means it was cached
<mask> }
<mask>
<mask> // getIPString is a helper function that extracts IP address from net.Addr
<mask> func getIPString(addr net.Addr) string {
<mask> switch addr := addr.(type) {
<mask> case *net.UDPAddr:
<mask> return addr.IP.String()
<mask> case *net.TCPAddr:
<mask> return addr.IP.String()
<mask> }
<mask> return ""
<mask> }
<mask>
<mask> func (l *queryLog) Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, addr net.Addr, upstream string) {
<mask> if !l.conf.Enabled {
<mask> return
<mask> }
<mask>
<mask> if question == nil || len(question.Question) != 1 || len(question.Question[0].Name) == 0 ||
</s> * QueryLog.Add() now receives net.IP, not net.Addr </s> add // 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
}
</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(), | https://github.com/AdguardTeam/AdGuardHome/commit/0cd6781a9a94bbb0cf1d0bd310fc50d665da4674 | querylog/qlog.go |
keep keep keep keep replace keep keep keep keep keep | <mask> }
<mask>
<mask> var a []byte
<mask> var err error
<mask> ip := getIPString(addr)
<mask>
<mask> if answer != nil {
<mask> a, err = answer.Pack()
<mask> if err != nil {
<mask> log.Printf("failed to pack answer for querylog: %s", err)
</s> * QueryLog.Add() now receives net.IP, not net.Addr </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> add // 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
}
</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) | https://github.com/AdguardTeam/AdGuardHome/commit/0cd6781a9a94bbb0cf1d0bd310fc50d665da4674 | querylog/qlog.go |
keep keep keep keep replace keep keep keep keep keep | <mask> }
<mask>
<mask> now := time.Now()
<mask> entry := logEntry{
<mask> IP: ip,
<mask> Time: now,
<mask>
<mask> Answer: a,
<mask> Result: *result,
<mask> Elapsed: elapsed,
</s> * QueryLog.Add() now receives net.IP, not net.Addr </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> add // 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
}
</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) { | https://github.com/AdguardTeam/AdGuardHome/commit/0cd6781a9a94bbb0cf1d0bd310fc50d665da4674 | querylog/qlog.go |
keep keep keep keep replace keep keep keep keep keep | <mask> // Close query log object
<mask> Close()
<mask>
<mask> // Add a log entry
<mask> Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, addr net.Addr, upstream string)
<mask>
<mask> // WriteDiskConfig - write configuration
<mask> WriteDiskConfig(dc *DiskConfig)
<mask> }
<mask>
</s> * QueryLog.Add() now receives net.IP, not net.Addr </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> add // 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
}
</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 | https://github.com/AdguardTeam/AdGuardHome/commit/0cd6781a9a94bbb0cf1d0bd310fc50d665da4674 | querylog/querylog.go |
keep keep keep add keep keep keep keep | <mask> // Package dnsfilter implements a DNS request and response filter.
<mask> package dnsfilter
<mask>
<mask> import (
<mask> "fmt"
<mask> "io/ioutil"
<mask> "net"
<mask> "net/http"
</s> 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 </s> add "context"
"crypto/sha256" </s> add "context" </s> add "sync" </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)
}
</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 // matched by white filter
</s> add // Matched by white filter. | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter.go |
keep keep add keep keep keep keep keep | <mask> blockFilters []Filter
<mask> }
<mask>
<mask> // DNSFilter matches hostnames and DNS requests against filtering rules.
<mask> type DNSFilter struct {
<mask> rulesStorage *filterlist.RuleStorage
<mask> filteringEngine *urlfilter.DNSEngine
<mask> rulesStorageAllow *filterlist.RuleStorage
</s> 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 </s> add counterLock sync.RWMutex </s> add "context" </s> add // 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 </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 </s> remove // override filtering settings
r, _ = d.CheckHost("example.org", dns.TypeA, &setts)
if r.IsFiltered {
t.Fatalf("CheckHost")
}
// override parental settings (force disable parental)
r, _ = d.CheckHost("pornhub.com", dns.TypeA, &setts)
if r.IsFiltered {
t.Fatalf("CheckHost")
}
// override safesearch settings (force enable safesearch)
r, _ = d.CheckHost("wmconvirus.narod.ru", dns.TypeA, &setts)
if !r.IsFiltered || r.Reason != FilteredSafeBrowsing {
t.Fatalf("CheckHost FilteredSafeBrowsing")
</s> add for _, tc := range testCases {
t.Run(tc.name, makeTester(tc, !tc.before)) | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter.go |
keep keep keep add keep keep keep keep keep | <mask>
<mask> // Channel for passing data to filters-initializer goroutine
<mask> filtersInitializerChan chan filtersInitializerParams
<mask> filtersInitializerLock sync.Mutex
<mask> }
<mask>
<mask> // Filter represents a filter list
<mask> type Filter struct {
<mask> ID int64 // auto-assigned when filter is added (see nextFilterID)
</s> 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 </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)
}
</s> add counterLock sync.RWMutex </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. </s> remove defer d.Close()
</s> add t.Cleanup(d.Close) | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter.go |
keep keep keep keep replace keep keep keep keep keep | <mask> gctx.parentalCache = cache.New(cacheConf)
<mask> }
<mask> }
<mask>
<mask> d := new(DNSFilter)
<mask>
<mask> err := d.initSecurityServices()
<mask> if err != nil {
<mask> log.Error("dnsfilter: initialize services: %s", err)
<mask> return nil
</s> 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 </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) </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) | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter.go |
keep keep keep add keep keep keep keep keep | <mask> package dnsfilter
<mask>
<mask> import (
<mask> "bytes"
<mask> "fmt"
<mask> "net"
<mask> "testing"
<mask>
<mask> "github.com/AdguardTeam/AdGuardHome/internal/testutil"
</s> 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 </s> add "context" </s> add "context" </s> add "sync" </s> add "github.com/AdguardTeam/golibs/cache" </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. </s> remove for _, test := range tests {
t.Run(fmt.Sprintf("%s-%s", test.testname, test.hostname), func(t *testing.T) {
filters := []Filter{{
ID: 0, Data: []byte(test.rules),
}}
d := NewForTest(nil, filters)
defer d.Close()
res, err := d.CheckHost(test.hostname, test.dnsType, &setts)
if err != nil {
t.Errorf("Error while matching host %s: %s", test.hostname, err)
}
if res.IsFiltered != test.isFiltered {
t.Errorf("Hostname %s has wrong result (%v must be %v)", test.hostname, res.IsFiltered, test.isFiltered)
}
if res.Reason != test.reason {
t.Errorf("Hostname %s has wrong reason (%v must be %v)", test.hostname, res.Reason.String(), test.reason.String())
}
</s> add 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
)
testCases := []struct {
name string
rules string
host string
wantIsFiltered bool
wantReason Reason
wantDNSType uint16
}{{
name: "sanity",
rules: "||doubleclick.net^",
host: "www.doubleclick.net",
wantIsFiltered: true,
wantReason: FilteredBlockList,
wantDNSType: dns.TypeA,
}, {
name: "sanity",
rules: "||doubleclick.net^",
host: "nodoubleclick.net",
wantIsFiltered: false,
wantReason: NotFilteredNotFound,
wantDNSType: dns.TypeA,
}, {
name: "sanity",
rules: "||doubleclick.net^",
host: "doubleclick.net.ru",
wantIsFiltered: false,
wantReason: NotFilteredNotFound,
wantDNSType: dns.TypeA,
}, {
name: "sanity",
rules: "||doubleclick.net^",
host: "wmconvirus.narod.ru",
wantIsFiltered: false,
wantReason: NotFilteredNotFound,
wantDNSType: dns.TypeA,
}, {
name: "blocking",
rules: blockingRules,
host: "example.org",
wantIsFiltered: true,
wantReason: FilteredBlockList,
wantDNSType: dns.TypeA,
}, {
name: "blocking",
rules: blockingRules,
host: "test.example.org",
wantIsFiltered: true,
wantReason: FilteredBlockList,
wantDNSType: dns.TypeA,
}, {
name: "blocking",
rules: blockingRules,
host: "test.test.example.org",
wantIsFiltered: true,
wantReason: FilteredBlockList,
wantDNSType: dns.TypeA,
}, {
name: "blocking",
rules: blockingRules,
host: "testexample.org",
wantIsFiltered: false,
wantReason: NotFilteredNotFound,
wantDNSType: dns.TypeA,
}, {
name: "blocking",
rules: blockingRules,
host: "onemoreexample.org",
wantIsFiltered: false,
wantReason: NotFilteredNotFound,
wantDNSType: dns.TypeA,
}, {
name: "allowlist",
rules: allowlistRules,
host: "example.org",
wantIsFiltered: true,
wantReason: FilteredBlockList,
wantDNSType: dns.TypeA,
}, {
name: "allowlist",
rules: allowlistRules,
host: "test.example.org",
wantIsFiltered: false,
wantReason: NotFilteredAllowList,
wantDNSType: dns.TypeA,
}, {
name: "allowlist",
rules: allowlistRules,
host: "test.test.example.org",
wantIsFiltered: false,
wantReason: NotFilteredAllowList,
wantDNSType: dns.TypeA,
}, {
name: "allowlist",
rules: allowlistRules,
host: "testexample.org",
wantIsFiltered: false,
wantReason: NotFilteredNotFound,
wantDNSType: dns.TypeA,
}, {
name: "allowlist",
rules: allowlistRules,
host: "onemoreexample.org",
wantIsFiltered: false,
wantReason: NotFilteredNotFound,
wantDNSType: dns.TypeA,
}, {
name: "important",
rules: importantRules,
host: "example.org",
wantIsFiltered: false,
wantReason: NotFilteredAllowList,
wantDNSType: dns.TypeA,
}, {
name: "important",
rules: importantRules,
host: "test.example.org",
wantIsFiltered: true,
wantReason: FilteredBlockList,
wantDNSType: dns.TypeA,
}, {
name: "important",
rules: importantRules,
host: "test.test.example.org",
wantIsFiltered: true,
wantReason: FilteredBlockList,
wantDNSType: dns.TypeA,
}, {
name: "important",
rules: importantRules,
host: "testexample.org",
wantIsFiltered: false,
wantReason: NotFilteredNotFound,
wantDNSType: dns.TypeA,
}, {
name: "important",
rules: importantRules,
host: "onemoreexample.org",
wantIsFiltered: false,
wantReason: NotFilteredNotFound,
wantDNSType: dns.TypeA,
}, {
name: "regex",
rules: regexRules,
host: "example.org",
wantIsFiltered: true,
wantReason: FilteredBlockList,
wantDNSType: dns.TypeA,
}, {
name: "regex",
rules: regexRules,
host: "test.example.org",
wantIsFiltered: false,
wantReason: NotFilteredAllowList,
wantDNSType: dns.TypeA,
}, {
name: "regex",
rules: regexRules,
host: "test.test.example.org",
wantIsFiltered: false,
wantReason: NotFilteredAllowList,
wantDNSType: dns.TypeA,
}, {
name: "regex",
rules: regexRules,
host: "testexample.org",
wantIsFiltered: true,
wantReason: FilteredBlockList,
wantDNSType: dns.TypeA,
}, {
name: "regex",
rules: regexRules,
host: "onemoreexample.org",
wantIsFiltered: true,
wantReason: FilteredBlockList,
wantDNSType: dns.TypeA,
}, {
name: "mask",
rules: maskRules,
host: "test.example.org",
wantIsFiltered: true,
wantReason: FilteredBlockList,
wantDNSType: dns.TypeA,
}, {
name: "mask",
rules: maskRules,
host: "test2.example.org",
wantIsFiltered: true,
wantReason: FilteredBlockList,
wantDNSType: dns.TypeA,
}, {
name: "mask",
rules: maskRules,
host: "example.com",
wantIsFiltered: true,
wantReason: FilteredBlockList,
wantDNSType: dns.TypeA,
}, {
name: "mask",
rules: maskRules,
host: "exampleeee.com",
wantIsFiltered: true,
wantReason: FilteredBlockList,
wantDNSType: dns.TypeA,
}, {
name: "mask",
rules: maskRules,
host: "onemoreexamsite.com",
wantIsFiltered: true,
wantReason: FilteredBlockList,
wantDNSType: dns.TypeA,
}, {
name: "mask",
rules: maskRules,
host: "example.org",
wantIsFiltered: false,
wantReason: NotFilteredNotFound,
wantDNSType: dns.TypeA,
}, {
name: "mask",
rules: maskRules,
host: "testexample.org",
wantIsFiltered: false,
wantReason: NotFilteredNotFound,
wantDNSType: dns.TypeA,
}, {
name: "mask",
rules: maskRules,
host: "example.co.uk",
wantIsFiltered: false,
wantReason: NotFilteredNotFound,
wantDNSType: dns.TypeA,
}, {
name: "dnstype",
rules: dnstypeRules,
host: "onemoreexample.org",
wantIsFiltered: false,
wantReason: NotFilteredNotFound,
wantDNSType: dns.TypeA,
}, {
name: "dnstype",
rules: dnstypeRules,
host: "example.org",
wantIsFiltered: false,
wantReason: NotFilteredNotFound,
wantDNSType: dns.TypeA,
}, {
name: "dnstype",
rules: dnstypeRules,
host: "example.org",
wantIsFiltered: true,
wantReason: FilteredBlockList,
wantDNSType: dns.TypeAAAA,
}, {
name: "dnstype",
rules: dnstypeRules,
host: "test.example.org",
wantIsFiltered: false,
wantReason: NotFilteredAllowList,
wantDNSType: dns.TypeA,
}, {
name: "dnstype",
rules: dnstypeRules,
host: "test.example.org",
wantIsFiltered: false,
wantReason: NotFilteredAllowList,
wantDNSType: dns.TypeAAAA,
}}
for _, tc := range testCases {
t.Run(fmt.Sprintf("%s-%s", tc.name, tc.host), func(t *testing.T) {
filters := []Filter{{ID: 0, Data: []byte(tc.rules)}}
d := newForTest(nil, filters)
t.Cleanup(d.Close)
res, err := d.CheckHost(tc.host, tc.wantDNSType, &setts)
assert.Nilf(t, err, "Error while matching host %s: %s", tc.host, err)
assert.Equalf(t, tc.wantIsFiltered, res.IsFiltered, "Hostname %s has wrong result (%v must be %v)", tc.host, res.IsFiltered, tc.wantIsFiltered)
assert.Equalf(t, tc.wantReason, res.Reason, "Hostname %s has wrong reason (%v must be %v)", tc.host, res.Reason, tc.wantReason) | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep add keep keep keep keep | <mask> "testing"
<mask>
<mask> "github.com/AdguardTeam/AdGuardHome/internal/testutil"
<mask> "github.com/AdguardTeam/golibs/log"
<mask> "github.com/AdguardTeam/urlfilter/rules"
<mask> "github.com/miekg/dns"
<mask> "github.com/stretchr/testify/assert"
</s> 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 </s> add "sync" </s> add "context"
"crypto/sha256" </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) </s> remove // test cached result
</s> add // Cached result. | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep keep keep replace replace replace replace replace replace replace replace keep keep keep keep keep | <mask> }
<mask>
<mask> var setts RequestFilteringSettings
<mask>
<mask> // HELPERS
<mask> // SAFE BROWSING
<mask> // SAFE SEARCH
<mask> // PARENTAL
<mask> // FILTERING
<mask> // BENCHMARKS
<mask>
<mask> // HELPERS
<mask>
<mask> func purgeCaches() {
<mask> if gctx.safebrowsingCache != nil {
<mask> gctx.safebrowsingCache.Clear()
<mask> }
</s> 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 </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) </s> remove // PARENTAL
</s> add // Parental. | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep keep replace replace replace replace replace replace replace replace keep keep keep replace | <mask> // HELPERS
<mask>
<mask> func purgeCaches() {
<mask> if gctx.safebrowsingCache != nil {
<mask> gctx.safebrowsingCache.Clear()
<mask> }
<mask> if gctx.parentalCache != nil {
<mask> gctx.parentalCache.Clear()
<mask> }
<mask> if gctx.safeSearchCache != nil {
<mask> gctx.safeSearchCache.Clear()
<mask> }
<mask> }
<mask>
<mask> func NewForTest(c *Config, filters []Filter) *DNSFilter {
</s> 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 </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 // For yandex we already know valid ip.
</s> add // For yandex we already know valid IP. </s> remove ips, err := net.LookupIP(safeDomain)
</s> add ipAddrs, err := resolver.LookupIPAddr(context.Background(), safeDomain) | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep keep keep replace replace replace replace replace replace keep keep keep keep keep | <mask>
<mask> func (d *DNSFilter) checkMatch(t *testing.T, hostname string) {
<mask> t.Helper()
<mask> res, err := d.CheckHost(hostname, dns.TypeA, &setts)
<mask> if err != nil {
<mask> t.Errorf("Error while matching host %s: %s", hostname, err)
<mask> }
<mask> if !res.IsFiltered {
<mask> t.Errorf("Expected hostname %s to match", hostname)
<mask> }
<mask> }
<mask>
<mask> func (d *DNSFilter) checkMatchIP(t *testing.T, hostname, ip string, qtype uint16) {
<mask> t.Helper()
<mask>
</s> 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 </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,
} </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 | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
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 | <mask> func (d *DNSFilter) checkMatchIP(t *testing.T, hostname, ip string, qtype uint16) {
<mask> t.Helper()
<mask>
<mask> res, err := d.CheckHost(hostname, qtype, &setts)
<mask> if err != nil {
<mask> t.Errorf("Error while matching host %s: %s", hostname, err)
<mask> }
<mask>
<mask> if !res.IsFiltered {
<mask> t.Errorf("Expected hostname %s to match", hostname)
<mask> }
<mask>
<mask> if len(res.Rules) == 0 {
<mask> t.Errorf("Expected result to have rules")
<mask>
<mask> return
<mask> }
<mask>
<mask> r := res.Rules[0]
<mask> if r.IP == nil || r.IP.String() != ip {
<mask> t.Errorf("Expected ip %s to match, actual: %v", ip, r.IP)
<mask> }
<mask> }
<mask>
<mask> func (d *DNSFilter) checkMatchEmpty(t *testing.T, hostname string) {
<mask> t.Helper()
</s> 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 </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 </s> remove ips, err := net.LookupIP(safeDomain)
</s> add ipAddrs, err := resolver.LookupIPAddr(context.Background(), safeDomain) | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep keep keep replace replace replace replace replace replace keep keep keep keep keep | <mask>
<mask> func (d *DNSFilter) checkMatchEmpty(t *testing.T, hostname string) {
<mask> t.Helper()
<mask> res, err := d.CheckHost(hostname, dns.TypeA, &setts)
<mask> if err != nil {
<mask> t.Errorf("Error while matching host %s: %s", hostname, err)
<mask> }
<mask> if res.IsFiltered {
<mask> t.Errorf("Expected hostname %s to not match", hostname)
<mask> }
<mask> }
<mask>
<mask> func TestEtcHostsMatching(t *testing.T) {
<mask> addr := "216.239.38.120"
<mask> addr6 := "::1"
</s> 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 </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,
} </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,
} | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep keep keep replace replace keep keep keep keep keep | <mask> addr, addr6)
<mask> filters := []Filter{{
<mask> ID: 0, Data: []byte(text),
<mask> }}
<mask> d := NewForTest(nil, filters)
<mask> defer d.Close()
<mask>
<mask> d.checkMatchIP(t, "google.com", addr, dns.TypeA)
<mask> d.checkMatchIP(t, "www.google.com", addr, dns.TypeA)
<mask> d.checkMatchEmpty(t, "subdomain.google.com")
<mask> d.checkMatchEmpty(t, "example.org")
</s> 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 </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 </s> remove // ...but empty IPv6
</s> add // Empty IPv6. | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep keep keep replace keep keep keep keep keep | <mask> d.checkMatchIP(t, "www.google.com", addr, dns.TypeA)
<mask> d.checkMatchEmpty(t, "subdomain.google.com")
<mask> d.checkMatchEmpty(t, "example.org")
<mask>
<mask> // IPv4
<mask> d.checkMatchIP(t, "block.com", "0.0.0.0", dns.TypeA)
<mask>
<mask> // ...but empty IPv6
<mask> res, err := d.CheckHost("block.com", dns.TypeAAAA, &setts)
<mask> assert.Nil(t, err)
</s> 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 </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}) </s> remove // ...and 1 IPv6 address
</s> add // One IPv6 address. | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep keep keep replace keep keep keep keep keep | <mask>
<mask> // IPv4
<mask> d.checkMatchIP(t, "block.com", "0.0.0.0", dns.TypeA)
<mask>
<mask> // ...but empty IPv6
<mask> res, err := d.CheckHost("block.com", dns.TypeAAAA, &setts)
<mask> assert.Nil(t, err)
<mask> assert.True(t, res.IsFiltered)
<mask> if assert.Len(t, res.Rules, 1) {
<mask> assert.Equal(t, "0.0.0.0 block.com", res.Rules[0].Text)
</s> 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 </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. </s> remove // ...and 1 IPv6 address
</s> add // One IPv6 address. | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep keep keep replace keep keep keep keep keep | <mask> assert.Equal(t, "0.0.0.0 block.com", res.Rules[0].Text)
<mask> assert.Empty(t, res.Rules[0].IP)
<mask> }
<mask>
<mask> // IPv6
<mask> d.checkMatchIP(t, "ipv6.com", addr6, dns.TypeAAAA)
<mask>
<mask> // ...but empty IPv4
<mask> res, err = d.CheckHost("ipv6.com", dns.TypeA, &setts)
<mask> assert.Nil(t, err)
</s> 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 </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}) </s> remove // not matched by white filter, but matched by block filter
</s> add // Not matched by white filter, but matched by block filter. | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep keep keep replace keep keep keep keep keep | <mask>
<mask> // IPv6
<mask> d.checkMatchIP(t, "ipv6.com", addr6, dns.TypeAAAA)
<mask>
<mask> // ...but empty IPv4
<mask> res, err = d.CheckHost("ipv6.com", dns.TypeA, &setts)
<mask> assert.Nil(t, err)
<mask> assert.True(t, res.IsFiltered)
<mask> if assert.Len(t, res.Rules, 1) {
<mask> assert.Equal(t, "::1 ipv6.com", res.Rules[0].Text)
</s> 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 </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. </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}) | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep keep replace keep keep keep keep replace replace | <mask> assert.Empty(t, res.Rules[0].IP)
<mask> }
<mask>
<mask> // 2 IPv4 (return only the first one)
<mask> res, err = d.CheckHost("host2", dns.TypeA, &setts)
<mask> assert.Nil(t, err)
<mask> assert.True(t, res.IsFiltered)
<mask> if assert.Len(t, res.Rules, 1) {
<mask> loopback4 := net.IP{0, 0, 0, 1}
<mask> assert.Equal(t, res.Rules[0].IP, loopback4)
</s> 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 </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 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 // 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 IPv4
</s> add // Empty IPv4. | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep keep replace keep keep keep keep replace replace keep | <mask> assert.Equal(t, res.Rules[0].IP, loopback4)
<mask> }
<mask>
<mask> // ...and 1 IPv6 address
<mask> res, err = d.CheckHost("host2", dns.TypeAAAA, &setts)
<mask> assert.Nil(t, err)
<mask> assert.True(t, res.IsFiltered)
<mask> if assert.Len(t, res.Rules, 1) {
<mask> loopback6 := net.IP{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
<mask> assert.Equal(t, res.Rules[0].IP, loopback6)
<mask> }
</s> 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 </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) </s> remove d := DNSFilter{}
</s> add d := newForTest(nil, nil)
t.Cleanup(d.Close) | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep keep keep replace keep keep keep keep keep | <mask> assert.Equal(t, res.Rules[0].IP, loopback6)
<mask> }
<mask> }
<mask>
<mask> // SAFE BROWSING
<mask>
<mask> func TestSafeBrowsing(t *testing.T) {
<mask> logOutput := &bytes.Buffer{}
<mask> testutil.ReplaceLogWriter(t, logOutput)
<mask> testutil.ReplaceLogLevel(t, log.DEBUG)
</s> 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 </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. </s> remove // SAFE SEARCH
</s> add // Safe Search. | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep replace replace replace keep replace keep keep keep keep | <mask> testutil.ReplaceLogLevel(t, log.DEBUG)
<mask>
<mask> d := NewForTest(&Config{SafeBrowsingEnabled: true}, nil)
<mask> defer d.Close()
<mask> d.checkMatch(t, "wmconvirus.narod.ru")
<mask>
<mask> assert.Contains(t, logOutput.String(), "SafeBrowsing lookup for wmconvirus.narod.ru")
<mask>
<mask> d.checkMatch(t, "test.wmconvirus.narod.ru")
<mask> d.checkMatchEmpty(t, "yandex.ru")
<mask> d.checkMatchEmpty(t, "pornhub.com")
</s> 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 </s> remove d.checkMatch(t, "test.wmconvirus.narod.ru")
</s> add 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) </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) </s> remove d.checkMatch(t, "wmconvirus.narod.ru")
</s> add d.checkMatch(t, matching) | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep replace keep keep keep replace keep keep keep keep | <mask>
<mask> d.checkMatch(t, "test.wmconvirus.narod.ru")
<mask> d.checkMatchEmpty(t, "yandex.ru")
<mask> d.checkMatchEmpty(t, "pornhub.com")
<mask>
<mask> // test cached result
<mask> d.safeBrowsingServer = "127.0.0.1"
<mask> d.checkMatch(t, "wmconvirus.narod.ru")
<mask> d.checkMatchEmpty(t, "pornhub.com")
<mask> d.safeBrowsingServer = defaultSafebrowsingServer
</s> 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 </s> remove d.checkMatch(t, "wmconvirus.narod.ru")
</s> add d.checkMatch(t, matching) </s> remove d.checkMatch(t, "pornhub.com")
</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) </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) | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep keep keep replace keep keep keep keep keep | <mask> d.checkMatchEmpty(t, "pornhub.com")
<mask>
<mask> // test cached result
<mask> d.safeBrowsingServer = "127.0.0.1"
<mask> d.checkMatch(t, "wmconvirus.narod.ru")
<mask> d.checkMatchEmpty(t, "pornhub.com")
<mask> d.safeBrowsingServer = defaultSafebrowsingServer
<mask> }
<mask>
<mask> func TestParallelSB(t *testing.T) {
</s> 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 </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,
}
</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) | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep keep keep replace replace keep keep keep keep replace replace keep keep keep | <mask> d.safeBrowsingServer = defaultSafebrowsingServer
<mask> }
<mask>
<mask> func TestParallelSB(t *testing.T) {
<mask> d := NewForTest(&Config{SafeBrowsingEnabled: true}, nil)
<mask> defer d.Close()
<mask> t.Run("group", func(t *testing.T) {
<mask> for i := 0; i < 100; i++ {
<mask> t.Run(fmt.Sprintf("aaa%d", i), func(t *testing.T) {
<mask> t.Parallel()
<mask> d.checkMatch(t, "wmconvirus.narod.ru")
<mask> d.checkMatch(t, "test.wmconvirus.narod.ru")
<mask> d.checkMatchEmpty(t, "yandex.ru")
<mask> d.checkMatchEmpty(t, "pornhub.com")
<mask> })
</s> 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 </s> remove d.checkMatch(t, "wmconvirus.narod.ru")
</s> add d.checkMatch(t, matching) </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, "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) | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep keep keep replace keep keep keep keep keep | <mask> }
<mask> })
<mask> }
<mask>
<mask> // SAFE SEARCH
<mask>
<mask> func TestSafeSearch(t *testing.T) {
<mask> d := NewForTest(&Config{SafeSearchEnabled: true}, nil)
<mask> defer d.Close()
<mask> val, ok := d.SafeSearchDomain("www.google.com")
</s> 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 </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") </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") | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep keep keep replace replace keep replace replace replace replace replace replace keep keep | <mask>
<mask> // SAFE SEARCH
<mask>
<mask> func TestSafeSearch(t *testing.T) {
<mask> d := NewForTest(&Config{SafeSearchEnabled: true}, nil)
<mask> defer d.Close()
<mask> val, ok := d.SafeSearchDomain("www.google.com")
<mask> if !ok {
<mask> t.Errorf("Expected safesearch to find result for www.google.com")
<mask> }
<mask> if val != "forcesafesearch.google.com" {
<mask> t.Errorf("Expected safesearch for google.com to be forcesafesearch.google.com")
<mask> }
<mask> }
<mask>
</s> 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 </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) </s> remove // SAFE SEARCH
</s> add // Safe Search. | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep replace replace replace replace replace replace replace replace keep keep keep keep replace keep | <mask> func TestCheckHostSafeSearchYandex(t *testing.T) {
<mask> d := NewForTest(&Config{SafeSearchEnabled: true}, nil)
<mask> defer d.Close()
<mask>
<mask> // Slice of yandex domains
<mask> yandex := []string{"yAndeX.ru", "YANdex.COM", "yandex.ua", "yandex.by", "yandex.kz", "www.yandex.com"}
<mask>
<mask> // Check host for each domain
<mask> for _, host := range yandex {
<mask> res, err := d.CheckHost(host, dns.TypeA, &setts)
<mask> assert.Nil(t, err)
<mask> assert.True(t, res.IsFiltered)
<mask> if assert.Len(t, res.Rules, 1) {
<mask> assert.Equal(t, res.Rules[0].IP.String(), "213.180.193.56")
<mask> }
</s> 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 </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 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) | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep keep keep replace replace replace replace replace replace keep keep keep keep keep | <mask> }
<mask> }
<mask> }
<mask>
<mask> func TestCheckHostSafeSearchGoogle(t *testing.T) {
<mask> d := NewForTest(&Config{SafeSearchEnabled: true}, nil)
<mask> defer d.Close()
<mask>
<mask> // Slice of google domains
<mask> googleDomains := []string{"www.google.com", "www.google.im", "www.google.co.in", "www.google.iq", "www.google.is", "www.google.it", "www.google.je"}
<mask>
<mask> // Check host for each domain
<mask> for _, host := range googleDomains {
<mask> res, err := d.CheckHost(host, dns.TypeA, &setts)
<mask> assert.Nil(t, err)
</s> 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 </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) </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) | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep keep replace replace replace replace replace replace replace replace keep keep keep keep replace replace keep | <mask> // Slice of google domains
<mask> googleDomains := []string{"www.google.com", "www.google.im", "www.google.co.in", "www.google.iq", "www.google.is", "www.google.it", "www.google.je"}
<mask>
<mask> // Check host for each domain
<mask> for _, host := range googleDomains {
<mask> res, err := d.CheckHost(host, dns.TypeA, &setts)
<mask> assert.Nil(t, err)
<mask> assert.True(t, res.IsFiltered)
<mask> if assert.Len(t, res.Rules, 1) {
<mask> assert.NotEqual(t, res.Rules[0].IP.String(), "0.0.0.0")
<mask> }
<mask> }
<mask> }
<mask>
<mask> func TestSafeSearchCacheYandex(t *testing.T) {
<mask> d := NewForTest(nil, nil)
<mask> defer d.Close()
<mask> domain := "yandex.ru"
</s> 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 </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 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(nil, nil)
defer d.Close()
</s> add d := newForTest(nil, nil)
t.Cleanup(d.Close)
resolver := &testResolver{}
d.resolver = resolver
</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)) | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep keep keep replace replace keep keep replace replace replace keep keep | <mask> assert.Nil(t, err)
<mask> assert.False(t, res.IsFiltered)
<mask> assert.Empty(t, res.Rules)
<mask>
<mask> d = NewForTest(&Config{SafeSearchEnabled: true}, nil)
<mask> defer d.Close()
<mask>
<mask> res, err = d.CheckHost(domain, dns.TypeA, &setts)
<mask> if err != nil {
<mask> t.Fatalf("CheckHost for safesearh domain %s failed cause %s", domain, err)
<mask> }
<mask>
<mask> // For yandex we already know valid ip.
</s> 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 </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)
d.resolver = resolver </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",
} { | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep keep keep replace keep keep keep keep keep | <mask> if err != nil {
<mask> t.Fatalf("CheckHost for safesearh domain %s failed cause %s", domain, err)
<mask> }
<mask>
<mask> // For yandex we already know valid ip.
<mask> if assert.Len(t, res.Rules, 1) {
<mask> assert.Equal(t, res.Rules[0].IP.String(), "213.180.193.56")
<mask> }
<mask>
<mask> // Check cache.
</s> 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 </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)) </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)) | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep keep keep replace keep keep keep keep keep | <mask> }
<mask>
<mask> // For yandex we already know valid ip.
<mask> if assert.Len(t, res.Rules, 1) {
<mask> assert.Equal(t, res.Rules[0].IP.String(), "213.180.193.56")
<mask> }
<mask>
<mask> // Check cache.
<mask> cachedValue, isFound := getCachedResult(gctx.safeSearchCache, domain)
<mask> assert.True(t, isFound)
</s> 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 </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)) </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)
}) | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep replace keep keep keep keep replace replace keep keep | <mask> if assert.Len(t, cachedValue.Rules, 1) {
<mask> assert.Equal(t, cachedValue.Rules[0].IP.String(), "213.180.193.56")
<mask> }
<mask> }
<mask>
<mask> func TestSafeSearchCacheGoogle(t *testing.T) {
<mask> d := NewForTest(nil, nil)
<mask> defer d.Close()
<mask> domain := "www.google.ru"
<mask> res, err := d.CheckHost(domain, dns.TypeA, &setts)
</s> 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 </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 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 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 // 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)
}) | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep keep keep replace replace keep keep keep keep keep | <mask> assert.Nil(t, err)
<mask> assert.False(t, res.IsFiltered)
<mask> assert.Empty(t, res.Rules)
<mask>
<mask> d = NewForTest(&Config{SafeSearchEnabled: true}, nil)
<mask> defer d.Close()
<mask>
<mask> // Let's lookup for safesearch domain
<mask> safeDomain, ok := d.SafeSearchDomain(domain)
<mask> if !ok {
<mask> t.Fatalf("Failed to get safesearch domain for %s", domain)
</s> 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 </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
</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") | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep replace keep replace replace replace | <mask>
<mask> // Let's lookup for safesearch domain
<mask> safeDomain, ok := d.SafeSearchDomain(domain)
<mask> if !ok {
<mask> t.Fatalf("Failed to get safesearch domain for %s", domain)
<mask> }
</s> 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 </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 {
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 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") | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep keep replace keep keep keep keep replace replace replace replace keep keep keep | <mask> t.Fatalf("Failed to get safesearch domain for %s", domain)
<mask> }
<mask>
<mask> ips, err := net.LookupIP(safeDomain)
<mask> if err != nil {
<mask> t.Fatalf("Failed to lookup for %s", safeDomain)
<mask> }
<mask>
<mask> ip := ips[0]
<mask> for _, i := range ips {
<mask> if i.To4() != nil {
<mask> ip = i
<mask> break
<mask> }
<mask> }
</s> 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 </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 // Let's lookup for safesearch domain
</s> add // Lookup for safesearch domain. </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 = 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) | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep keep keep replace keep keep keep keep keep | <mask> assert.True(t, cachedValue.Rules[0].IP.Equal(ip))
<mask> }
<mask> }
<mask>
<mask> // PARENTAL
<mask>
<mask> func TestParentalControl(t *testing.T) {
<mask> logOutput := &bytes.Buffer{}
<mask> testutil.ReplaceLogWriter(t, logOutput)
<mask> testutil.ReplaceLogLevel(t, log.DEBUG)
</s> 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 </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)
}) </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)) | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep keep keep replace replace replace replace replace keep keep keep keep keep | <mask> logOutput := &bytes.Buffer{}
<mask> testutil.ReplaceLogWriter(t, logOutput)
<mask> testutil.ReplaceLogLevel(t, log.DEBUG)
<mask>
<mask> d := NewForTest(&Config{ParentalEnabled: true}, nil)
<mask> defer d.Close()
<mask> d.checkMatch(t, "pornhub.com")
<mask> assert.Contains(t, logOutput.String(), "Parental lookup for pornhub.com")
<mask> d.checkMatch(t, "www.pornhub.com")
<mask> d.checkMatchEmpty(t, "www.yandex.ru")
<mask> d.checkMatchEmpty(t, "yandex.ru")
<mask> d.checkMatchEmpty(t, "api.jquery.com")
<mask>
<mask> // test cached result
</s> 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 </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. </s> remove d.checkMatch(t, "wmconvirus.narod.ru")
</s> add d.checkMatch(t, matching) | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep replace keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep | <mask> d.parentalServer = "127.0.0.1"
<mask> d.checkMatch(t, "pornhub.com")
<mask> d.checkMatchEmpty(t, "yandex.ru")
<mask> d.parentalServer = defaultParentalServer
<mask> }
<mask>
<mask> // FILTERING
<mask>
<mask> const nl = "\n"
<mask>
<mask> const (
<mask> blockingRules = `||example.org^` + nl
<mask> allowlistRules = `||example.org^` + nl + `@@||test.example.org` + nl
<mask> importantRules = `@@||example.org^` + nl + `||test.example.org^$important` + nl
<mask> regexRules = `/example\.org/` + nl + `@@||test.example.org^` + nl
<mask> maskRules = `test*.example.org^` + nl + `exam*.com` + nl
<mask> dnstypeRules = `||example.org^$dnstype=AAAA` + nl + `@@||test.example.org^` + nl
<mask> )
<mask>
<mask> var tests = []struct {
<mask> testname string
<mask> rules string
<mask> hostname string
<mask> isFiltered bool
<mask> reason Reason
<mask> dnsType uint16
<mask> }{
<mask> {"sanity", "||doubleclick.net^", "www.doubleclick.net", true, FilteredBlockList, dns.TypeA},
<mask> {"sanity", "||doubleclick.net^", "nodoubleclick.net", false, NotFilteredNotFound, dns.TypeA},
<mask> {"sanity", "||doubleclick.net^", "doubleclick.net.ru", false, NotFilteredNotFound, dns.TypeA},
<mask> {"sanity", "||doubleclick.net^", "wmconvirus.narod.ru", false, NotFilteredNotFound, dns.TypeA},
<mask>
<mask> {"blocking", blockingRules, "example.org", true, FilteredBlockList, dns.TypeA},
<mask> {"blocking", blockingRules, "test.example.org", true, FilteredBlockList, dns.TypeA},
<mask> {"blocking", blockingRules, "test.test.example.org", true, FilteredBlockList, dns.TypeA},
<mask> {"blocking", blockingRules, "testexample.org", false, NotFilteredNotFound, dns.TypeA},
<mask> {"blocking", blockingRules, "onemoreexample.org", false, NotFilteredNotFound, dns.TypeA},
<mask>
<mask> {"allowlist", allowlistRules, "example.org", true, FilteredBlockList, dns.TypeA},
<mask> {"allowlist", allowlistRules, "test.example.org", false, NotFilteredAllowList, dns.TypeA},
<mask> {"allowlist", allowlistRules, "test.test.example.org", false, NotFilteredAllowList, dns.TypeA},
<mask> {"allowlist", allowlistRules, "testexample.org", false, NotFilteredNotFound, dns.TypeA},
<mask> {"allowlist", allowlistRules, "onemoreexample.org", false, NotFilteredNotFound, dns.TypeA},
<mask>
<mask> {"important", importantRules, "example.org", false, NotFilteredAllowList, dns.TypeA},
<mask> {"important", importantRules, "test.example.org", true, FilteredBlockList, dns.TypeA},
<mask> {"important", importantRules, "test.test.example.org", true, FilteredBlockList, dns.TypeA},
<mask> {"important", importantRules, "testexample.org", false, NotFilteredNotFound, dns.TypeA},
<mask> {"important", importantRules, "onemoreexample.org", false, NotFilteredNotFound, dns.TypeA},
<mask>
<mask> {"regex", regexRules, "example.org", true, FilteredBlockList, dns.TypeA},
<mask> {"regex", regexRules, "test.example.org", false, NotFilteredAllowList, dns.TypeA},
<mask> {"regex", regexRules, "test.test.example.org", false, NotFilteredAllowList, dns.TypeA},
<mask> {"regex", regexRules, "testexample.org", true, FilteredBlockList, dns.TypeA},
<mask> {"regex", regexRules, "onemoreexample.org", true, FilteredBlockList, dns.TypeA},
<mask>
<mask> {"mask", maskRules, "test.example.org", true, FilteredBlockList, dns.TypeA},
<mask> {"mask", maskRules, "test2.example.org", true, FilteredBlockList, dns.TypeA},
<mask> {"mask", maskRules, "example.com", true, FilteredBlockList, dns.TypeA},
<mask> {"mask", maskRules, "exampleeee.com", true, FilteredBlockList, dns.TypeA},
<mask> {"mask", maskRules, "onemoreexamsite.com", true, FilteredBlockList, dns.TypeA},
<mask> {"mask", maskRules, "example.org", false, NotFilteredNotFound, dns.TypeA},
<mask> {"mask", maskRules, "testexample.org", false, NotFilteredNotFound, dns.TypeA},
<mask> {"mask", maskRules, "example.co.uk", false, NotFilteredNotFound, dns.TypeA},
<mask>
<mask> {"dnstype", dnstypeRules, "onemoreexample.org", false, NotFilteredNotFound, dns.TypeA},
<mask> {"dnstype", dnstypeRules, "example.org", false, NotFilteredNotFound, dns.TypeA},
<mask> {"dnstype", dnstypeRules, "example.org", true, FilteredBlockList, dns.TypeAAAA},
<mask> {"dnstype", dnstypeRules, "test.example.org", false, NotFilteredAllowList, dns.TypeA},
<mask> {"dnstype", dnstypeRules, "test.example.org", false, NotFilteredAllowList, dns.TypeAAAA},
<mask> }
<mask>
</s> 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 </s> remove for _, test := range tests {
t.Run(fmt.Sprintf("%s-%s", test.testname, test.hostname), func(t *testing.T) {
filters := []Filter{{
ID: 0, Data: []byte(test.rules),
}}
d := NewForTest(nil, filters)
defer d.Close()
res, err := d.CheckHost(test.hostname, test.dnsType, &setts)
if err != nil {
t.Errorf("Error while matching host %s: %s", test.hostname, err)
}
if res.IsFiltered != test.isFiltered {
t.Errorf("Hostname %s has wrong result (%v must be %v)", test.hostname, res.IsFiltered, test.isFiltered)
}
if res.Reason != test.reason {
t.Errorf("Hostname %s has wrong reason (%v must be %v)", test.hostname, res.Reason.String(), test.reason.String())
}
</s> add 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
)
testCases := []struct {
name string
rules string
host string
wantIsFiltered bool
wantReason Reason
wantDNSType uint16
}{{
name: "sanity",
rules: "||doubleclick.net^",
host: "www.doubleclick.net",
wantIsFiltered: true,
wantReason: FilteredBlockList,
wantDNSType: dns.TypeA,
}, {
name: "sanity",
rules: "||doubleclick.net^",
host: "nodoubleclick.net",
wantIsFiltered: false,
wantReason: NotFilteredNotFound,
wantDNSType: dns.TypeA,
}, {
name: "sanity",
rules: "||doubleclick.net^",
host: "doubleclick.net.ru",
wantIsFiltered: false,
wantReason: NotFilteredNotFound,
wantDNSType: dns.TypeA,
}, {
name: "sanity",
rules: "||doubleclick.net^",
host: "wmconvirus.narod.ru",
wantIsFiltered: false,
wantReason: NotFilteredNotFound,
wantDNSType: dns.TypeA,
}, {
name: "blocking",
rules: blockingRules,
host: "example.org",
wantIsFiltered: true,
wantReason: FilteredBlockList,
wantDNSType: dns.TypeA,
}, {
name: "blocking",
rules: blockingRules,
host: "test.example.org",
wantIsFiltered: true,
wantReason: FilteredBlockList,
wantDNSType: dns.TypeA,
}, {
name: "blocking",
rules: blockingRules,
host: "test.test.example.org",
wantIsFiltered: true,
wantReason: FilteredBlockList,
wantDNSType: dns.TypeA,
}, {
name: "blocking",
rules: blockingRules,
host: "testexample.org",
wantIsFiltered: false,
wantReason: NotFilteredNotFound,
wantDNSType: dns.TypeA,
}, {
name: "blocking",
rules: blockingRules,
host: "onemoreexample.org",
wantIsFiltered: false,
wantReason: NotFilteredNotFound,
wantDNSType: dns.TypeA,
}, {
name: "allowlist",
rules: allowlistRules,
host: "example.org",
wantIsFiltered: true,
wantReason: FilteredBlockList,
wantDNSType: dns.TypeA,
}, {
name: "allowlist",
rules: allowlistRules,
host: "test.example.org",
wantIsFiltered: false,
wantReason: NotFilteredAllowList,
wantDNSType: dns.TypeA,
}, {
name: "allowlist",
rules: allowlistRules,
host: "test.test.example.org",
wantIsFiltered: false,
wantReason: NotFilteredAllowList,
wantDNSType: dns.TypeA,
}, {
name: "allowlist",
rules: allowlistRules,
host: "testexample.org",
wantIsFiltered: false,
wantReason: NotFilteredNotFound,
wantDNSType: dns.TypeA,
}, {
name: "allowlist",
rules: allowlistRules,
host: "onemoreexample.org",
wantIsFiltered: false,
wantReason: NotFilteredNotFound,
wantDNSType: dns.TypeA,
}, {
name: "important",
rules: importantRules,
host: "example.org",
wantIsFiltered: false,
wantReason: NotFilteredAllowList,
wantDNSType: dns.TypeA,
}, {
name: "important",
rules: importantRules,
host: "test.example.org",
wantIsFiltered: true,
wantReason: FilteredBlockList,
wantDNSType: dns.TypeA,
}, {
name: "important",
rules: importantRules,
host: "test.test.example.org",
wantIsFiltered: true,
wantReason: FilteredBlockList,
wantDNSType: dns.TypeA,
}, {
name: "important",
rules: importantRules,
host: "testexample.org",
wantIsFiltered: false,
wantReason: NotFilteredNotFound,
wantDNSType: dns.TypeA,
}, {
name: "important",
rules: importantRules,
host: "onemoreexample.org",
wantIsFiltered: false,
wantReason: NotFilteredNotFound,
wantDNSType: dns.TypeA,
}, {
name: "regex",
rules: regexRules,
host: "example.org",
wantIsFiltered: true,
wantReason: FilteredBlockList,
wantDNSType: dns.TypeA,
}, {
name: "regex",
rules: regexRules,
host: "test.example.org",
wantIsFiltered: false,
wantReason: NotFilteredAllowList,
wantDNSType: dns.TypeA,
}, {
name: "regex",
rules: regexRules,
host: "test.test.example.org",
wantIsFiltered: false,
wantReason: NotFilteredAllowList,
wantDNSType: dns.TypeA,
}, {
name: "regex",
rules: regexRules,
host: "testexample.org",
wantIsFiltered: true,
wantReason: FilteredBlockList,
wantDNSType: dns.TypeA,
}, {
name: "regex",
rules: regexRules,
host: "onemoreexample.org",
wantIsFiltered: true,
wantReason: FilteredBlockList,
wantDNSType: dns.TypeA,
}, {
name: "mask",
rules: maskRules,
host: "test.example.org",
wantIsFiltered: true,
wantReason: FilteredBlockList,
wantDNSType: dns.TypeA,
}, {
name: "mask",
rules: maskRules,
host: "test2.example.org",
wantIsFiltered: true,
wantReason: FilteredBlockList,
wantDNSType: dns.TypeA,
}, {
name: "mask",
rules: maskRules,
host: "example.com",
wantIsFiltered: true,
wantReason: FilteredBlockList,
wantDNSType: dns.TypeA,
}, {
name: "mask",
rules: maskRules,
host: "exampleeee.com",
wantIsFiltered: true,
wantReason: FilteredBlockList,
wantDNSType: dns.TypeA,
}, {
name: "mask",
rules: maskRules,
host: "onemoreexamsite.com",
wantIsFiltered: true,
wantReason: FilteredBlockList,
wantDNSType: dns.TypeA,
}, {
name: "mask",
rules: maskRules,
host: "example.org",
wantIsFiltered: false,
wantReason: NotFilteredNotFound,
wantDNSType: dns.TypeA,
}, {
name: "mask",
rules: maskRules,
host: "testexample.org",
wantIsFiltered: false,
wantReason: NotFilteredNotFound,
wantDNSType: dns.TypeA,
}, {
name: "mask",
rules: maskRules,
host: "example.co.uk",
wantIsFiltered: false,
wantReason: NotFilteredNotFound,
wantDNSType: dns.TypeA,
}, {
name: "dnstype",
rules: dnstypeRules,
host: "onemoreexample.org",
wantIsFiltered: false,
wantReason: NotFilteredNotFound,
wantDNSType: dns.TypeA,
}, {
name: "dnstype",
rules: dnstypeRules,
host: "example.org",
wantIsFiltered: false,
wantReason: NotFilteredNotFound,
wantDNSType: dns.TypeA,
}, {
name: "dnstype",
rules: dnstypeRules,
host: "example.org",
wantIsFiltered: true,
wantReason: FilteredBlockList,
wantDNSType: dns.TypeAAAA,
}, {
name: "dnstype",
rules: dnstypeRules,
host: "test.example.org",
wantIsFiltered: false,
wantReason: NotFilteredAllowList,
wantDNSType: dns.TypeA,
}, {
name: "dnstype",
rules: dnstypeRules,
host: "test.example.org",
wantIsFiltered: false,
wantReason: NotFilteredAllowList,
wantDNSType: dns.TypeAAAA,
}}
for _, tc := range testCases {
t.Run(fmt.Sprintf("%s-%s", tc.name, tc.host), func(t *testing.T) {
filters := []Filter{{ID: 0, Data: []byte(tc.rules)}}
d := newForTest(nil, filters)
t.Cleanup(d.Close)
res, err := d.CheckHost(tc.host, tc.wantDNSType, &setts)
assert.Nilf(t, err, "Error while matching host %s: %s", tc.host, err)
assert.Equalf(t, tc.wantIsFiltered, res.IsFiltered, "Hostname %s has wrong result (%v must be %v)", tc.host, res.IsFiltered, tc.wantIsFiltered)
assert.Equalf(t, tc.wantReason, res.Reason, "Hostname %s has wrong reason (%v must be %v)", tc.host, res.Reason, tc.wantReason) </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 d := DNSFilter{}
</s> add d := newForTest(nil, nil)
t.Cleanup(d.Close) </s> add u.counterLock.Unlock() </s> remove d := DNSFilter{}
</s> add d := newForTest(nil, nil)
t.Cleanup(d.Close) | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep | <mask> {"dnstype", dnstypeRules, "test.example.org", false, NotFilteredAllowList, dns.TypeAAAA},
<mask> }
<mask>
<mask> func TestMatching(t *testing.T) {
<mask> for _, test := range tests {
<mask> t.Run(fmt.Sprintf("%s-%s", test.testname, test.hostname), func(t *testing.T) {
<mask> filters := []Filter{{
<mask> ID: 0, Data: []byte(test.rules),
<mask> }}
<mask> d := NewForTest(nil, filters)
<mask> defer d.Close()
<mask>
<mask> res, err := d.CheckHost(test.hostname, test.dnsType, &setts)
<mask> if err != nil {
<mask> t.Errorf("Error while matching host %s: %s", test.hostname, err)
<mask> }
<mask> if res.IsFiltered != test.isFiltered {
<mask> t.Errorf("Hostname %s has wrong result (%v must be %v)", test.hostname, res.IsFiltered, test.isFiltered)
<mask> }
<mask> if res.Reason != test.reason {
<mask> t.Errorf("Hostname %s has wrong reason (%v must be %v)", test.hostname, res.Reason.String(), test.reason.String())
<mask> }
<mask> })
<mask> }
<mask> }
<mask>
<mask> func TestWhitelist(t *testing.T) {
</s> 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 </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 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 // 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. | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep replace keep replace | <mask> }}
<mask> d := NewForTest(nil, filters)
<mask> d.SetFilters(filters, whiteFilters, false)
<mask> defer d.Close()
</s> 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 </s> remove // matched by white filter
</s> add // Matched by white filter. </s> remove d := NewForTest(nil, filters)
defer d.Close()
</s> add d := newForTest(nil, filters)
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 d := NewForTest(nil, nil)
defer d.Close()
</s> add d := newForTest(nil, 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
| https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep keep keep replace keep keep keep keep keep | <mask> d := NewForTest(nil, filters)
<mask> d.SetFilters(filters, whiteFilters, false)
<mask> defer d.Close()
<mask>
<mask> // matched by white filter
<mask> res, err := d.CheckHost("host1", dns.TypeA, &setts)
<mask> assert.Nil(t, err)
<mask> assert.False(t, res.IsFiltered)
<mask> assert.Equal(t, res.Reason, NotFilteredAllowList)
<mask> if assert.Len(t, res.Rules, 1) {
</s> 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 </s> remove defer d.Close()
</s> add t.Cleanup(d.Close) </s> remove d := NewForTest(nil, filters)
</s> add d := newForTest(nil, filters) </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 // 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)) </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}) | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep keep keep replace keep keep keep keep keep | <mask> if assert.Len(t, res.Rules, 1) {
<mask> assert.Equal(t, "||host1^", res.Rules[0].Text)
<mask> }
<mask>
<mask> // not matched by white filter, but matched by block filter
<mask> res, err = d.CheckHost("host2", dns.TypeA, &setts)
<mask> assert.Nil(t, err)
<mask> assert.True(t, res.IsFiltered)
<mask> assert.Equal(t, res.Reason, FilteredBlockList)
<mask> if assert.Len(t, res.Rules, 1) {
</s> 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 </s> remove // matched by white filter
</s> add // Matched by white filter. </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 // ...but empty IPv4
</s> add // Empty IPv4. </s> remove // ...but empty IPv6
</s> add // Empty IPv6. </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)) | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep keep keep replace keep keep keep keep keep | <mask> assert.Equal(t, "||host2^", res.Rules[0].Text)
<mask> }
<mask> }
<mask>
<mask> // CLIENT SETTINGS
<mask>
<mask> func applyClientSettings(setts *RequestFilteringSettings) {
<mask> setts.FilteringEnabled = false
<mask> setts.ParentalEnabled = false
<mask> setts.SafeBrowsingEnabled = true
</s> 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 </s> remove func NewForTest(c *Config, filters []Filter) *DNSFilter {
</s> add func newForTest(c *Config, filters []Filter) *DNSFilter { </s> remove // IPv6
</s> add // IPv6 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. </s> remove // 2 IPv4 (return only the first one)
</s> add // Two IPv4, the first one returned. </s> remove
// blocked by additional rules
r, _ = d.CheckHost("facebook.com", dns.TypeA, &setts)
assert.True(t, r.IsFiltered)
assert.Equal(t, r.Reason, FilteredBlockedService)
</s> add </s> remove // ...but empty IPv4
</s> add // Empty IPv4. | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep keep replace replace keep replace replace replace keep | <mask> setts.ServicesRules = append(setts.ServicesRules, s)
<mask> }
<mask>
<mask> // Check behaviour without any per-client settings,
<mask> // then apply per-client settings and check behaviour once again
<mask> func TestClientSettings(t *testing.T) {
<mask> var r Result
<mask> filters := []Filter{{
<mask> ID: 0, Data: []byte("||example.org^\n"),
<mask> }}
</s> 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 </s> remove // safesearch is disabled
r, _ = d.CheckHost("wmconvirus.narod.ru", dns.TypeA, &setts)
if r.IsFiltered {
t.Fatalf("CheckHost safesearch")
</s> add // Check behaviour without any per-client settings, then apply per-client
// settings and check behaviour once again.
for _, tc := range testCases {
t.Run(tc.name, makeTester(tc, tc.before)) </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 := NewForTest(nil, filters)
defer d.Close()
</s> add d := newForTest(nil, filters)
t.Cleanup(d.Close) </s> remove d := NewForTest(nil, filters)
</s> add d := newForTest(nil, filters) </s> remove defer d.Close()
</s> add t.Cleanup(d.Close) | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep keep replace replace replace replace replace replace replace replace replace replace keep replace replace replace replace | <mask> filters := []Filter{{
<mask> ID: 0, Data: []byte("||example.org^\n"),
<mask> }}
<mask> d := NewForTest(&Config{ParentalEnabled: true, SafeBrowsingEnabled: false}, filters)
<mask> defer d.Close()
<mask>
<mask> // no client settings:
<mask>
<mask> // blocked by filters
<mask> r, _ = d.CheckHost("example.org", dns.TypeA, &setts)
<mask> if !r.IsFiltered || r.Reason != FilteredBlockList {
<mask> t.Fatalf("CheckHost FilteredBlockList")
<mask> }
<mask>
<mask> // blocked by parental
<mask> r, _ = d.CheckHost("pornhub.com", dns.TypeA, &setts)
<mask> if !r.IsFiltered || r.Reason != FilteredParental {
<mask> t.Fatalf("CheckHost FilteredParental")
</s> 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 </s> remove // override filtering settings
r, _ = d.CheckHost("example.org", dns.TypeA, &setts)
if r.IsFiltered {
t.Fatalf("CheckHost")
}
// override parental settings (force disable parental)
r, _ = d.CheckHost("pornhub.com", dns.TypeA, &setts)
if r.IsFiltered {
t.Fatalf("CheckHost")
}
// override safesearch settings (force enable safesearch)
r, _ = d.CheckHost("wmconvirus.narod.ru", dns.TypeA, &setts)
if !r.IsFiltered || r.Reason != FilteredSafeBrowsing {
t.Fatalf("CheckHost FilteredSafeBrowsing")
</s> add for _, tc := range testCases {
t.Run(tc.name, makeTester(tc, !tc.before)) </s> remove
// blocked by additional rules
r, _ = d.CheckHost("facebook.com", dns.TypeA, &setts)
assert.True(t, r.IsFiltered)
assert.Equal(t, r.Reason, FilteredBlockedService)
</s> add </s> remove // safesearch is disabled
r, _ = d.CheckHost("wmconvirus.narod.ru", dns.TypeA, &setts)
if r.IsFiltered {
t.Fatalf("CheckHost safesearch")
</s> add // Check behaviour without any per-client settings, then apply per-client
// settings and check behaviour once again.
for _, tc := range testCases {
t.Run(tc.name, makeTester(tc, tc.before)) </s> remove // not blocked
r, _ = d.CheckHost("facebook.com", dns.TypeA, &setts)
assert.False(t, r.IsFiltered)
// override client settings:
</s> add </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, | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep keep keep replace replace replace replace keep keep replace replace replace replace replace keep keep | <mask> if !r.IsFiltered || r.Reason != FilteredParental {
<mask> t.Fatalf("CheckHost FilteredParental")
<mask> }
<mask>
<mask> // safesearch is disabled
<mask> r, _ = d.CheckHost("wmconvirus.narod.ru", dns.TypeA, &setts)
<mask> if r.IsFiltered {
<mask> t.Fatalf("CheckHost safesearch")
<mask> }
<mask>
<mask> // not blocked
<mask> r, _ = d.CheckHost("facebook.com", dns.TypeA, &setts)
<mask> assert.False(t, r.IsFiltered)
<mask>
<mask> // override client settings:
<mask> applyClientSettings(&setts)
<mask>
</s> 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 </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)
}
} </s> remove // override filtering settings
r, _ = d.CheckHost("example.org", dns.TypeA, &setts)
if r.IsFiltered {
t.Fatalf("CheckHost")
}
// override parental settings (force disable parental)
r, _ = d.CheckHost("pornhub.com", dns.TypeA, &setts)
if r.IsFiltered {
t.Fatalf("CheckHost")
}
// override safesearch settings (force enable safesearch)
r, _ = d.CheckHost("wmconvirus.narod.ru", dns.TypeA, &setts)
if !r.IsFiltered || r.Reason != FilteredSafeBrowsing {
t.Fatalf("CheckHost FilteredSafeBrowsing")
</s> add for _, tc := range testCases {
t.Run(tc.name, makeTester(tc, !tc.before)) </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
// blocked by additional rules
r, _ = d.CheckHost("facebook.com", dns.TypeA, &setts)
assert.True(t, r.IsFiltered)
assert.Equal(t, r.Reason, FilteredBlockedService)
</s> add </s> remove d = NewForTest(&Config{SafeSearchEnabled: true}, nil)
defer d.Close()
</s> add d = newForTest(&Config{SafeSearchEnabled: true}, nil)
t.Cleanup(d.Close) | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep replace replace replace replace replace keep | <mask> applyClientSettings(&setts)
<mask>
<mask> // override filtering settings
<mask> r, _ = d.CheckHost("example.org", dns.TypeA, &setts)
<mask> if r.IsFiltered {
<mask> t.Fatalf("CheckHost")
<mask> }
<mask>
<mask> // override parental settings (force disable parental)
<mask> r, _ = d.CheckHost("pornhub.com", dns.TypeA, &setts)
<mask> if r.IsFiltered {
<mask> t.Fatalf("CheckHost")
<mask> }
<mask>
<mask> // override safesearch settings (force enable safesearch)
<mask> r, _ = d.CheckHost("wmconvirus.narod.ru", dns.TypeA, &setts)
<mask> if !r.IsFiltered || r.Reason != FilteredSafeBrowsing {
<mask> t.Fatalf("CheckHost FilteredSafeBrowsing")
<mask> }
<mask>
<mask> // blocked by additional rules
<mask> r, _ = d.CheckHost("facebook.com", dns.TypeA, &setts)
<mask> assert.True(t, r.IsFiltered)
<mask> assert.Equal(t, r.Reason, FilteredBlockedService)
<mask> }
</s> 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 </s> remove // not blocked
r, _ = d.CheckHost("facebook.com", dns.TypeA, &setts)
assert.False(t, r.IsFiltered)
// override client settings:
</s> add </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)
}
} </s> remove // safesearch is disabled
r, _ = d.CheckHost("wmconvirus.narod.ru", dns.TypeA, &setts)
if r.IsFiltered {
t.Fatalf("CheckHost safesearch")
</s> add // Check behaviour without any per-client settings, then apply per-client
// settings and check behaviour once again.
for _, tc := range testCases {
t.Run(tc.name, makeTester(tc, tc.before)) </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 // not matched by white filter, but matched by block filter
</s> add // Not matched by white filter, but matched by block filter. | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep keep keep replace keep keep keep keep keep | <mask> assert.True(t, r.IsFiltered)
<mask> assert.Equal(t, r.Reason, FilteredBlockedService)
<mask> }
<mask>
<mask> // BENCHMARKS
<mask>
<mask> func BenchmarkSafeBrowsing(b *testing.B) {
<mask> d := NewForTest(&Config{SafeBrowsingEnabled: true}, nil)
<mask> defer d.Close()
<mask> for n := 0; n < b.N; n++ {
</s> 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 </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,
} </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 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 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
// blocked by additional rules
r, _ = d.CheckHost("facebook.com", dns.TypeA, &setts)
assert.True(t, r.IsFiltered)
assert.Equal(t, r.Reason, FilteredBlockedService)
</s> add </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,
}
| https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
keep keep keep replace replace keep replace replace replace replace replace replace replace replace keep keep keep | <mask> // BENCHMARKS
<mask>
<mask> func BenchmarkSafeBrowsing(b *testing.B) {
<mask> d := NewForTest(&Config{SafeBrowsingEnabled: true}, nil)
<mask> defer d.Close()
<mask> for n := 0; n < b.N; n++ {
<mask> hostname := "wmconvirus.narod.ru"
<mask> res, err := d.CheckHost(hostname, dns.TypeA, &setts)
<mask> if err != nil {
<mask> b.Errorf("Error while matching host %s: %s", hostname, err)
<mask> }
<mask> if !res.IsFiltered {
<mask> b.Errorf("Expected hostname %s to match", hostname)
<mask> }
<mask> }
<mask> }
<mask>
</s> 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 </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 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 // BENCHMARKS
</s> add // Benchmarks. </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) | https://github.com/AdguardTeam/AdGuardHome/commit/0d0a419bd34dd8fe612f790ace698aebd930bfcc | internal/dnsfilter/dnsfilter_test.go |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.