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 1 commit
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: 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