Skip to content

Commit

Permalink
hidden path segment extension
Browse files Browse the repository at this point in the history
error messages


remove hidden path extension


t
  • Loading branch information
Claude Hähni committed Aug 27, 2019
1 parent a178cff commit f3a3ad7
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 62 deletions.
4 changes: 2 additions & 2 deletions go/lib/layers/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ go_test(
],
embed = [":go_default_library"],
deps = [
"//go/lib/xtest:go_default_library",
"@com_github_google_gopacket//:go_default_library",
"@com_github_google_gopacket//layers:go_default_library",
"@com_github_smartystreets_goconvey//convey:go_default_library",
"@com_github_stretchr_testify//assert:go_default_library",
"@com_github_stretchr_testify//require:go_default_library",
],
)
4 changes: 2 additions & 2 deletions go/lib/layers/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ func NewExtnOHPFromLayer(extension *Extension) (*ExtnOHP, error) {
}

func (o *ExtnOHP) DecodeFromLayer(extension *Extension) error {
if len(extension.Data) != common.LineLen-3 {
if len(extension.Data) != common.ExtnFirstLineLen {
return common.NewBasicError("bad length for OHP extension", nil,
"actual", len(extension.Data), "want", common.LineLen-3)
"actual", len(extension.Data), "want", common.ExtnFirstLineLen)
}
return nil
}
Expand Down
54 changes: 29 additions & 25 deletions go/lib/layers/extensions_layer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ import (

"github.com/google/gopacket"
"github.com/google/gopacket/layers"
. "github.com/smartystreets/goconvey/convey"

"github.com/scionproto/scion/go/lib/xtest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestExtensionDecodeFromBytes(t *testing.T) {
Expand Down Expand Up @@ -71,16 +70,18 @@ func TestExtensionDecodeFromBytes(t *testing.T) {
},
},
}
Convey("", t, func() {
for _, tc := range testCases {
Convey(tc.Description, func() {
var extn Extension
err := extn.DecodeFromBytes(tc.Data, gopacket.NilDecodeFeedback)
xtest.SoMsgError("err", err, tc.ExpectedError)
SoMsg("extension", extn, ShouldResemble, tc.ExpectedExtension)
})
}
})
for _, tc := range testCases {
t.Run(tc.Description, func(t *testing.T) {
var extn Extension
err := extn.DecodeFromBytes(tc.Data, gopacket.NilDecodeFeedback)
if tc.ExpectedError {
assert.Error(t, err)
} else {
require.NoError(t, err)
assert.Equal(t, tc.ExpectedExtension, extn, "extension must matches")
}
})
}
}

func TestExtensionSerializeTo(t *testing.T) {
Expand All @@ -91,7 +92,7 @@ func TestExtensionSerializeTo(t *testing.T) {

ExpectedError bool
ExpectedBytes []byte
ExpectedLength int
ExpectedLength uint8
}
testCases := []*TestCase{
{
Expand Down Expand Up @@ -159,15 +160,18 @@ func TestExtensionSerializeTo(t *testing.T) {
ExpectedLength: 1,
},
}
Convey("", t, func() {
for _, tc := range testCases {
Convey(tc.Description, func() {
b := gopacket.NewSerializeBuffer()
err := tc.Extension.SerializeTo(b, tc.SerializeOptions)
xtest.SoMsgError("err", err, tc.ExpectedError)
SoMsg("b", b.Bytes(), ShouldResemble, tc.ExpectedBytes)
SoMsg("updated length field", tc.Extension.NumLines, ShouldEqual, tc.ExpectedLength)
})
}
})
for _, tc := range testCases {
t.Run(tc.Description, func(t *testing.T) {
b := gopacket.NewSerializeBuffer()
err := tc.Extension.SerializeTo(b, tc.SerializeOptions)
if tc.ExpectedError {
assert.Error(t, err)
} else {
require.NoError(t, err)
assert.Equal(t, tc.ExpectedBytes, b.Bytes(), "buffer must match")
assert.Equal(t, tc.ExpectedLength, tc.Extension.NumLines,
"updated length field must match")
}
})
}
}
70 changes: 37 additions & 33 deletions go/lib/layers/extensions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@ import (
"testing"

"github.com/google/gopacket"
. "github.com/smartystreets/goconvey/convey"

"github.com/scionproto/scion/go/lib/xtest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestExtnOHPDecodeFromLayer(t *testing.T) {
type TestCase struct {
Description string
Extension *Extension
Bytes []byte
ExpectedError bool
}
testCases := []*TestCase{
Expand All @@ -42,15 +40,17 @@ func TestExtnOHPDecodeFromLayer(t *testing.T) {
Extension: mustCreateExtensionLayer([]byte{0, 1, 0, 0, 0, 0, 0, 0}),
},
}
Convey("", t, func() {
for _, tc := range testCases {
Convey(tc.Description, func() {
var extn ExtnOHP
err := extn.DecodeFromLayer(tc.Extension)
xtest.SoMsgError("err", err, tc.ExpectedError)
})
}
})
for _, tc := range testCases {
t.Run(tc.Description, func(t *testing.T) {
var extn ExtnOHP
err := extn.DecodeFromLayer(tc.Extension)
if tc.ExpectedError {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
})
}
}

func TestExtnSCMPDecodeFromLayer(t *testing.T) {
Expand All @@ -77,16 +77,18 @@ func TestExtnSCMPDecodeFromLayer(t *testing.T) {
ExpectedExtension: ExtnSCMP{Error: true, HopByHop: true},
},
}
Convey("", t, func() {
for _, tc := range testCases {
Convey(tc.Description, func() {
var extn ExtnSCMP
err := extn.DecodeFromLayer(tc.Extension)
xtest.SoMsgError("err", err, tc.ExpectedError)
SoMsg("extension", extn, ShouldResemble, tc.ExpectedExtension)
})
}
})
for _, tc := range testCases {
t.Run(tc.Description, func(t *testing.T) {
var extn ExtnSCMP
err := extn.DecodeFromLayer(tc.Extension)
if tc.ExpectedError {
assert.Error(t, err)
} else {
require.NoError(t, err)
assert.Equal(t, tc.ExpectedExtension, extn, "extension must match")
}
})
}
}

func TestExtnUnkownDecodeFromLayer(t *testing.T) {
Expand All @@ -106,16 +108,18 @@ func TestExtnUnkownDecodeFromLayer(t *testing.T) {
ExpectedExtension: ExtnUnknown{Length: 13, TypeField: 3},
},
}
Convey("", t, func() {
for _, tc := range testCases {
Convey(tc.Description, func() {
var extn ExtnUnknown
err := extn.DecodeFromLayer(tc.Extension)
xtest.SoMsgError("err", err, tc.ExpectedError)
SoMsg("extension", extn, ShouldResemble, tc.ExpectedExtension)
})
}
})
for _, tc := range testCases {
t.Run(tc.Description, func(t *testing.T) {
var extn ExtnUnknown
err := extn.DecodeFromLayer(tc.Extension)
if tc.ExpectedError {
assert.Error(t, err)
} else {
require.NoError(t, err)
assert.Equal(t, tc.ExpectedExtension, extn, "extension must match")
}
})
}
}

func mustCreateExtensionLayer(b []byte) *Extension {
Expand Down

0 comments on commit f3a3ad7

Please sign in to comment.