mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-22 21:15:35 +03:00
79d7a1ef46
Updates #4923. Squashed commit of the following: commit 762a3f9b7d7d4dd8799e8bf4df632b8d50321bf8 Merge: 2af65b42a34a34dc05
Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Dec 12 11:13:21 2023 +0300 Merge branch 'master' into 4923-gopacket-dhcp-vol.5 commit 2af65b42a62b92ec5bc28ef81eb6f08d0f9f443e Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Dec 8 16:22:51 2023 +0300 dhcpsvc: imp code commit 71233b9952b0d74e7e890d6755652877bc4c543b Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Dec 8 15:26:25 2023 +0300 dhcpsvc: imp docs commit 2949544f32b52d592f76e53062cf017e08073d29 Merge: 593e9edaa214175eb4
Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Dec 7 16:48:18 2023 +0300 Merge branch 'master' into 4923-gopacket-dhcp-vol.5 commit 593e9edaa9e776db35b3bedfa942c015d7b1e4af Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Dec 7 16:45:10 2023 +0300 dhcpsvc: imp docs commit cdb1915c7db3bf36800b40bc6aedc0e20f55f899 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Dec 7 16:33:56 2023 +0300 dhcpsvc: imp code commit a0c423c2b39d674debf4c0fedf6208f656be861a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Dec 5 20:56:43 2023 +0300 dnspsvc: add opts commit 050ab7f9410c206287c66376e21d36af8a3da384 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Dec 5 20:17:37 2023 +0300 WIP
88 lines
2.2 KiB
Go
88 lines
2.2 KiB
Go
package dhcpsvc
|
|
|
|
import (
|
|
"net/netip"
|
|
"testing"
|
|
|
|
"github.com/google/gopacket/layers"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestIPv4Config_Options(t *testing.T) {
|
|
oneIP, otherIP := netip.MustParseAddr("1.2.3.4"), netip.MustParseAddr("5.6.7.8")
|
|
subnetMask := netip.MustParseAddr("255.255.0.0")
|
|
|
|
opt1 := layers.NewDHCPOption(layers.DHCPOptSubnetMask, subnetMask.AsSlice())
|
|
opt6 := layers.NewDHCPOption(layers.DHCPOptDNS, append(oneIP.AsSlice(), otherIP.AsSlice()...))
|
|
opt28 := layers.NewDHCPOption(layers.DHCPOptBroadcastAddr, oneIP.AsSlice())
|
|
opt121 := layers.NewDHCPOption(layers.DHCPOptClasslessStaticRoute, []byte("cba"))
|
|
|
|
testCases := []struct {
|
|
name string
|
|
conf *IPv4Config
|
|
wantExplicit layers.DHCPOptions
|
|
}{{
|
|
name: "all_default",
|
|
conf: &IPv4Config{
|
|
Options: nil,
|
|
},
|
|
wantExplicit: nil,
|
|
}, {
|
|
name: "configured_ip",
|
|
conf: &IPv4Config{
|
|
Options: layers.DHCPOptions{opt28},
|
|
},
|
|
wantExplicit: layers.DHCPOptions{opt28},
|
|
}, {
|
|
name: "configured_ips",
|
|
conf: &IPv4Config{
|
|
Options: layers.DHCPOptions{opt6},
|
|
},
|
|
wantExplicit: layers.DHCPOptions{opt6},
|
|
}, {
|
|
name: "configured_del",
|
|
conf: &IPv4Config{
|
|
Options: layers.DHCPOptions{
|
|
layers.NewDHCPOption(layers.DHCPOptBroadcastAddr, nil),
|
|
},
|
|
},
|
|
wantExplicit: nil,
|
|
}, {
|
|
name: "rewritten_del",
|
|
conf: &IPv4Config{
|
|
Options: layers.DHCPOptions{
|
|
layers.NewDHCPOption(layers.DHCPOptBroadcastAddr, nil),
|
|
opt28,
|
|
},
|
|
},
|
|
wantExplicit: layers.DHCPOptions{opt28},
|
|
}, {
|
|
name: "configured_and_del",
|
|
conf: &IPv4Config{
|
|
Options: layers.DHCPOptions{
|
|
layers.NewDHCPOption(layers.DHCPOptClasslessStaticRoute, []byte("a")),
|
|
layers.NewDHCPOption(layers.DHCPOptClasslessStaticRoute, nil),
|
|
opt121,
|
|
},
|
|
},
|
|
wantExplicit: layers.DHCPOptions{opt121},
|
|
}, {
|
|
name: "replace_config_value",
|
|
conf: &IPv4Config{
|
|
SubnetMask: netip.MustParseAddr("255.255.255.0"),
|
|
Options: layers.DHCPOptions{opt1},
|
|
},
|
|
wantExplicit: layers.DHCPOptions{opt1},
|
|
}}
|
|
|
|
for _, tc := range testCases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
imp, exp := tc.conf.options()
|
|
assert.Equal(t, tc.wantExplicit, exp)
|
|
|
|
for c := range exp {
|
|
assert.NotContains(t, imp, c)
|
|
}
|
|
})
|
|
}
|
|
}
|