AdGuardHome/internal/home/clients_internal_test.go

65 lines
1.4 KiB
Go
Raw Normal View History

package home
import (
"net"
"net/netip"
"testing"
"github.com/AdguardTeam/AdGuardHome/internal/client"
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/golibs/logutil/slogutil"
"github.com/AdguardTeam/golibs/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// newClientsContainer is a helper that creates a new clients container for
// tests.
Pull request 1883: 951-blocked-services-client-schedule Updates #951. Squashed commit of the following: commit 94e4766932940a99c5265489bccb46d0ed6cec25 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Jun 27 17:21:41 2023 +0300 chlog: upd docs commit b4022c33860c258bf29650413f0c972b849a1758 Merge: cfa24ff01 e7e638443 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Jun 27 16:33:20 2023 +0300 Merge branch 'master' into 951-blocked-services-client-schedule commit cfa24ff0190b2bc12736700eeff815525fbaf5fe Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Jun 27 15:04:10 2023 +0300 chlog: imp docs commit dad27590d5eefde82758d58fc06a20c139492db8 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Jun 26 17:38:08 2023 +0300 home: imp err msg commit 7d9ba98c4477000fc2e0f06c3462fe9cd0c65293 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Jun 26 16:58:00 2023 +0300 all: add tests commit 8e952fc4e3b3d433b29efe47c88d6b7806e99ff8 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Jun 23 16:36:10 2023 +0300 schedule: add todo commit 723573a98d5b930334a5fa125eb12593f4a2430d Merge: 2151ab2a6 e54fc9b1e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Jun 23 11:40:03 2023 +0300 Merge branch 'master' into 951-blocked-services-client-schedule commit 2151ab2a627b9833ba6cce9621f72b29d326da75 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Jun 23 11:37:49 2023 +0300 all: add tests commit 81ab341db3e4053f09b181d8111c0da197bdac05 Merge: aa7ae41a8 66345e855 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Jun 22 17:59:01 2023 +0300 Merge branch 'master' into 951-blocked-services-client-schedule commit aa7ae41a868045fe24e390b25f15551fd8821529 Merge: 304389a48 06d465b0d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Jun 21 17:10:11 2023 +0300 Merge branch 'master' into 951-blocked-services-client-schedule commit 304389a487f728e8ced293ea811a4e0026a37f0d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Jun 21 17:05:31 2023 +0300 home: imp err msg commit 29cfc7ae2a0bbd5ec3205eae3f6f810519787f26 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Jun 20 20:42:59 2023 +0300 all: imp err handling commit 8543868eef6442fd30131d9567b66222999101e9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Jun 20 18:21:50 2023 +0300 all: upd chlog commit c5b614d45e5cf25c30c52343f48139fb34c77539 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Jun 20 14:37:47 2023 +0300 all: add blocked services schedule
2023-06-27 18:03:07 +03:00
func newClientsContainer(t *testing.T) (c *clientsContainer) {
t.Helper()
c = &clientsContainer{
testing: true,
}
ctx := testutil.ContextWithTimeout(t, testTimeout)
err := c.Init(
ctx,
slogutil.NewDiscardLogger(),
nil,
client.EmptyDHCP{},
nil,
nil,
&filtering.Config{},
)
require.NoError(t, err)
return c
}
func TestClientsCustomUpstream(t *testing.T) {
Pull request 1883: 951-blocked-services-client-schedule Updates #951. Squashed commit of the following: commit 94e4766932940a99c5265489bccb46d0ed6cec25 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Jun 27 17:21:41 2023 +0300 chlog: upd docs commit b4022c33860c258bf29650413f0c972b849a1758 Merge: cfa24ff01 e7e638443 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Jun 27 16:33:20 2023 +0300 Merge branch 'master' into 951-blocked-services-client-schedule commit cfa24ff0190b2bc12736700eeff815525fbaf5fe Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Jun 27 15:04:10 2023 +0300 chlog: imp docs commit dad27590d5eefde82758d58fc06a20c139492db8 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Jun 26 17:38:08 2023 +0300 home: imp err msg commit 7d9ba98c4477000fc2e0f06c3462fe9cd0c65293 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Jun 26 16:58:00 2023 +0300 all: add tests commit 8e952fc4e3b3d433b29efe47c88d6b7806e99ff8 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Jun 23 16:36:10 2023 +0300 schedule: add todo commit 723573a98d5b930334a5fa125eb12593f4a2430d Merge: 2151ab2a6 e54fc9b1e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Jun 23 11:40:03 2023 +0300 Merge branch 'master' into 951-blocked-services-client-schedule commit 2151ab2a627b9833ba6cce9621f72b29d326da75 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Jun 23 11:37:49 2023 +0300 all: add tests commit 81ab341db3e4053f09b181d8111c0da197bdac05 Merge: aa7ae41a8 66345e855 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Jun 22 17:59:01 2023 +0300 Merge branch 'master' into 951-blocked-services-client-schedule commit aa7ae41a868045fe24e390b25f15551fd8821529 Merge: 304389a48 06d465b0d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Jun 21 17:10:11 2023 +0300 Merge branch 'master' into 951-blocked-services-client-schedule commit 304389a487f728e8ced293ea811a4e0026a37f0d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Jun 21 17:05:31 2023 +0300 home: imp err msg commit 29cfc7ae2a0bbd5ec3205eae3f6f810519787f26 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Jun 20 20:42:59 2023 +0300 all: imp err handling commit 8543868eef6442fd30131d9567b66222999101e9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Jun 20 18:21:50 2023 +0300 all: upd chlog commit c5b614d45e5cf25c30c52343f48139fb34c77539 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Jun 20 14:37:47 2023 +0300 all: add blocked services schedule
2023-06-27 18:03:07 +03:00
clients := newClientsContainer(t)
ctx := testutil.ContextWithTimeout(t, testTimeout)
// Add client with upstreams.
err := clients.storage.Add(ctx, &client.Persistent{
Name: "client1",
UID: client.MustNewUID(),
Pull request 2122: AG-27492-client-persistent-ids Squashed commit of the following: commit a0527b86f10596a86357630117607a3c507e4ac2 Merge: 512edaf2d 9694f19ef Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Jan 17 13:15:18 2024 +0300 Merge branch 'master' into AG-27492-client-persistent-ids commit 512edaf2dc29f19c4fb7860b0c350a5e4180cda4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Jan 15 15:50:28 2024 +0300 home: imp docs commit 4d4b3599918aab8ee6315c7f2f35f70db89e4d02 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Jan 11 20:20:42 2024 +0300 home: imp code commit 8031347b8613cc49a80968e162dd198851eafe7c Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Jan 11 18:46:20 2024 +0300 home: fix typo commit 5932b181fe6a0c0bc605070fd9ddcc6617703ab7 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Jan 11 16:52:49 2024 +0300 home: imp code more commit 9412f5846795acfb68b009491b1045d1e27d8ddc Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Jan 11 15:41:23 2024 +0300 home: imp code commit 855d3201ab1b176ed5fdd32bce933a7795601a6d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Jan 10 20:24:49 2024 +0300 home: add tests commit 112f1bd13acf992b0ba9562c29365b22d5374ec2 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Dec 29 18:29:11 2023 +0300 home: imp code commit 8b295bfa8968c3767bcfaf05c7f109d75af8c961 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Dec 29 14:58:17 2023 +0300 home: persistent client ids
2024-01-17 13:24:21 +03:00
IPs: []netip.Addr{netip.MustParseAddr("1.1.1.1"), netip.MustParseAddr("1:2:3::4")},
Upstreams: []string{
"1.1.1.1",
"[/example.org/]8.8.8.8",
},
})
require.NoError(t, err)
Pull request: custom upstreams cache Merge in DNS/adguard-home from custom-ups-cache to master Squashed commit of the following: commit 98428a87520f70cb522701d8eccfe4c529be1e40 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Nov 17 10:53:32 2023 +0200 all: upd dep commit 775a639af4a2a45220b17e8b0037edc126ff62e4 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Nov 17 09:52:31 2023 +0200 dnsforward: imp test commit e9e2a58b48e8588dfcb28df319d4651e1fe77af5 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Nov 17 09:44:46 2023 +0200 docs: changelog commit a6d67218f037c8fec29e5fa2967476d63c3cfc32 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Nov 17 09:37:17 2023 +0200 all: upd dep commit b101ff6e0cf393dacdee6fb68d33ba8f11c36280 Merge: d61f4eb88 8bb1aad73 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Nov 16 15:54:05 2023 +0200 Merge remote-tracking branch 'origin/master' into custom-ups-cache commit d61f4eb8871f8ae8504259998bf9015b29001cfb Merge: 567a8a4af fdf60eeed Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Nov 13 10:32:22 2023 +0200 Merge remote-tracking branch 'origin/master' into custom-ups-cache commit 567a8a4af34ad001d0e6d7d2efdc123205569e8c Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Nov 13 10:30:24 2023 +0200 home: imp code commit a3c16facbebc166e5c0c731c1e892b61c0950d9e Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Nov 10 14:34:04 2023 +0200 all: imp code commit 84160eafee1d0f2d0cd3f025f2d5070e4f597ad6 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Nov 10 14:31:26 2023 +0200 all: conf custom ups cache commit b7f6581901ebad96c87e765a305a1fa5b336efbb Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Nov 10 14:29:47 2023 +0200 all: conf custom ups cache commit d07df945d4e7614a679ef5dc77756096abf1e66c Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Nov 10 09:26:29 2023 +0200 all: docs commit 998124bac08889c7d354dd1a099929726725bccc Merge: f665e2f85 53170d871 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Nov 10 09:24:28 2023 +0200 Merge remote-tracking branch 'origin/master' into custom-ups-cache commit f665e2f85bce12d95f80aba6614b6bfd4874b122 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Nov 10 09:22:46 2023 +0200 all: conf custom ups cache commit a4b26973bef4f3b339198ffbe52a50baca303daf Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Nov 9 12:46:39 2023 +0200 all: conf custom ups cache
2023-11-17 15:51:51 +03:00
upsConf, err := clients.UpstreamConfigByID("1.2.3.4", net.DefaultResolver)
assert.Nil(t, upsConf)
assert.NoError(t, err)
Pull request: custom upstreams cache Merge in DNS/adguard-home from custom-ups-cache to master Squashed commit of the following: commit 98428a87520f70cb522701d8eccfe4c529be1e40 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Nov 17 10:53:32 2023 +0200 all: upd dep commit 775a639af4a2a45220b17e8b0037edc126ff62e4 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Nov 17 09:52:31 2023 +0200 dnsforward: imp test commit e9e2a58b48e8588dfcb28df319d4651e1fe77af5 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Nov 17 09:44:46 2023 +0200 docs: changelog commit a6d67218f037c8fec29e5fa2967476d63c3cfc32 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Nov 17 09:37:17 2023 +0200 all: upd dep commit b101ff6e0cf393dacdee6fb68d33ba8f11c36280 Merge: d61f4eb88 8bb1aad73 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Nov 16 15:54:05 2023 +0200 Merge remote-tracking branch 'origin/master' into custom-ups-cache commit d61f4eb8871f8ae8504259998bf9015b29001cfb Merge: 567a8a4af fdf60eeed Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Nov 13 10:32:22 2023 +0200 Merge remote-tracking branch 'origin/master' into custom-ups-cache commit 567a8a4af34ad001d0e6d7d2efdc123205569e8c Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Nov 13 10:30:24 2023 +0200 home: imp code commit a3c16facbebc166e5c0c731c1e892b61c0950d9e Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Nov 10 14:34:04 2023 +0200 all: imp code commit 84160eafee1d0f2d0cd3f025f2d5070e4f597ad6 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Nov 10 14:31:26 2023 +0200 all: conf custom ups cache commit b7f6581901ebad96c87e765a305a1fa5b336efbb Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Nov 10 14:29:47 2023 +0200 all: conf custom ups cache commit d07df945d4e7614a679ef5dc77756096abf1e66c Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Nov 10 09:26:29 2023 +0200 all: docs commit 998124bac08889c7d354dd1a099929726725bccc Merge: f665e2f85 53170d871 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Nov 10 09:24:28 2023 +0200 Merge remote-tracking branch 'origin/master' into custom-ups-cache commit f665e2f85bce12d95f80aba6614b6bfd4874b122 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Nov 10 09:22:46 2023 +0200 all: conf custom ups cache commit a4b26973bef4f3b339198ffbe52a50baca303daf Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Nov 9 12:46:39 2023 +0200 all: conf custom ups cache
2023-11-17 15:51:51 +03:00
upsConf, err = clients.UpstreamConfigByID("1.1.1.1", net.DefaultResolver)
require.NotNil(t, upsConf)
assert.NoError(t, err)
}