Skip to content

Commit

Permalink
Some fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Farina <matt.farina@suse.com>
(cherry picked from commit 764557c)
  • Loading branch information
mattfarina committed Feb 21, 2024
1 parent e8858f8 commit c309b6f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ var validPluginName = regexp.MustCompile("^[A-Za-z0-9_-]+$")

// validatePluginData validates a plugin's YAML data.
func validatePluginData(plug *Plugin, filepath string) error {
// When metadata section missing, initialize with no data
if plug.Metadata == nil {
plug.Metadata = &Metadata{}
}
if !validPluginName.MatchString(plug.Metadata.Name) {
return fmt.Errorf("invalid plugin name at %q", filepath)
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/plugin/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,11 @@ func TestSetupEnvWithSpace(t *testing.T) {
}

func TestValidatePluginData(t *testing.T) {
// A mock plugin missing any metadata.
mockMissingMeta := &Plugin{
Dir: "no-such-dir",
}

for i, item := range []struct {
pass bool
plug *Plugin
Expand All @@ -363,6 +368,7 @@ func TestValidatePluginData(t *testing.T) {
{false, mockPlugin("$foo -bar")}, // Test leading chars
{false, mockPlugin("foo -bar ")}, // Test trailing chars
{false, mockPlugin("foo\nbar")}, // Test newline
{false, mockMissingMeta}, // Test if the metadata section missing
} {
err := validatePluginData(item.plug, fmt.Sprintf("test-%d", i))
if item.pass && err != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/repo/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,10 @@ func loadIndex(data []byte, source string) (*IndexFile, error) {
log.Printf("skipping loading invalid entry for chart %q from %s: empty entry", name, source)
continue
}
// When metadata section missing, initialize with no data
if cvs[idx].Metadata == nil {
cvs[idx].Metadata = &chart.Metadata{}
}
if cvs[idx].APIVersion == "" {
cvs[idx].APIVersion = chart.APIVersionV1
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/repo/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ entries:
name: grafana
foo:
-
bar:
- digest: "sha256:1234567890abcdef"
urls:
- https://charts.helm.sh/stable/alpine-1.0.0.tgz
`
)

Expand Down

0 comments on commit c309b6f

Please sign in to comment.