From d1b2960b7b2d4d43374def6488faf96b7d4cb5dc Mon Sep 17 00:00:00 2001 From: Pablo Mazzini Date: Sun, 11 Nov 2018 20:49:42 +0000 Subject: add OptRelayAgentInformation --- dhcpv4/option_relay_agent_information.go | 74 +++++++++++++++++++++++++++ dhcpv4/option_relay_agent_information_test.go | 41 +++++++++++++++ dhcpv4/options.go | 21 ++++++-- 3 files changed, 131 insertions(+), 5 deletions(-) create mode 100644 dhcpv4/option_relay_agent_information.go create mode 100644 dhcpv4/option_relay_agent_information_test.go diff --git a/dhcpv4/option_relay_agent_information.go b/dhcpv4/option_relay_agent_information.go new file mode 100644 index 0000000..844c4bc --- /dev/null +++ b/dhcpv4/option_relay_agent_information.go @@ -0,0 +1,74 @@ +package dhcpv4 + +import "fmt" + +// This option implements the relay agent information option +// https://tools.ietf.org/html/rfc3046 + +// OptRelayAgentInformation is a "container" option for specific agent-supplied +// sub-options. +type OptRelayAgentInformation struct { + Options []Option +} + +// Parse returns a new OptRelayAgentInformation from a byte stream, or error if +// any. +func ParseOptRelayAgentInformation(data []byte) (*OptRelayAgentInformation, error) { + if len(data) < 4 { + return nil, ErrShortByteStream + } + code := OptionCode(data[0]) + if code != OptionRelayAgentInformation { + return nil, fmt.Errorf("expected code %v, got %v", OptionRelayAgentInformation, code) + } + length := int(data[1]) + if len(data) < 2+length { + return nil, ErrShortByteStream + } + options, err := OptionsFromBytesWithParser(data[2:length+2], relayParseOption) + if err != nil { + return nil, err + } + return &OptRelayAgentInformation{Options: options}, nil +} + +func relayParseOption(data []byte) (Option, error) { + if len(data) < 2 { + return nil, ErrShortByteStream + } + code := OptionCode(data[0]) + length := int(data[1]) + if len(data) < 2+length { + return nil, ErrShortByteStream + } + return &OptionGeneric{OptionCode: code, Data: data[2:length+2]}, nil +} + +// Code returns the option code. +func (o *OptRelayAgentInformation) Code() OptionCode { + return OptionRelayAgentInformation +} + +// ToBytes returns a serialized stream of bytes for this option. +func (o *OptRelayAgentInformation) ToBytes() []byte { + ret := []byte{byte(o.Code()), byte(o.Length())} + for _, opt := range o.Options { + ret = append(ret, opt.ToBytes()...) + } + return ret +} + +// String returns a human-readable string for this option. +func (o *OptRelayAgentInformation) String() string { + return fmt.Sprintf("Relay Agent Information -> [%v]", o.Options) +} + +// Length returns the length of the data portion (excluding option code and byte +// for length, if any). +func (o *OptRelayAgentInformation) Length() int { + l := 0 + for _, opt := range o.Options { + l += 2 + opt.Length() + } + return l +} diff --git a/dhcpv4/option_relay_agent_information_test.go b/dhcpv4/option_relay_agent_information_test.go new file mode 100644 index 0000000..e3310e9 --- /dev/null +++ b/dhcpv4/option_relay_agent_information_test.go @@ -0,0 +1,41 @@ +package dhcpv4 + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestParseOptRelayAgentInformation(t *testing.T) { + data := []byte{ + byte(OptionRelayAgentInformation), + 13, + 1, 5, 'l', 'i', 'n', 'u', 'x', + 2, 4, 'b', 'o', 'o', 't', + } + opt, err := ParseOptRelayAgentInformation(data) + require.NoError(t, err) + + circuit, ok := opt.Options[0].(*OptionGeneric) + require.True(t, ok) + remote, ok := opt.Options[1].(*OptionGeneric) + require.True(t, ok) + require.Equal(t, circuit.Data, []byte("linux")) + require.Equal(t, remote.Data, []byte("boot")) +} + +func TestParseOptRelayAgentInformationToBytes(t *testing.T) { + opt := OptRelayAgentInformation{} + opt1 := &OptionGeneric{OptionCode: 1, Data: []byte("linux")} + opt.Options = append(opt.Options, opt1) + opt2 := &OptionGeneric{OptionCode: 2, Data: []byte("boot")} + opt.Options = append(opt.Options, opt2) + data := opt.ToBytes() + expected := []byte{ + byte(OptionRelayAgentInformation), + 13, + 1, 5, 'l', 'i', 'n', 'u', 'x', + 2, 4, 'b', 'o', 'o', 't', + } + require.Equal(t, expected, data) +} diff --git a/dhcpv4/options.go b/dhcpv4/options.go index 6256ef7..b117728 100644 --- a/dhcpv4/options.go +++ b/dhcpv4/options.go @@ -50,6 +50,8 @@ func ParseOption(data []byte) (Option, error) { opt, err = ParseOptHostName(data) case OptionDomainName: opt, err = ParseOptDomainName(data) + case OptionRootPath: + opt, err = ParseOptRootPath(data) case OptionBroadcastAddress: opt, err = ParseOptBroadcastAddress(data) case OptionNTPServers: @@ -74,14 +76,14 @@ func ParseOption(data []byte) (Option, error) { opt, err = ParseOptBootfileName(data) case OptionUserClassInformation: opt, err = ParseOptUserClass(data) + case OptionRelayAgentInformation: + opt, err = ParseOptRelayAgentInformation(data) case OptionClientSystemArchitectureType: opt, err = ParseOptClientArchType(data) - case OptionVendorIdentifyingVendorClass: - opt, err = ParseOptVIVC(data) case OptionDNSDomainSearchList: opt, err = ParseOptDomainSearch(data) - case OptionRootPath: - opt, err = ParseOptRootPath(data) + case OptionVendorIdentifyingVendorClass: + opt, err = ParseOptVIVC(data) default: opt, err = ParseOptionGeneric(data) } @@ -112,6 +114,15 @@ func OptionsFromBytes(data []byte) ([]Option, error) { // and builds a list of options from it. The sequence should not contain the // DHCP magic cookie. Returns an error if any invalid option or length is found. func OptionsFromBytesWithoutMagicCookie(data []byte) ([]Option, error) { + return OptionsFromBytesWithParser(data, ParseOption) +} + +// OptionParser is a function signature for option parsing +type OptionParser func(data []byte) (Option, error) + +// OptionsFromBytesWithParser parses Options from byte sequences using the +// parsing function that is passed in as a paremeter +func OptionsFromBytesWithParser(data []byte, parser OptionParser) ([]Option, error) { options := make([]Option, 0, 10) idx := 0 for { @@ -122,7 +133,7 @@ func OptionsFromBytesWithoutMagicCookie(data []byte) ([]Option, error) { if idx > len(data) { return nil, errors.New("read past the end of options") } - opt, err := ParseOption(data[idx:]) + opt, err := parser(data[idx:]) idx++ if err != nil { return nil, err -- cgit v1.2.3 From 190b8db21355bbb3d28f875ba2063143bd51f27c Mon Sep 17 00:00:00 2001 From: Pablo Mazzini Date: Sun, 11 Nov 2018 20:55:54 +0000 Subject: OptRelayAgentInformation: fix comment --- dhcpv4/option_relay_agent_information.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dhcpv4/option_relay_agent_information.go b/dhcpv4/option_relay_agent_information.go index 844c4bc..75bbef0 100644 --- a/dhcpv4/option_relay_agent_information.go +++ b/dhcpv4/option_relay_agent_information.go @@ -11,8 +11,8 @@ type OptRelayAgentInformation struct { Options []Option } -// Parse returns a new OptRelayAgentInformation from a byte stream, or error if -// any. +// ParseOptRelayAgentInformation returns a new OptRelayAgentInformation from a +// byte stream, or error if any. func ParseOptRelayAgentInformation(data []byte) (*OptRelayAgentInformation, error) { if len(data) < 4 { return nil, ErrShortByteStream -- cgit v1.2.3 From cb41e074afe04510b3951f9c9a39cc848a0d3fde Mon Sep 17 00:00:00 2001 From: Pablo Mazzini Date: Sun, 11 Nov 2018 21:05:24 +0000 Subject: OptRelayAgentInformation: increase coverage --- dhcpv4/option_relay_agent_information_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dhcpv4/option_relay_agent_information_test.go b/dhcpv4/option_relay_agent_information_test.go index e3310e9..68b5c73 100644 --- a/dhcpv4/option_relay_agent_information_test.go +++ b/dhcpv4/option_relay_agent_information_test.go @@ -15,7 +15,7 @@ func TestParseOptRelayAgentInformation(t *testing.T) { } opt, err := ParseOptRelayAgentInformation(data) require.NoError(t, err) - + require.Equal(t, len(opt.Options), 2) circuit, ok := opt.Options[0].(*OptionGeneric) require.True(t, ok) remote, ok := opt.Options[1].(*OptionGeneric) -- cgit v1.2.3 From 0bdc80968e801d1b72062d3481129c84f3788627 Mon Sep 17 00:00:00 2001 From: Pablo Mazzini Date: Sun, 11 Nov 2018 21:18:22 +0000 Subject: OptRelayAgentInformation: increase coverage --- dhcpv4/options_test.go | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/dhcpv4/options_test.go b/dhcpv4/options_test.go index c06f6f5..258fcfd 100644 --- a/dhcpv4/options_test.go +++ b/dhcpv4/options_test.go @@ -7,19 +7,9 @@ import ( ) func TestParseOption(t *testing.T) { - // Generic - option := []byte{5, 4, 192, 168, 1, 254} // DNS option - opt, err := ParseOption(option) - require.NoError(t, err) - generic := opt.(*OptionGeneric) - require.Equal(t, OptionNameServer, generic.Code()) - require.Equal(t, []byte{192, 168, 1, 254}, generic.Data) - require.Equal(t, 4, generic.Length()) - require.Equal(t, "Name Server -> [192 168 1 254]", generic.String()) - // Option subnet mask - option = []byte{1, 4, 255, 255, 255, 0} - opt, err = ParseOption(option) + option := []byte{1, 4, 255, 255, 255, 0} + opt, err := ParseOption(option) require.NoError(t, err) require.Equal(t, OptionSubnetMask, opt.Code(), "Code") require.Equal(t, 4, opt.Length(), "Length") @@ -57,6 +47,22 @@ func TestParseOption(t *testing.T) { require.Equal(t, 4, opt.Length(), "Length") require.Equal(t, option, opt.ToBytes(), "ToBytes") + // Option root path + option = []byte{17, 4, '/', 'f', 'o', 'o'} + opt, err = ParseOption(option) + require.NoError(t, err) + require.Equal(t, OptionRootPath, opt.Code(), "Code") + require.Equal(t, 4, opt.Length(), "Length") + require.Equal(t, option, opt.ToBytes(), "ToBytes") + + // Option broadcast address + option = []byte{28, 4, 255, 255, 255, 255} + opt, err = ParseOption(option) + require.NoError(t, err) + require.Equal(t, OptionBroadcastAddress, opt.Code(), "Code") + require.Equal(t, 4, opt.Length(), "Length") + require.Equal(t, option, opt.ToBytes(), "ToBytes") + // Option NTP servers option = []byte{42, 4, 10, 10, 10, 10} opt, err = ParseOption(option) @@ -145,12 +151,15 @@ func TestParseOption(t *testing.T) { require.Equal(t, 4, opt.Length(), "Length") require.Equal(t, option, opt.ToBytes(), "ToBytes") - option = []byte{17, 4, '/', 'f', 'o', 'o'} + // Generic + option = []byte{5, 4, 192, 168, 1, 254} // DNS option opt, err = ParseOption(option) require.NoError(t, err) - require.Equal(t, OptionRootPath, opt.Code(), "Code") - require.Equal(t, 4, opt.Length(), "Length") - require.Equal(t, option, opt.ToBytes(), "ToBytes") + generic := opt.(*OptionGeneric) + require.Equal(t, OptionNameServer, generic.Code()) + require.Equal(t, []byte{192, 168, 1, 254}, generic.Data) + require.Equal(t, 4, generic.Length()) + require.Equal(t, "Name Server -> [192 168 1 254]", generic.String()) } func TestParseOptionZeroLength(t *testing.T) { -- cgit v1.2.3 From 1d591269d345af65c9f1c2c3a9d6b1c8ea327cb2 Mon Sep 17 00:00:00 2001 From: Pablo Mazzini Date: Sun, 11 Nov 2018 21:28:37 +0000 Subject: OptRelayAgentInformation: increase coverage --- dhcpv4/options_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dhcpv4/options_test.go b/dhcpv4/options_test.go index 258fcfd..a4bf6d7 100644 --- a/dhcpv4/options_test.go +++ b/dhcpv4/options_test.go @@ -79,6 +79,14 @@ func TestParseOption(t *testing.T) { require.Equal(t, 4, opt.Length(), "Length") require.Equal(t, option, opt.ToBytes(), "ToBytes") + // Requested IP address lease time + option = []byte{51, 4, 0, 0, 0, 0} + opt, err = ParseOption(option) + require.NoError(t, err) + require.Equal(t, OptionIPAddressLeaseTime, opt.Code(), "Code") + require.Equal(t, 4, opt.Length(), "Length") + require.Equal(t, option, opt.ToBytes(), "ToBytes") + // Message type option = []byte{53, 1, 1} opt, err = ParseOption(option) -- cgit v1.2.3 From 060633e1afd24f6c69dccf9ee99b85dddbdee651 Mon Sep 17 00:00:00 2001 From: Pablo Mazzini Date: Sun, 11 Nov 2018 22:15:57 +0000 Subject: OptRelayAgentInformation: increase coverage --- dhcpv4/options.go | 2 +- dhcpv4/options_test.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/dhcpv4/options.go b/dhcpv4/options.go index b117728..dc4a724 100644 --- a/dhcpv4/options.go +++ b/dhcpv4/options.go @@ -145,7 +145,7 @@ func OptionsFromBytesWithParser(data []byte, parser OptionParser) ([]Option, err // Options with zero length have no length byte, so here we handle the // ones with nonzero length - if opt.Length() > 0 { + if opt.Code() != OptionPad { idx++ } idx += opt.Length() diff --git a/dhcpv4/options_test.go b/dhcpv4/options_test.go index a4bf6d7..3c1de67 100644 --- a/dhcpv4/options_test.go +++ b/dhcpv4/options_test.go @@ -151,6 +151,14 @@ func TestParseOption(t *testing.T) { require.Equal(t, 5, opt.Length(), "Length") require.Equal(t, option, opt.ToBytes(), "ToBytes") + // Option relay agent information + option = []byte{82, 2, 1, 0} + opt, err = ParseOption(option) + require.NoError(t, err) + require.Equal(t, OptionRelayAgentInformation, opt.Code(), "Code") + require.Equal(t, 2, opt.Length(), "Length") + require.Equal(t, option, opt.ToBytes(), "ToBytes") + // Option client system architecture type option option = []byte{93, 4, 't', 'e', 's', 't'} opt, err = ParseOption(option) -- cgit v1.2.3 From 472ea5db936189a5cfb3d92847714f914a16ea1d Mon Sep 17 00:00:00 2001 From: Pablo Mazzini Date: Sun, 11 Nov 2018 22:28:05 +0000 Subject: OptRelayAgentInformation: increase coverage --- dhcpv4/option_relay_agent_information.go | 2 +- dhcpv4/option_relay_agent_information_test.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/dhcpv4/option_relay_agent_information.go b/dhcpv4/option_relay_agent_information.go index 75bbef0..447783e 100644 --- a/dhcpv4/option_relay_agent_information.go +++ b/dhcpv4/option_relay_agent_information.go @@ -60,7 +60,7 @@ func (o *OptRelayAgentInformation) ToBytes() []byte { // String returns a human-readable string for this option. func (o *OptRelayAgentInformation) String() string { - return fmt.Sprintf("Relay Agent Information -> [%v]", o.Options) + return fmt.Sprintf("Relay Agent Information -> %v", o.Options) } // Length returns the length of the data portion (excluding option code and byte diff --git a/dhcpv4/option_relay_agent_information_test.go b/dhcpv4/option_relay_agent_information_test.go index 68b5c73..2b7b7a3 100644 --- a/dhcpv4/option_relay_agent_information_test.go +++ b/dhcpv4/option_relay_agent_information_test.go @@ -39,3 +39,9 @@ func TestParseOptRelayAgentInformationToBytes(t *testing.T) { } require.Equal(t, expected, data) } + +func TestOptRelayAgentInformationToBytesString(t *testing.T) { + o := OptRelayAgentInformation{} + require.Equal(t, "Relay Agent Information -> []", o.String()) +} + -- cgit v1.2.3 From a71c47f36f5ebcd3397ff66991042e13c3d8b15e Mon Sep 17 00:00:00 2001 From: Pablo Mazzini Date: Sun, 11 Nov 2018 22:33:34 +0000 Subject: OptRelayAgentInformation: remove extra line --- dhcpv4/option_relay_agent_information_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/dhcpv4/option_relay_agent_information_test.go b/dhcpv4/option_relay_agent_information_test.go index 2b7b7a3..9e0bfde 100644 --- a/dhcpv4/option_relay_agent_information_test.go +++ b/dhcpv4/option_relay_agent_information_test.go @@ -44,4 +44,3 @@ func TestOptRelayAgentInformationToBytesString(t *testing.T) { o := OptRelayAgentInformation{} require.Equal(t, "Relay Agent Information -> []", o.String()) } - -- cgit v1.2.3 From 63b2012572c4572c2f992f6efc911cf105750f7e Mon Sep 17 00:00:00 2001 From: Pablo Mazzini Date: Sun, 11 Nov 2018 22:43:47 +0000 Subject: OptRelayAgentInformation: increase coverage --- dhcpv4/option_relay_agent_information_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dhcpv4/option_relay_agent_information_test.go b/dhcpv4/option_relay_agent_information_test.go index 9e0bfde..f4f46c9 100644 --- a/dhcpv4/option_relay_agent_information_test.go +++ b/dhcpv4/option_relay_agent_information_test.go @@ -13,7 +13,9 @@ func TestParseOptRelayAgentInformation(t *testing.T) { 1, 5, 'l', 'i', 'n', 'u', 'x', 2, 4, 'b', 'o', 'o', 't', } - opt, err := ParseOptRelayAgentInformation(data) + opt, err := ParseOptRelayAgentInformation([]byte("")) + require.Error(t, err) + opt, err = ParseOptRelayAgentInformation(data) require.NoError(t, err) require.Equal(t, len(opt.Options), 2) circuit, ok := opt.Options[0].(*OptionGeneric) -- cgit v1.2.3 From 44c5227b7ac262bcbd0aa050e1d3cbb1ba4bc74d Mon Sep 17 00:00:00 2001 From: Pablo Mazzini Date: Sun, 11 Nov 2018 22:48:58 +0000 Subject: OptRelayAgentInformation: increase coverage --- dhcpv4/options_test.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/dhcpv4/options_test.go b/dhcpv4/options_test.go index 3c1de67..bf869f2 100644 --- a/dhcpv4/options_test.go +++ b/dhcpv4/options_test.go @@ -7,10 +7,20 @@ import ( ) func TestParseOption(t *testing.T) { - // Option subnet mask - option := []byte{1, 4, 255, 255, 255, 0} + // Generic + option := []byte{5, 4, 192, 168, 1, 254} // DNS option opt, err := ParseOption(option) require.NoError(t, err) + generic := opt.(*OptionGeneric) + require.Equal(t, OptionNameServer, generic.Code()) + require.Equal(t, []byte{192, 168, 1, 254}, generic.Data) + require.Equal(t, 4, generic.Length()) + require.Equal(t, "Name Server -> [192 168 1 254]", generic.String()) + + // Option subnet mask + option = []byte{1, 4, 255, 255, 255, 0} + opt, err = ParseOption(option) + require.NoError(t, err) require.Equal(t, OptionSubnetMask, opt.Code(), "Code") require.Equal(t, 4, opt.Length(), "Length") require.Equal(t, option, opt.ToBytes(), "ToBytes") @@ -166,16 +176,6 @@ func TestParseOption(t *testing.T) { require.Equal(t, OptionClientSystemArchitectureType, opt.Code(), "Code") require.Equal(t, 4, opt.Length(), "Length") require.Equal(t, option, opt.ToBytes(), "ToBytes") - - // Generic - option = []byte{5, 4, 192, 168, 1, 254} // DNS option - opt, err = ParseOption(option) - require.NoError(t, err) - generic := opt.(*OptionGeneric) - require.Equal(t, OptionNameServer, generic.Code()) - require.Equal(t, []byte{192, 168, 1, 254}, generic.Data) - require.Equal(t, 4, generic.Length()) - require.Equal(t, "Name Server -> [192 168 1 254]", generic.String()) } func TestParseOptionZeroLength(t *testing.T) { -- cgit v1.2.3 From 8ea757126815ff6d795142d3b2e31bde47acd7fa Mon Sep 17 00:00:00 2001 From: Pablo Mazzini Date: Sun, 11 Nov 2018 23:01:36 +0000 Subject: OptRelayAgentInformation: increase coverage --- dhcpv4/option_relay_agent_information_test.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/dhcpv4/option_relay_agent_information_test.go b/dhcpv4/option_relay_agent_information_test.go index f4f46c9..a3eb3ef 100644 --- a/dhcpv4/option_relay_agent_information_test.go +++ b/dhcpv4/option_relay_agent_information_test.go @@ -13,8 +13,14 @@ func TestParseOptRelayAgentInformation(t *testing.T) { 1, 5, 'l', 'i', 'n', 'u', 'x', 2, 4, 'b', 'o', 'o', 't', } - opt, err := ParseOptRelayAgentInformation([]byte("")) + + // short bytes + opt, err := ParseOptRelayAgentInformation([]byte{}) require.Error(t, err) + + // wrong code + opt, err = ParseOptRelayAgentInformation([]byte{1, 2, 1, 0}) + opt, err = ParseOptRelayAgentInformation(data) require.NoError(t, err) require.Equal(t, len(opt.Options), 2) -- cgit v1.2.3 From 41291f85fc29a1d53e6e4d478e82fc1de39ee832 Mon Sep 17 00:00:00 2001 From: Pablo Mazzini Date: Mon, 12 Nov 2018 11:32:40 +0000 Subject: OptRelayAgentInformation: increase coverage --- dhcpv4/option_relay_agent_information_test.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/dhcpv4/option_relay_agent_information_test.go b/dhcpv4/option_relay_agent_information_test.go index a3eb3ef..28b4ca9 100644 --- a/dhcpv4/option_relay_agent_information_test.go +++ b/dhcpv4/option_relay_agent_information_test.go @@ -14,12 +14,21 @@ func TestParseOptRelayAgentInformation(t *testing.T) { 2, 4, 'b', 'o', 'o', 't', } - // short bytes + // short option bytes opt, err := ParseOptRelayAgentInformation([]byte{}) require.Error(t, err) // wrong code opt, err = ParseOptRelayAgentInformation([]byte{1, 2, 1, 0}) + require.Error(t, err) + + // wrong length + opt, err = ParseOptRelayAgentInformation([]byte{82, 3, 1, 0}) + require.Error(t, err) + + // short sub-option bytes + opt, err = ParseOptRelayAgentInformation([]byte{82, 2, 1}) + require.Error(t, err) opt, err = ParseOptRelayAgentInformation(data) require.NoError(t, err) -- cgit v1.2.3 From 42c46b5a6c407e515ca948fe5643e1258f80b280 Mon Sep 17 00:00:00 2001 From: Pablo Mazzini Date: Mon, 12 Nov 2018 12:49:34 +0000 Subject: OptRelayAgentInformation: increase coverage --- dhcpv4/option_relay_agent_information_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dhcpv4/option_relay_agent_information_test.go b/dhcpv4/option_relay_agent_information_test.go index 28b4ca9..3395271 100644 --- a/dhcpv4/option_relay_agent_information_test.go +++ b/dhcpv4/option_relay_agent_information_test.go @@ -14,7 +14,7 @@ func TestParseOptRelayAgentInformation(t *testing.T) { 2, 4, 'b', 'o', 'o', 't', } - // short option bytes + // short bytes opt, err := ParseOptRelayAgentInformation([]byte{}) require.Error(t, err) @@ -22,12 +22,12 @@ func TestParseOptRelayAgentInformation(t *testing.T) { opt, err = ParseOptRelayAgentInformation([]byte{1, 2, 1, 0}) require.Error(t, err) - // wrong length + // wrong option length opt, err = ParseOptRelayAgentInformation([]byte{82, 3, 1, 0}) require.Error(t, err) - // short sub-option bytes - opt, err = ParseOptRelayAgentInformation([]byte{82, 2, 1}) + // short sub-option length + opt, err = ParseOptRelayAgentInformation([]byte{82, 2, 2, 0}) require.Error(t, err) opt, err = ParseOptRelayAgentInformation(data) -- cgit v1.2.3 From 888609097f1aaea108ea2aebcb1d799688505944 Mon Sep 17 00:00:00 2001 From: Pablo Mazzini Date: Mon, 12 Nov 2018 12:54:26 +0000 Subject: OptRelayAgentInformation: increase coverage --- dhcpv4/option_relay_agent_information_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dhcpv4/option_relay_agent_information_test.go b/dhcpv4/option_relay_agent_information_test.go index 3395271..9146a24 100644 --- a/dhcpv4/option_relay_agent_information_test.go +++ b/dhcpv4/option_relay_agent_information_test.go @@ -27,7 +27,7 @@ func TestParseOptRelayAgentInformation(t *testing.T) { require.Error(t, err) // short sub-option length - opt, err = ParseOptRelayAgentInformation([]byte{82, 2, 2, 0}) + opt, err = ParseOptRelayAgentInformation([]byte{82, 2, 1, 1}) require.Error(t, err) opt, err = ParseOptRelayAgentInformation(data) -- cgit v1.2.3 From f5c1950747619f12256e39e69b9a2a9ec6168d04 Mon Sep 17 00:00:00 2001 From: Pablo Mazzini Date: Mon, 12 Nov 2018 13:08:18 +0000 Subject: OptRelayAgentInformation: increase coverage --- dhcpv4/option_relay_agent_information_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dhcpv4/option_relay_agent_information_test.go b/dhcpv4/option_relay_agent_information_test.go index 9146a24..88cb39a 100644 --- a/dhcpv4/option_relay_agent_information_test.go +++ b/dhcpv4/option_relay_agent_information_test.go @@ -14,7 +14,7 @@ func TestParseOptRelayAgentInformation(t *testing.T) { 2, 4, 'b', 'o', 'o', 't', } - // short bytes + // short option bytes opt, err := ParseOptRelayAgentInformation([]byte{}) require.Error(t, err) @@ -26,6 +26,10 @@ func TestParseOptRelayAgentInformation(t *testing.T) { opt, err = ParseOptRelayAgentInformation([]byte{82, 3, 1, 0}) require.Error(t, err) + // short sub-option bytes + opt, err = ParseOptRelayAgentInformation([]byte{82, 1, 1}) + require.Error(t, err) + // short sub-option length opt, err = ParseOptRelayAgentInformation([]byte{82, 2, 1, 1}) require.Error(t, err) -- cgit v1.2.3 From 5ee47520014b0835b58e3624381e01bdf14ef9ba Mon Sep 17 00:00:00 2001 From: Pablo Mazzini Date: Mon, 12 Nov 2018 13:37:38 +0000 Subject: OptRelayAgentInformation: increase coverage --- dhcpv4/option_relay_agent_information_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dhcpv4/option_relay_agent_information_test.go b/dhcpv4/option_relay_agent_information_test.go index 88cb39a..1e99206 100644 --- a/dhcpv4/option_relay_agent_information_test.go +++ b/dhcpv4/option_relay_agent_information_test.go @@ -27,7 +27,7 @@ func TestParseOptRelayAgentInformation(t *testing.T) { require.Error(t, err) // short sub-option bytes - opt, err = ParseOptRelayAgentInformation([]byte{82, 1, 1}) + opt, err = ParseOptRelayAgentInformation([]byte{82, 3, 1, 0, 1}) require.Error(t, err) // short sub-option length -- cgit v1.2.3