From c04e18e45253f08d127a37c8328e7084e486c7cc Mon Sep 17 00:00:00 2001 From: Benoit Tigeot Date: Wed, 12 Nov 2025 21:23:01 +0100 Subject: [PATCH] fix: improve plugin name validation error messages Signed-off-by: Benoit Tigeot --- internal/plugin/metadata_legacy.go | 5 ++- internal/plugin/metadata_legacy_test.go | 55 +++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 internal/plugin/metadata_legacy_test.go diff --git a/internal/plugin/metadata_legacy.go b/internal/plugin/metadata_legacy.go index a7b245dc0..8f74d44cb 100644 --- a/internal/plugin/metadata_legacy.go +++ b/internal/plugin/metadata_legacy.go @@ -69,7 +69,10 @@ type MetadataLegacy struct { func (m *MetadataLegacy) Validate() error { if !validPluginName.MatchString(m.Name) { - return fmt.Errorf("invalid plugin name") + if m.Name == "" { + return fmt.Errorf("plugin name is empty or missing: ensure plugin.yaml contains 'name:' field (lowercase)") + } + return fmt.Errorf("invalid plugin name %q: plugin names can only contain ASCII characters a-z, A-Z, 0-9, _ and -", m.Name) } m.Usage = sanitizeString(m.Usage) diff --git a/internal/plugin/metadata_legacy_test.go b/internal/plugin/metadata_legacy_test.go new file mode 100644 index 000000000..caabcc12a --- /dev/null +++ b/internal/plugin/metadata_legacy_test.go @@ -0,0 +1,55 @@ +/* +Copyright The Helm Authors. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package plugin + +import ( + "strings" + "testing" +) + +func TestMetadataLegacyValidate_EmptyName(t *testing.T) { + metadata := MetadataLegacy{ + Name: "", + Version: "1.0.0", + } + + err := metadata.Validate() + if err == nil { + t.Fatal("expected error for empty plugin name") + } + + expectedMsg := "plugin name is empty or missing" + if !strings.Contains(err.Error(), expectedMsg) { + t.Errorf("expected error to contain %q, got %q", expectedMsg, err.Error()) + } +} + +func TestMetadataLegacyValidate_InvalidName(t *testing.T) { + metadata := MetadataLegacy{ + Name: "invalid name", + Version: "1.0.0", + } + + err := metadata.Validate() + if err == nil { + t.Fatal("expected error for invalid plugin name") + } + + expectedMsg := "plugin names can only contain ASCII characters" + if !strings.Contains(err.Error(), expectedMsg) { + t.Errorf("expected error to contain %q, got %q", expectedMsg, err.Error()) + } +}