mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-25 06:25:44 +03:00
332621f268
Squashed commit of the following: commit 425f1bd28074d22890629d06f43257e0353ce3d5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Feb 8 20:15:58 2024 +0300 all: upd deps, go, scripts
57 lines
969 B
Go
57 lines
969 B
Go
package dnsforward
|
|
|
|
import (
|
|
"slices"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestAnyNameMatches(t *testing.T) {
|
|
dnsNames := []string{"host1", "*.host2", "1.2.3.4"}
|
|
slices.Sort(dnsNames)
|
|
|
|
testCases := []struct {
|
|
name string
|
|
dnsName string
|
|
want bool
|
|
}{{
|
|
name: "match",
|
|
dnsName: "host1",
|
|
want: true,
|
|
}, {
|
|
name: "match",
|
|
dnsName: "a.host2",
|
|
want: true,
|
|
}, {
|
|
name: "match",
|
|
dnsName: "b.a.host2",
|
|
want: true,
|
|
}, {
|
|
name: "match",
|
|
dnsName: "1.2.3.4",
|
|
want: true,
|
|
}, {
|
|
name: "mismatch_bad_ip",
|
|
dnsName: "1.2.3.256",
|
|
want: false,
|
|
}, {
|
|
name: "mismatch",
|
|
dnsName: "host2",
|
|
want: false,
|
|
}, {
|
|
name: "mismatch",
|
|
dnsName: "",
|
|
want: false,
|
|
}, {
|
|
name: "mismatch",
|
|
dnsName: "*.host2",
|
|
want: false,
|
|
}}
|
|
|
|
for _, tc := range testCases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
assert.Equal(t, tc.want, anyNameMatches(dnsNames, tc.dnsName))
|
|
})
|
|
}
|
|
}
|