Merge bd48661a9531fb093731f2d0f3d9e2375574fd21 into 8f75c6ac9dd3acac09d7d1a6422b1834fe6acc9c

This commit is contained in:
Florian Lang 2025-01-19 22:27:00 +00:00 committed by GitHub
commit de22d5d023
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 35 additions and 0 deletions

View File

@ -23,6 +23,7 @@ type SafeSearchConfig struct {
// enabled or disabled.
Bing bool `yaml:"bing" json:"bing"`
Brave bool `yaml:"brave" json:"brave"`
DuckDuckGo bool `yaml:"duckduckgo" json:"duckduckgo"`
Ecosia bool `yaml:"ecosia" json:"ecosia"`
Google bool `yaml:"google" json:"google"`

View File

@ -5,6 +5,9 @@ import _ "embed"
//go:embed rules/bing.txt
var bing string
//go:embed rules/brave.txt
var brave string
//go:embed rules/google.txt
var google string
@ -29,6 +32,7 @@ var youtube string
// https://adguardteam.github.io/HostlistsRegistry/assets/youtube_safe_search.txt.
var safeSearchRules = map[Service]string{
Bing: bing,
Brave: brave,
DuckDuckGo: duckduckgo,
Ecosia: ecosia,
Google: google,

View File

@ -0,0 +1 @@
|search.brave.com^$dnsrewrite=NOERROR;CNAME;safesearch.brave.com

View File

@ -36,6 +36,7 @@ type Service string
// Service enum members.
const (
Bing Service = "bing"
Brave Service = "brave"
DuckDuckGo Service = "duckduckgo"
Ecosia Service = "ecosia"
Google Service = "google"
@ -61,6 +62,8 @@ func isServiceProtected(s filtering.SafeSearchConfig, service Service) (ok bool)
return s.Yandex
case YouTube:
return s.YouTube
case Brave:
return s.Brave
default:
panic(fmt.Errorf("safesearch: invalid sources: not found service %q", service))
}

View File

@ -33,6 +33,7 @@ var testConf = filtering.SafeSearchConfig{
Enabled: true,
Bing: true,
Brave: true,
DuckDuckGo: true,
Ecosia: true,
Google: true,
@ -220,3 +221,27 @@ func TestDefault_Update(t *testing.T) {
assert.False(t, res.IsFiltered)
}
func TestDefault_CheckHost_brave(t *testing.T) {
ctx := testutil.ContextWithTimeout(t, testTimeout)
ss, err := safesearch.NewDefault(ctx, &safesearch.DefaultConfig{
Logger: slogutil.NewDiscardLogger(),
ServicesConfig: testConf,
CacheSize: testCacheSize,
CacheTTL: testCacheTTL,
})
require.NoError(t, err)
host := "search.brave.com"
t.Run(host, func(t *testing.T) {
var res filtering.Result
res, err = ss.CheckHost(ctx, host, testQType)
require.NoError(t, err)
assert.True(t, res.IsFiltered)
assert.Equal(t, filtering.FilteredSafeSearch, res.Reason)
assert.Equal(t, "safesearch.brave.com", res.CanonName)
assert.Empty(t, res.Rules)
})
}

View File

@ -432,6 +432,7 @@ var config = &configuration{
SafeSearchConf: filtering.SafeSearchConfig{
Enabled: false,
Brave: true,
Bing: true,
DuckDuckGo: true,
Ecosia: true,