@@ -27,6 +27,7 @@ import (
2727 "github.com/AdguardTeam/AdGuardHome/internal/filtering"
2828 "github.com/AdguardTeam/AdGuardHome/internal/filtering/hashprefix"
2929 "github.com/AdguardTeam/AdGuardHome/internal/filtering/safesearch"
30+ "github.com/AdguardTeam/AdGuardHome/internal/schedule"
3031 "github.com/AdguardTeam/dnsproxy/proxy"
3132 "github.com/AdguardTeam/dnsproxy/upstream"
3233 "github.com/AdguardTeam/golibs/logutil/slogutil"
@@ -106,6 +107,21 @@ func startDeferStop(t *testing.T, s *Server) {
106107 testutil .CleanupAndRequireSuccess (t , s .Stop )
107108}
108109
110+ // applyEmptyClientFiltering is a helper function for tests with
111+ // [filtering.Config] that does nothing.
112+ func applyEmptyClientFiltering (_ string , _ netip.Addr , _ * filtering.Settings ) {}
113+
114+ // emptyFilteringBlockedServices is a helper function that returns an empty
115+ // filtering blocked services for tests.
116+ func emptyFilteringBlockedServices () (bsvc * filtering.BlockedServices ) {
117+ return & filtering.BlockedServices {
118+ Schedule : schedule .EmptyWeekly (),
119+ }
120+ }
121+
122+ // createTestServer is a helper function that returns a properly initialized
123+ // *Server for use in tests, given the provided parameters. It also populates
124+ // the filtering configuration with default parameters.
109125func createTestServer (
110126 t * testing.T ,
111127 filterConf * filtering.Config ,
@@ -123,6 +139,12 @@ func createTestServer(
123139 Data : []byte (rules ),
124140 }}
125141
142+ filterConf .BlockedServices = cmp .Or (filterConf .BlockedServices , emptyFilteringBlockedServices ())
143+
144+ if filterConf .ApplyClientFiltering == nil {
145+ filterConf .ApplyClientFiltering = applyEmptyClientFiltering
146+ }
147+
126148 f , err := filtering .New (filterConf , filters )
127149 require .NoError (t , err )
128150
@@ -926,9 +948,6 @@ func TestClientRulesForCNAMEMatching(t *testing.T) {
926948 UDPListenAddrs : []* net.UDPAddr {{}},
927949 TCPListenAddrs : []* net.TCPAddr {{}},
928950 Config : Config {
929- FilterHandler : func (_ netip.Addr , _ string , settings * filtering.Settings ) {
930- settings .FilteringEnabled = false
931- },
932951 UpstreamMode : UpstreamModeLoadBalance ,
933952 EDNSClientSubnet : & EDNSClientSubnet {
934953 Enabled : false ,
@@ -1020,10 +1039,12 @@ func TestBlockedCustomIP(t *testing.T) {
10201039 }}
10211040
10221041 f , err := filtering .New (& filtering.Config {
1023- ProtectionEnabled : true ,
1024- BlockingMode : filtering .BlockingModeCustomIP ,
1025- BlockingIPv4 : netip.Addr {},
1026- BlockingIPv6 : netip.Addr {},
1042+ ProtectionEnabled : true ,
1043+ ApplyClientFiltering : applyEmptyClientFiltering ,
1044+ BlockedServices : emptyFilteringBlockedServices (),
1045+ BlockingMode : filtering .BlockingModeCustomIP ,
1046+ BlockingIPv4 : netip.Addr {},
1047+ BlockingIPv6 : netip.Addr {},
10271048 }, filters )
10281049 require .NoError (t , err )
10291050
@@ -1176,7 +1197,9 @@ func TestBlockedBySafeBrowsing(t *testing.T) {
11761197
11771198func TestRewrite (t * testing.T ) {
11781199 c := & filtering.Config {
1179- BlockingMode : filtering .BlockingModeDefault ,
1200+ ApplyClientFiltering : applyEmptyClientFiltering ,
1201+ BlockedServices : emptyFilteringBlockedServices (),
1202+ BlockingMode : filtering .BlockingModeDefault ,
11801203 Rewrites : []* filtering.LegacyRewrite {{
11811204 Domain : "test.com" ,
11821205 Answer : "1.2.3.4" ,
@@ -1322,7 +1345,9 @@ func TestPTRResponseFromDHCPLeases(t *testing.T) {
13221345 const localDomain = "lan"
13231346
13241347 flt , err := filtering .New (& filtering.Config {
1325- BlockingMode : filtering .BlockingModeDefault ,
1348+ ApplyClientFiltering : applyEmptyClientFiltering ,
1349+ BlockedServices : emptyFilteringBlockedServices (),
1350+ BlockingMode : filtering .BlockingModeDefault ,
13261351 }, nil )
13271352 require .NoError (t , err )
13281353
@@ -1411,8 +1436,10 @@ func TestPTRResponseFromHosts(t *testing.T) {
14111436 })
14121437
14131438 flt , err := filtering .New (& filtering.Config {
1414- BlockingMode : filtering .BlockingModeDefault ,
1415- EtcHosts : hc ,
1439+ ApplyClientFiltering : applyEmptyClientFiltering ,
1440+ BlockedServices : emptyFilteringBlockedServices (),
1441+ BlockingMode : filtering .BlockingModeDefault ,
1442+ EtcHosts : hc ,
14161443 }, nil )
14171444 require .NoError (t , err )
14181445
0 commit comments