Skip to content

Commit

Permalink
Merge pull request from GHSA-c52f-pq47-2r9j
Browse files Browse the repository at this point in the history
switched to stricter YAML parsing on plugin metadata files
  • Loading branch information
Matthew Fisher authored Sep 17, 2020
2 parents 809e2d9 + 6eeec4a commit d9ef5ce
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pkg/plugin/installer/local_installer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestLocalInstaller(t *testing.T) {
t.Fatal(err)
}

source := "../testdata/plugdir/echo"
source := "../testdata/plugdir/good/echo"
i, err := NewForSource(source, "")
if err != nil {
t.Fatalf("unexpected error: %s", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/installer/vcs_installer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestVCSInstaller(t *testing.T) {
}

source := "https://github.com/adamreese/helm-env"
testRepoPath, _ := filepath.Abs("../testdata/plugdir/echo")
testRepoPath, _ := filepath.Abs("../testdata/plugdir/good/echo")
repo := &testRepo{
local: testRepoPath,
tags: []string{"0.1.0", "0.1.1"},
Expand Down
8 changes: 7 additions & 1 deletion pkg/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ type Metadata struct {
// Downloaders field is used if the plugin supply downloader mechanism
// for special protocols.
Downloaders []Downloaders `json:"downloaders"`

// UseTunnelDeprecated indicates that this command needs a tunnel.
// Setting this will cause a number of side effects, such as the
// automatic setting of HELM_HOST.
// DEPRECATED and unused, but retained for backwards compatibility with Helm 2 plugins. Remove in Helm 4
UseTunnelDeprecated bool `json:"useTunnel,omitempty"`
}

// Plugin represents a plugin.
Expand Down Expand Up @@ -200,7 +206,7 @@ func LoadDir(dirname string) (*Plugin, error) {
}

plug := &Plugin{Dir: dirname}
if err := yaml.Unmarshal(data, &plug.Metadata); err != nil {
if err := yaml.UnmarshalStrict(data, &plug.Metadata); err != nil {
return nil, errors.Wrapf(err, "failed to load plugin at %q", pluginfile)
}
return plug, validatePluginData(plug, pluginfile)
Expand Down
15 changes: 11 additions & 4 deletions pkg/plugin/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func TestNoMatchPrepareCommand(t *testing.T) {
}

func TestLoadDir(t *testing.T) {
dirname := "testdata/plugdir/hello"
dirname := "testdata/plugdir/good/hello"
plug, err := LoadDir(dirname)
if err != nil {
t.Fatalf("error loading Hello plugin: %s", err)
Expand All @@ -205,8 +205,15 @@ func TestLoadDir(t *testing.T) {
}
}

func TestLoadDirDuplicateEntries(t *testing.T) {
dirname := "testdata/plugdir/bad/duplicate-entries"
if _, err := LoadDir(dirname); err == nil {
t.Errorf("successfully loaded plugin with duplicate entries when it should've failed")
}
}

func TestDownloader(t *testing.T) {
dirname := "testdata/plugdir/downloader"
dirname := "testdata/plugdir/good/downloader"
plug, err := LoadDir(dirname)
if err != nil {
t.Fatalf("error loading Hello plugin: %s", err)
Expand Down Expand Up @@ -244,7 +251,7 @@ func TestLoadAll(t *testing.T) {
t.Fatalf("expected empty dir to have 0 plugins")
}

basedir := "testdata/plugdir"
basedir := "testdata/plugdir/good"
plugs, err := LoadAll(basedir)
if err != nil {
t.Fatalf("Could not load %q: %s", basedir, err)
Expand Down Expand Up @@ -288,7 +295,7 @@ func TestFindPlugins(t *testing.T) {
},
{
name: "normal",
plugdirs: "./testdata/plugdir",
plugdirs: "./testdata/plugdir/good",
expected: 3,
},
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/plugin/testdata/plugdir/bad/duplicate-entries/plugin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: "duplicate-entries"
version: "0.1.0"
usage: "usage"
description: |-
description
command: "echo hello"
ignoreFlags: true
hooks:
install: "echo installing..."
hooks:
install: "echo installing something different"
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ description: |-
description
command: "$HELM_PLUGIN_SELF/hello.sh"
ignoreFlags: true
install: "echo installing..."
hooks:
install: "echo installing..."

0 comments on commit d9ef5ce

Please sign in to comment.