switched to stricter YAML parsing on plugin metadata files

Signed-off-by: Matthew Fisher <matt.fisher@microsoft.com>
pull/8762/head
Matthew Fisher 4 years ago
parent 809e2d999e
commit 6eeec4a002
No known key found for this signature in database
GPG Key ID: 92AA783CBAAE8E3B

@ -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)

@ -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"},

@ -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.
@ -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)

@ -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)
@ -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)
@ -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)
@ -288,7 +295,7 @@ func TestFindPlugins(t *testing.T) {
},
{
name: "normal",
plugdirs: "./testdata/plugdir",
plugdirs: "./testdata/plugdir/good",
expected: 3,
},
}

@ -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"

@ -5,6 +5,5 @@ description: |-
description
command: "$HELM_PLUGIN_SELF/hello.sh"
ignoreFlags: true
install: "echo installing..."
hooks:
install: "echo installing..."
Loading…
Cancel
Save