2019-06-10 09:33:19 +01:00
|
|
|
package home
|
2019-04-26 13:10:29 +01:00
|
|
|
|
2019-09-18 16:44:27 +01:00
|
|
|
import (
|
2019-12-23 13:59:02 +00:00
|
|
|
"net"
|
2022-10-14 13:29:44 +01:00
|
|
|
"net/netip"
|
2019-09-18 16:44:27 +01:00
|
|
|
"testing"
|
2019-12-23 13:59:02 +00:00
|
|
|
|
2023-09-01 13:24:44 +01:00
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/client"
|
2023-04-06 12:12:50 +01:00
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
2019-09-18 16:44:27 +01:00
|
|
|
"github.com/stretchr/testify/assert"
|
2021-03-11 14:32:58 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2019-09-18 16:44:27 +01:00
|
|
|
)
|
2019-04-26 13:10:29 +01:00
|
|
|
|
2023-04-06 12:12:50 +01:00
|
|
|
// newClientsContainer is a helper that creates a new clients container for
|
|
|
|
// tests.
|
2023-06-27 16:03:07 +01:00
|
|
|
func newClientsContainer(t *testing.T) (c *clientsContainer) {
|
2023-08-30 12:02:12 +01:00
|
|
|
t.Helper()
|
|
|
|
|
2023-04-06 12:12:50 +01:00
|
|
|
c = &clientsContainer{
|
|
|
|
testing: true,
|
|
|
|
}
|
|
|
|
|
2024-09-30 12:17:42 +01:00
|
|
|
require.NoError(t, c.Init(nil, client.EmptyDHCP{}, nil, nil, &filtering.Config{}))
|
2019-04-26 13:10:29 +01:00
|
|
|
|
2023-04-06 12:12:50 +01:00
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2020-05-13 18:31:43 +01:00
|
|
|
func TestClientsCustomUpstream(t *testing.T) {
|
2023-06-27 16:03:07 +01:00
|
|
|
clients := newClientsContainer(t)
|
2020-05-13 18:31:43 +01:00
|
|
|
|
2021-03-11 14:32:58 +00:00
|
|
|
// Add client with upstreams.
|
2024-07-01 15:34:47 +01:00
|
|
|
err := clients.storage.Add(&client.Persistent{
|
2020-05-13 18:31:43 +01:00
|
|
|
Name: "client1",
|
2024-02-27 10:48:11 +00:00
|
|
|
UID: client.MustNewUID(),
|
2024-01-17 10:24:21 +00:00
|
|
|
IPs: []netip.Addr{netip.MustParseAddr("1.1.1.1"), netip.MustParseAddr("1:2:3::4")},
|
2020-05-13 18:31:43 +01:00
|
|
|
Upstreams: []string{
|
|
|
|
"1.1.1.1",
|
|
|
|
"[/example.org/]8.8.8.8",
|
|
|
|
},
|
2021-03-11 14:32:58 +00:00
|
|
|
})
|
2021-05-28 11:02:59 +01:00
|
|
|
require.NoError(t, err)
|
2020-05-13 18:31:43 +01:00
|
|
|
|
2023-11-17 12:51:51 +00:00
|
|
|
upsConf, err := clients.UpstreamConfigByID("1.2.3.4", net.DefaultResolver)
|
|
|
|
assert.Nil(t, upsConf)
|
2021-05-28 11:02:59 +01:00
|
|
|
assert.NoError(t, err)
|
2020-05-13 18:31:43 +01:00
|
|
|
|
2023-11-17 12:51:51 +00:00
|
|
|
upsConf, err = clients.UpstreamConfigByID("1.1.1.1", net.DefaultResolver)
|
|
|
|
require.NotNil(t, upsConf)
|
2021-05-28 11:02:59 +01:00
|
|
|
assert.NoError(t, err)
|
2020-05-13 18:31:43 +01:00
|
|
|
}
|