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-11-02 13:18:02 +00:00
|
|
|
"net/netip"
|
2019-09-18 16:44:27 +01:00
|
|
|
"testing"
|
2019-12-23 13:59:02 +00:00
|
|
|
|
2023-09-07 15:13:48 +01:00
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/client"
|
2023-04-12 12:48:42 +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-12 12:48:42 +01:00
|
|
|
// newClientsContainer is a helper that creates a new clients container for
|
|
|
|
// tests.
|
2023-07-03 12:10:40 +01:00
|
|
|
func newClientsContainer(t *testing.T) (c *clientsContainer) {
|
2023-09-07 15:13:48 +01:00
|
|
|
t.Helper()
|
|
|
|
|
2023-04-12 12:48:42 +01:00
|
|
|
c = &clientsContainer{
|
|
|
|
testing: true,
|
|
|
|
}
|
|
|
|
|
2024-09-30 18:17:20 +01:00
|
|
|
require.NoError(t, c.Init(nil, client.EmptyDHCP{}, nil, nil, &filtering.Config{}))
|
2019-04-26 13:10:29 +01:00
|
|
|
|
2023-04-12 12:48:42 +01:00
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2020-05-13 18:31:43 +01:00
|
|
|
func TestClientsCustomUpstream(t *testing.T) {
|
2023-07-03 12:10:40 +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-03 13:38:37 +01:00
|
|
|
err := clients.storage.Add(&client.Persistent{
|
2020-05-13 18:31:43 +01:00
|
|
|
Name: "client1",
|
2024-03-12 14:45:11 +00:00
|
|
|
UID: client.MustNewUID(),
|
2024-01-30 15:43:51 +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-12-07 14:23:00 +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-12-07 14:23:00 +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
|
|
|
}
|