From f71272ca7972bcd1adac90184f079e17f3d27e44 Mon Sep 17 00:00:00 2001 From: Medya Gh Date: Wed, 30 Sep 2020 17:22:45 -0700 Subject: [PATCH 1/5] don't allow profile name to be less than 2 characters --- cmd/minikube/cmd/start.go | 2 +- pkg/minikube/config/profile.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 8975cd787b12..ff85c7ded088 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -155,7 +155,7 @@ func runStart(cmd *cobra.Command, args []string) { if !config.ProfileNameValid(ClusterFlagValue()) { out.WarningT("Profile name '{{.name}}' is not valid", out.V{"name": ClusterFlagValue()}) - exit.Message(reason.Usage, "Only alphanumeric and dashes '-' are permitted. Minimum 1 character, starting with alphanumeric.") + exit.Message(reason.Usage, "Only alphanumeric and dashes '-' are permitted. Minimum 2 character, starting with alphanumeric.") } existing, err := config.Load(ClusterFlagValue()) diff --git a/pkg/minikube/config/profile.go b/pkg/minikube/config/profile.go index b5baf5ed4fb8..f7e8c142db1e 100644 --- a/pkg/minikube/config/profile.go +++ b/pkg/minikube/config/profile.go @@ -90,8 +90,8 @@ func ProfileNameValid(name string) bool { const RestrictedNamePattern = `(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])` var validName = regexp.MustCompile(`^` + RestrictedNamePattern + `$`) - - return validName.MatchString(name) + // length needs to be more than 1 character because docker volume #9366 + return validName.MatchString(name) && len(name) > 1 } // ProfileNameInReservedKeywords checks if the profile is an internal keywords From 1048e6d4906bb413afab0665f2102fed46774364 Mon Sep 17 00:00:00 2001 From: Medya Gh Date: Wed, 30 Sep 2020 17:24:26 -0700 Subject: [PATCH 2/5] add unit test --- pkg/minikube/config/profile_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/minikube/config/profile_test.go b/pkg/minikube/config/profile_test.go index ffeb29c3ecdd..f225e109180a 100644 --- a/pkg/minikube/config/profile_test.go +++ b/pkg/minikube/config/profile_test.go @@ -81,9 +81,10 @@ func TestProfileNameValid(t *testing.T) { "1st-profile": true, "1st-2nd-3rd-profile": true, "n": true, - "1": true, "12567": true, + "p": false, + "1": false, "pro file": false, "pro-file-": false, "-profile": false, From e178684f32d2bd977ab64489aa6e8f47b22eeaa8 Mon Sep 17 00:00:00 2001 From: Medya Gh Date: Wed, 30 Sep 2020 17:26:24 -0700 Subject: [PATCH 3/5] unit test --- pkg/minikube/config/profile_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/minikube/config/profile_test.go b/pkg/minikube/config/profile_test.go index f225e109180a..b5b99230c750 100644 --- a/pkg/minikube/config/profile_test.go +++ b/pkg/minikube/config/profile_test.go @@ -80,10 +80,9 @@ func TestProfileNameValid(t *testing.T) { "pro-file1": true, "1st-profile": true, "1st-2nd-3rd-profile": true, - "n": true, "12567": true, - "p": false, + "n": false, "1": false, "pro file": false, "pro-file-": false, From 437aed366c41f83e16d60ede34b765f2c5cb8729 Mon Sep 17 00:00:00 2001 From: Medya Gh Date: Wed, 30 Sep 2020 17:31:22 -0700 Subject: [PATCH 4/5] unit test --- pkg/minikube/config/profile_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/minikube/config/profile_test.go b/pkg/minikube/config/profile_test.go index b5b99230c750..89536bceca6b 100644 --- a/pkg/minikube/config/profile_test.go +++ b/pkg/minikube/config/profile_test.go @@ -81,9 +81,10 @@ func TestProfileNameValid(t *testing.T) { "1st-profile": true, "1st-2nd-3rd-profile": true, "12567": true, + "111": true, - "n": false, "1": false, + "n": false, "pro file": false, "pro-file-": false, "-profile": false, From dc0918e6baaf209abed9fc275be5310213101697 Mon Sep 17 00:00:00 2001 From: Medya Gh Date: Mon, 5 Oct 2020 16:13:21 -0700 Subject: [PATCH 5/5] review comments --- cmd/minikube/cmd/start.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index ff85c7ded088..7cac99439e2b 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -155,7 +155,7 @@ func runStart(cmd *cobra.Command, args []string) { if !config.ProfileNameValid(ClusterFlagValue()) { out.WarningT("Profile name '{{.name}}' is not valid", out.V{"name": ClusterFlagValue()}) - exit.Message(reason.Usage, "Only alphanumeric and dashes '-' are permitted. Minimum 2 character, starting with alphanumeric.") + exit.Message(reason.Usage, "Only alphanumeric and dashes '-' are permitted. Minimum 2 characters, starting with alphanumeric.") } existing, err := config.Load(ClusterFlagValue())