Skip to content

Commit

Permalink
CM-271 Enforce Value Size Limits for Update
Browse files Browse the repository at this point in the history
  • Loading branch information
rnistuk committed Mar 3, 2020
1 parent 100b5f1 commit babfb61
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions x/crud/internal/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,15 @@ func (msg MsgBLZUpdate) ValidateBasic() sdk.Error {
if msg.Owner.Empty() {
return sdk.ErrInvalidAddress(msg.Owner.String())
}

if len(msg.UUID) == 0 || len(msg.Key) == 0 {
return sdk.ErrInvalidPubKey("UUID or key Empty")
}

if len(msg.Value) > MaxValueSize {
return sdk.ErrInternal("Value too large")
}

return nil
}

Expand Down
7 changes: 6 additions & 1 deletion x/crud/internal/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestMsgBLZCreate_ValidateBasic(t *testing.T) {
sut.Key = "Key"
sut.UUID = "UUID"
sut.Value = string(make([]byte, MaxValueSize+1))
assert.Equal(t, sut.ValidateBasic(), sdk.ErrInternal("Value too large"))
assert.Equal(t, sdk.ErrInternal("Value too large"), sut.ValidateBasic())
}

func TestMsgBLZCreate_GetSignBytes(t *testing.T) {
Expand Down Expand Up @@ -160,6 +160,11 @@ func TestMsgBLZUpdate_ValidateBasic(t *testing.T) {
sut.UUID = "uuid"
sut.Key = ""
assert.Equal(t, sut.ValidateBasic(), sdk.ErrInvalidPubKey("UUID or key Empty"))

sut.Key = "Key"
sut.UUID = "UUID"
sut.Value = string(make([]byte, MaxValueSize+1))
assert.Equal(t, sdk.ErrInternal("Value too large"), sut.ValidateBasic())
}

func TestMsgBLZUpdate_GetSignBytes(t *testing.T) {
Expand Down

0 comments on commit babfb61

Please sign in to comment.