Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

7421 add brave safe search #7552

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/filtering/safesearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 4 additions & 0 deletions internal/filtering/safesearch/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions internal/filtering/safesearch/rules/brave.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
|search.brave.com^$dnsrewrite=NOERROR;CNAME;safesearch.brave.com
3 changes: 3 additions & 0 deletions internal/filtering/safesearch/safesearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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))
}
Expand Down
25 changes: 25 additions & 0 deletions internal/filtering/safesearch/safesearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var testConf = filtering.SafeSearchConfig{
Enabled: true,

Bing: true,
Brave: true,
DuckDuckGo: true,
Ecosia: true,
Google: true,
Expand Down Expand Up @@ -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)
})
}
1 change: 1 addition & 0 deletions internal/home/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ var config = &configuration{

SafeSearchConf: filtering.SafeSearchConfig{
Enabled: false,
Brave: true,
Bing: true,
DuckDuckGo: true,
Ecosia: true,
Expand Down