diff options
author | Dennis Marttinen <twelho@welho.tech> | 2022-07-27 15:48:19 +0300 |
---|---|---|
committer | Dennis Marttinen <twelho@welho.tech> | 2022-07-27 15:54:50 +0300 |
commit | feb14de874aeca08e22d0d0a2f7859315646289d (patch) | |
tree | 6c9c9b26fc371db7cb6acaed1ab43e2d4c4e3740 | |
parent | aeb78d02bd032611653400cd55e3331a1f839aa9 (diff) |
dhcpv4: add unit tests for NewRenewFromOffer
Signed-off-by: Dennis Marttinen <twelho@welho.tech>
-rw-r--r-- | dhcpv4/dhcpv4_test.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/dhcpv4/dhcpv4_test.go b/dhcpv4/dhcpv4_test.go index 5d60b52..eff7a71 100644 --- a/dhcpv4/dhcpv4_test.go +++ b/dhcpv4/dhcpv4_test.go @@ -266,6 +266,43 @@ func TestDHCPv4NewRequestFromOfferWithModifier(t *testing.T) { require.Equal(t, MessageTypeRequest, req.MessageType()) } +func TestDHCPv4NewRenewFromOffer(t *testing.T) { + offer, err := New() + require.NoError(t, err) + offer.SetBroadcast() + offer.UpdateOption(OptMessageType(MessageTypeOffer)) + offer.UpdateOption(OptServerIdentifier(net.IPv4(192, 168, 0, 1))) + offer.UpdateOption(OptRequestedIPAddress(net.IPv4(192, 168, 0, 1))) + offer.YourIPAddr = net.IPv4(192, 168, 0, 1) + + // RFC 2131: RENEW-style requests will be unicast + var req *DHCPv4 + req, err = NewRenewFromOffer(offer) + require.NoError(t, err) + require.Equal(t, MessageTypeRequest, req.MessageType()) + require.Nil(t, req.GetOneOption(OptionServerIdentifier)) + require.Nil(t, req.GetOneOption(OptionRequestedIPAddress)) + require.Equal(t, offer.YourIPAddr, req.ClientIPAddr) + require.True(t, req.IsUnicast()) + require.False(t, req.IsBroadcast()) + // Renewals should behave identically to initial requests regarding requested options + require.True(t, req.IsOptionRequested(OptionRouter)) + require.True(t, req.IsOptionRequested(OptionSubnetMask)) + require.True(t, req.IsOptionRequested(OptionDomainName)) + require.True(t, req.IsOptionRequested(OptionDomainNameServer)) +} + +func TestDHCPv4NewRenewFromOfferWithModifier(t *testing.T) { + offer, err := New() + require.NoError(t, err) + offer.UpdateOption(OptMessageType(MessageTypeOffer)) + userClass := WithUserClass("linuxboot", false) + req, err := NewRenewFromOffer(offer, userClass) + require.NoError(t, err) + require.Equal(t, MessageTypeRequest, req.MessageType()) + require.Contains(t, req.UserClass(), "linuxboot") +} + func TestNewReplyFromRequest(t *testing.T) { discover, err := New() require.NoError(t, err) |