forked from AdguardTeam/AdGuardHome
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pull request 2096: 4923 gopacket dhcp vol.5
Updates AdguardTeam#4923. Squashed commit of the following: commit 762a3f9 Merge: 2af65b4 34a34dc 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 2af65b4 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Dec 8 16:22:51 2023 +0300 dhcpsvc: imp code commit 71233b9 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Dec 8 15:26:25 2023 +0300 dhcpsvc: imp docs commit 2949544 Merge: 593e9ed 214175e 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 593e9ed Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Dec 7 16:45:10 2023 +0300 dhcpsvc: imp docs commit cdb1915 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Dec 7 16:33:56 2023 +0300 dhcpsvc: imp code commit a0c423c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Dec 5 20:56:43 2023 +0300 dnspsvc: add opts commit 050ab7f Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Dec 5 20:17:37 2023 +0300 WIP
- Loading branch information
1 parent
34a34dc
commit 79d7a1e
Showing
3 changed files
with
349 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
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) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.