fix name length check on lint (#8543)

Signed-off-by: Matt Butcher <matt.butcher@microsoft.com>
pull/8681/head
Matt Butcher 4 years ago committed by GitHub
parent ac983a644b
commit 96d9ab9663
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -5,6 +5,7 @@ go 1.13
require (
github.com/BurntSushi/toml v0.3.1
github.com/DATA-DOG/go-sqlmock v1.4.1
github.com/Masterminds/goutils v1.1.0
github.com/Masterminds/semver/v3 v3.1.0
github.com/Masterminds/sprig/v3 v3.1.0
github.com/Masterminds/squirrel v1.4.0

@ -147,7 +147,8 @@ func validateReleaseName(releaseName string) error {
return errMissingRelease
}
if !ValidName.MatchString(releaseName) || (len(releaseName) > releaseNameMaxLen) {
// Check length first, since that is a less expensive operation.
if len(releaseName) > releaseNameMaxLen || !ValidName.MatchString(releaseName) {
return errInvalidName
}

@ -165,6 +165,9 @@ func validateYamlContent(err error) error {
}
func validateMetadataName(obj *K8sYamlStruct) error {
if len(obj.Metadata.Name) == 0 || len(obj.Metadata.Name) > 253 {
return fmt.Errorf("object name must be between 0 and 253 characters: %q", obj.Metadata.Name)
}
// This will return an error if the characters do not abide by the standard OR if the
// name is left empty.
if validName.MatchString(obj.Metadata.Name) {

@ -22,6 +22,8 @@ import (
"strings"
"testing"
"github.com/Masterminds/goutils"
"helm.sh/helm/v3/internal/test/ensure"
"helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/chartutil"
@ -119,6 +121,14 @@ func TestValidateMetadataName(t *testing.T) {
"a..b": false,
"%^&#$%*@^*@&#^": false,
}
// The length checker should catch this first. So this is not true fuzzing.
tooLong, err := goutils.RandomAlphaNumeric(300)
if err != nil {
t.Fatalf("Randomizer failed to initialize: %s", err)
}
names[tooLong] = false
for input, expectPass := range names {
obj := K8sYamlStruct{Metadata: k8sYamlMetadata{Name: input}}
if err := validateMetadataName(&obj); (err == nil) != expectPass {

Loading…
Cancel
Save