Skip to content

Commit

Permalink
imp: validate allowed forwarding hops
Browse files Browse the repository at this point in the history
  • Loading branch information
crodriguezvega committed Jun 27, 2024
1 parent 90d57db commit e310e27
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
8 changes: 8 additions & 0 deletions modules/apps/transfer/types/transfer_authorization.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ func (a TransferAuthorization) ValidateBasic() error {
}
found[allocation.AllowList[i]] = true
}

for i := 0; i < len(allocation.AllowedForwarding); i++ {
for _, hop := range allocation.AllowedForwarding[i].Hops {
if err := hop.Validate(); err != nil {
return errorsmod.Wrap(err, "invalid forwarding hop")
}
}
}
}

return nil
Expand Down
36 changes: 33 additions & 3 deletions modules/apps/transfer/types/transfer_authorization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,16 @@ func (suite *TypesTestSuite) TestTransferAuthorizationValidateBasic() {
},
true,
},
{
"success: with allowed forwarding hops",
func() {
transferAuthz.Allocations[0].AllowedForwarding = []types.AllowedForwarding{
{Hops: []types.Hop{validHop}},
{Hops: []types.Hop{{types.PortID, "channel-1"}}},
}
},
true,
},
{
"empty allocations",
func() {
Expand Down Expand Up @@ -622,8 +632,8 @@ func (suite *TypesTestSuite) TestTransferAuthorizationValidateBasic() {
false,
},
{
name: "duplicate channel ID",
malleate: func() {
"duplicate channel ID",
func() {
allocation := types.Allocation{
SourcePort: mock.PortID,
SourceChannel: transferAuthz.Allocations[0].SourceChannel,
Expand All @@ -633,7 +643,27 @@ func (suite *TypesTestSuite) TestTransferAuthorizationValidateBasic() {

transferAuthz.Allocations = append(transferAuthz.Allocations, allocation)
},
expPass: false,
false,
},
{
"fowarding hop with invalid port ID",
func() {
transferAuthz.Allocations[0].AllowedForwarding = []types.AllowedForwarding{
{Hops: []types.Hop{validHop}},
{Hops: []types.Hop{{"invalid/port", ibctesting.FirstChannelID}}},
}
},
false,
},
{
"fowarding hop with invalid channel ID",
func() {
transferAuthz.Allocations[0].AllowedForwarding = []types.AllowedForwarding{
{Hops: []types.Hop{validHop}},
{Hops: []types.Hop{{types.PortID, "invalid/channel"}}},
}
},
false,
},
}

Expand Down

0 comments on commit e310e27

Please sign in to comment.