mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-12-17 05:01:35 +03:00
37e046acc4
Merge in DNS/adguard-home from fix-blocked-services-client-schedule to master
Updates #951.
Squashed commit of the following:
commit 1c890953ff4b7862db10f99f4851797050ad9d8e
Merge: ac0b722d1 f40ef76c7
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Thu Jun 22 15:54:03 2023 +0300
Merge branch 'master' into fix-blocked-services-client-schedule
commit ac0b722d1deef664ab464e0bff387542e027bd3f
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Thu Jun 22 14:32:03 2023 +0300
home: fix typo
commit 64eb519c4b77cff1071059f1f41acfd0e3ea9513
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Thu Jun 22 14:23:07 2023 +0300
home: add test case
commit c7b60f3ea89e41f8b84bf6f2f5e075e9b3dd45ec
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Thu Jun 22 12:00:24 2023 +0300
home: imp code
commit 7806c920bb0c4b4c44c3fed7e920f795904630b2
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Wed Jun 21 20:49:47 2023 +0300
home: add tests
commit d37c9fde882965f005ddec86ad0502585d2eea95
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Wed Jun 21 18:49:43 2023 +0300
home: fix client blocked services
81 lines
1.7 KiB
Go
81 lines
1.7 KiB
Go
package home
|
|
|
|
import (
|
|
"net"
|
|
"testing"
|
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
|
"github.com/AdguardTeam/AdGuardHome/internal/schedule"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestApplyAdditionalFiltering_blockedServices(t *testing.T) {
|
|
filtering.InitModule()
|
|
|
|
var (
|
|
globalBlockedServices = []string{"ok"}
|
|
clientBlockedServices = []string{"ok", "mail_ru", "vk"}
|
|
invalidBlockedServices = []string{"invalid"}
|
|
|
|
err error
|
|
)
|
|
|
|
Context.filters, err = filtering.New(&filtering.Config{
|
|
BlockedServices: &filtering.BlockedServices{
|
|
Schedule: schedule.EmptyWeekly(),
|
|
IDs: globalBlockedServices,
|
|
},
|
|
}, nil)
|
|
require.NoError(t, err)
|
|
|
|
Context.clients.idIndex = map[string]*Client{
|
|
"client_1": {
|
|
UseOwnBlockedServices: false,
|
|
},
|
|
"client_2": {
|
|
UseOwnBlockedServices: true,
|
|
},
|
|
"client_3": {
|
|
BlockedServices: clientBlockedServices,
|
|
UseOwnBlockedServices: true,
|
|
},
|
|
"client_4": {
|
|
BlockedServices: invalidBlockedServices,
|
|
UseOwnBlockedServices: true,
|
|
},
|
|
}
|
|
|
|
testCases := []struct {
|
|
name string
|
|
ip net.IP
|
|
id string
|
|
setts *filtering.Settings
|
|
wantLen int
|
|
}{{
|
|
name: "global_settings",
|
|
id: "client_1",
|
|
wantLen: len(globalBlockedServices),
|
|
}, {
|
|
name: "custom_settings",
|
|
id: "client_2",
|
|
wantLen: 0,
|
|
}, {
|
|
name: "custom_settings_block",
|
|
id: "client_3",
|
|
wantLen: len(clientBlockedServices),
|
|
}, {
|
|
name: "custom_settings_invalid",
|
|
id: "client_4",
|
|
wantLen: 0,
|
|
}}
|
|
|
|
for _, tc := range testCases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
setts := &filtering.Settings{}
|
|
|
|
applyAdditionalFiltering(net.IP{1, 2, 3, 4}, tc.id, setts)
|
|
require.Len(t, setts.ServicesRules, tc.wantLen)
|
|
})
|
|
}
|
|
}
|