Skip to content

Commit

Permalink
feat: check uri format on trigger service msg
Browse files Browse the repository at this point in the history
  • Loading branch information
amimart committed Apr 19, 2022
1 parent 57a54eb commit b9ae987
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions x/knowledge/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ import (
// x/knowledge module sentinel errors.
var (
ErrEntityAlreadyExists = sdkerrors.Register(ModuleName, 1100, "entity already exists")
ErrInvalidURI = sdkerrors.Register(ModuleName, 1101, "invalid uri")
)
6 changes: 6 additions & 0 deletions x/knowledge/types/message_trigger_service.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package types

import (
"net/url"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
Expand Down Expand Up @@ -42,5 +44,9 @@ func (msg *MsgTriggerService) ValidateBasic() error {
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
}

if _, err := url.Parse(msg.Uri); err != nil {
return sdkerrors.Wrapf(ErrInvalidURI, "invalid service uri (%s)", err)
}
return nil
}
14 changes: 14 additions & 0 deletions x/knowledge/types/message_trigger_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ func TestMsgTriggerService_ValidateBasic(t *testing.T) {
Creator: sample.AccAddress(),
},
},
{
name: "invalid uri",
msg: MsgTriggerService{
Creator: sample.AccAddress(),
Uri: "é:// ",
},
err: ErrInvalidURI,
}, {
name: "valid uri",
msg: MsgTriggerService{
Creator: sample.AccAddress(),
Uri: "okp4:service#coucou?target=okp4",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit b9ae987

Please sign in to comment.