Skip to content
Open
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
3 changes: 2 additions & 1 deletion pkg/types/ipallowlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"net"
"strings"
"unicode/utf8"

"github.com/render-oss/cli/pkg/client"
)
Expand Down Expand Up @@ -38,7 +39,7 @@ func ParseIPAllowListEntry(raw string) (cidrBlock string, description string, er
cidrBlock = ipNet.String()

const maxDescriptionLength = 255
if len(description) > maxDescriptionLength {
if utf8.RuneCountInString(description) > maxDescriptionLength {
return "", "", fmt.Errorf("invalid --ip-allow-list %q: description exceeds %d characters", raw, maxDescriptionLength)
}

Expand Down
27 changes: 27 additions & 0 deletions pkg/types/ipallowlist_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types_test

import (
"strings"
"testing"

"github.com/render-oss/cli/pkg/types"
Expand Down Expand Up @@ -61,6 +62,32 @@ func TestParseIPAllowListEntry(t *testing.T) {
})
}

func TestParseIPAllowListEntryDescriptionLength(t *testing.T) {
for _, tc := range []struct {
name string
description string
ok bool
}{
{"255 ASCII characters", strings.Repeat("x", 255), true},
{"256 ASCII characters", strings.Repeat("x", 256), false},
{"255 multi-byte characters", strings.Repeat("雪", 255), true},
{"256 multi-byte characters", strings.Repeat("雪", 256), false},
{"64 emoji", strings.Repeat("😀", 64), true},
{"punctuation and Unicode", "QA,office=入口,description=kept", true},
} {
t.Run(tc.name, func(t *testing.T) {
cidr, desc, err := types.ParseIPAllowListEntry("cidr=10.0.0.0/8,description=" + tc.description)
if !tc.ok {
require.ErrorContains(t, err, "description exceeds 255 characters")
return
}
require.NoError(t, err)
assert.Equal(t, "10.0.0.0/8", cidr)
assert.Equal(t, tc.description, desc)
})
}
}

func TestParseIPAllowList(t *testing.T) {
t.Run("parses each entry into a CidrBlockAndDescription", func(t *testing.T) {
out, err := types.ParseIPAllowList([]string{
Expand Down