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