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_test.go | 41 +++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 dhcpv4/option_relay_agent_information_test.go (limited to 'dhcpv4/option_relay_agent_information_test.go') 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) +} -- 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(-) (limited to 'dhcpv4/option_relay_agent_information_test.go') 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 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(-) (limited to 'dhcpv4/option_relay_agent_information_test.go') 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(-) (limited to 'dhcpv4/option_relay_agent_information_test.go') 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(-) (limited to 'dhcpv4/option_relay_agent_information_test.go') 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 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(-) (limited to 'dhcpv4/option_relay_agent_information_test.go') 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(-) (limited to 'dhcpv4/option_relay_agent_information_test.go') 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(-) (limited to 'dhcpv4/option_relay_agent_information_test.go') 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(-) (limited to 'dhcpv4/option_relay_agent_information_test.go') 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(-) (limited to 'dhcpv4/option_relay_agent_information_test.go') 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(-) (limited to 'dhcpv4/option_relay_agent_information_test.go') 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