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 IAM custom role length validation to match API. #3660

Merged
merged 1 commit into from
May 20, 2019
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
2 changes: 1 addition & 1 deletion google/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const (
ComputeServiceAccountNameRegex = "[0-9]{1,20}[email protected]"

// https://cloud.google.com/iam/docs/understanding-custom-roles#naming_the_role
IAMCustomRoleIDRegex = "^[a-zA-Z0-9_\\.\\-]{1,30}$"
IAMCustomRoleIDRegex = "^[a-zA-Z0-9_\\.]{3,64}$"
)

var (
Expand Down
11 changes: 6 additions & 5 deletions google/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,19 +324,20 @@ func TestValidateIAMCustomRoleIDRegex(t *testing.T) {
{TestName: "basic", Value: "foobar"},
{TestName: "with numbers", Value: "foobar123"},
{TestName: "with capipals", Value: "FooBar"},
{TestName: "short", Value: "f"},
{TestName: "long", Value: "foobarfoobarfoobarfoobarfoobar"},
{TestName: "has a hyphen", Value: "foo-bar"},
{TestName: "short", Value: "foo"},
{TestName: "long", Value: strings.Repeat("f", 64)},
{TestName: "has a dot", Value: "foo.bar"},
{TestName: "has an underscore", Value: "foo_bar"},
{TestName: "all of the above", Value: "foo.Bar-Baz_123"},
{TestName: "all of the above", Value: "foo.BarBaz_123"},

// With errors
{TestName: "empty", Value: "", ExpectError: true},
{TestName: "has an slash", Value: "foo/bar", ExpectError: true},
{TestName: "has a hyphen", Value: "foo-bar", ExpectError: true},
{TestName: "has a dollar", Value: "foo$", ExpectError: true},
{TestName: "has a space", Value: "foo bar", ExpectError: true},
{TestName: "too long", Value: strings.Repeat("f", 31), ExpectError: true},
{TestName: "too short", Value: "fo", ExpectError: true},
{TestName: "too long", Value: strings.Repeat("f", 65), ExpectError: true},
}

es := testStringValidationCases(x, validateIAMCustomRoleID)
Expand Down