Skip to content

Commit

Permalink
[FAB-13251] Add nil check in ToGossipMessage
Browse files Browse the repository at this point in the history
Change-Id: I4b7dac64775107d88b0807a4e5f058222e6b8d2f
Signed-off-by: yacovm <yacovm@il.ibm.com>
  • Loading branch information
yacovm committed Dec 12, 2018
1 parent 681dcfc commit a00a80b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions protos/gossip/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,9 @@ func (m *SignedGossipMessage) IsSigned() bool {
// SignedGossipMessage out of it.
// Returns an error if un-marshaling fails.
func (e *Envelope) ToGossipMessage() (*SignedGossipMessage, error) {
if e == nil {
return nil, errors.New("nil envelope")
}
msg := &GossipMessage{}
err := proto.Unmarshal(e.Payload, msg)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions protos/gossip/extensions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ import (
"github.com/stretchr/testify/assert"
)

func TestToGossipMessageNilEnvelope(t *testing.T) {
memReq := &MembershipRequest{}
_, err := memReq.SelfInformation.ToGossipMessage()
assert.EqualError(t, err, "nil envelope")
}

func TestToString(t *testing.T) {
// Ensure we don't print the byte content when we
// log messages.
Expand Down

0 comments on commit a00a80b

Please sign in to comment.