Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

increase port identifier limit to 128 characters #344

Merged
merged 4 commits into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,14 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

### API Breaking

* (core) [\#227](https://github.com/cosmos/ibc-go/pull/227) Remove sdk.Result from application callbacks

### State Machine Breaking

* (24-host) [#\344](https://github.com/cosmos/ibc-go/pull/344) Increase port identifier limit to 128 characters.


## [v1.0.0](https://github.com/cosmos/ibc-go/releases/tag/v1.0.0) - 2021-08-10

Expand Down
3 changes: 2 additions & 1 deletion modules/apps/transfer/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const (
validPort = "testportid"
invalidPort = "(invalidport1)"
invalidShortPort = "p"
invalidLongPort = "invalidlongportinvalidlongportinvalidlongportinvalidlongportinvalid"
// 195 characters
invalidLongPort = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis eros neque, ultricies vel ligula ac, convallis porttitor elit. Maecenas tincidunt turpis elit, vel faucibus nisl pellentesque sodales"

validChannel = "testchannel"
invalidChannel = "(invalidchannel1)"
Expand Down
3 changes: 2 additions & 1 deletion modules/core/04-channel/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ const (
// invalid constants used for testing
invalidPort = "(invalidport1)"
invalidShortPort = "p"
invalidLongPort = "invalidlongportinvalidlongportinvalidlongportidinvalidlongportidinvalid"
// 195 characters
invalidLongPort = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis eros neque, ultricies vel ligula ac, convallis porttitor elit. Maecenas tincidunt turpis elit, vel faucibus nisl pellentesque sodales"

invalidChannel = "(invalidchannel1)"
invalidShortChannel = "invalid"
Expand Down
6 changes: 5 additions & 1 deletion modules/core/24-host/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import (
// adjusting this restriction.
const DefaultMaxCharacterLength = 64

// DefaultMaxPortCharacterLength defines the default maximum character length used
// in validation of port identifiers.
var DefaultMaxPortCharacterLength = 128
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose var instead of const so apps could modify this in the future if they so choose. I don't see a good reason why it needs to be a const?


// IsValidID defines regular expression to check if the string consist of
// characters in one of the following categories only:
// - Alphanumeric
Expand Down Expand Up @@ -80,7 +84,7 @@ func ChannelIdentifierValidator(id string) error {
// A valid Identifier must be between 2-64 characters and only contain alphanumeric and some allowed
// special characters (see IsValidID).
func PortIdentifierValidator(id string) error {
return defaultIdentifierValidator(id, 2, DefaultMaxCharacterLength)
return defaultIdentifierValidator(id, 2, DefaultMaxPortCharacterLength)
}

// NewPathValidator takes in a Identifier Validator function and returns
Expand Down
30 changes: 30 additions & 0 deletions modules/core/24-host/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"github.com/stretchr/testify/require"
)

// 195 characters
var longId = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis eros neque, ultricies vel ligula ac, convallis porttitor elit. Maecenas tincidunt turpis elit, vel faucibus nisl pellentesque sodales"

type testCase struct {
msg string
id string
Expand Down Expand Up @@ -50,6 +53,33 @@ func TestDefaultIdentifierValidator(t *testing.T) {
}
}

func TestPortIdentifierValidator(t *testing.T) {
testCases := []testCase{
{"valid lowercase", "transfer", true},
{"valid id special chars", "._+-#[]<>._+-#[]<>", true},
{"valid id lower and special chars", "lower._+-#[]<>", true},
{"numeric id", "1234567890", true},
{"uppercase id", "NOTLOWERCASE", true},
{"numeric id", "1234567890", true},
{"blank id", " ", false},
{"id length out of range", "1", false},
{"id is too long", longId, false},
{"path-like id", "lower/case/id", false},
{"invalid id", "(clientid)", false},
{"empty string", "", false},
}

for _, tc := range testCases {

err := PortIdentifierValidator(tc.id)
if tc.expPass {
require.NoError(t, err, tc.msg)
} else {
require.Error(t, err, tc.msg)
}
}
}

func TestPathValidator(t *testing.T) {
testCases := []testCase{
{"valid lowercase", "p/lowercaseid", true},
Expand Down