Reject v-versions

Signed-off-by: MrJack <36191829+biagiopietro@users.noreply.github.com>
pull/31615/head
MrJack 7 months ago
parent dc5248a7ba
commit 74f71f10b0

@ -41,7 +41,7 @@ An exact semver version can be supplied per-plugin using the @version syntax:
helm plugin update myplugin@1.2.3 otherplugin@2.0.0 helm plugin update myplugin@1.2.3 otherplugin@2.0.0
helm plugin update myplugin@v1.0.0 helm plugin update myplugin@v1.0.0
Range constraints (e.g. ~1.2, ^1.0.0, >=1.0.0) are not supported. Range constraints (e.g. ~1.2, ^1.0.0, >=1.0.0, v1.0.0) are not supported.
If no version is given for a plugin it is updated to the latest version: If no version is given for a plugin it is updated to the latest version:
@ -85,8 +85,8 @@ func (o *pluginUpdateOptions) complete(args []string) error {
return fmt.Errorf("plugin %q specified more than once", name) return fmt.Errorf("plugin %q specified more than once", name)
} }
if version != "" { if version != "" {
if _, err := semver.NewVersion(version); err != nil { if _, err := semver.StrictNewVersion(version); err != nil {
return fmt.Errorf("invalid version %q for plugin %q: must be an exact version (e.g. 1.2.3 or v1.2.3)", version, name) return fmt.Errorf("invalid version %q for plugin %q: must be an exact semver version (e.g. 1.2.3); the \"v\" prefix is not allowed", version, name)
} }
} }
o.plugins[name] = version o.plugins[name] = version

@ -80,8 +80,8 @@ func TestPluginUpdateComplete(t *testing.T) {
}, },
{ {
name: "multiple plugins each with different exact versions", name: "multiple plugins each with different exact versions",
args: []string{"plugin-a@v1.2.3", "plugin-b@2.0.0", "plugin-c@3.0.0"}, args: []string{"plugin-a@1.2.3", "plugin-b@2.0.0", "plugin-c@3.0.0"},
wantPlugins: map[string]string{"plugin-a": "v1.2.3", "plugin-b": "2.0.0", "plugin-c": "3.0.0"}, wantPlugins: map[string]string{"plugin-a": "1.2.3", "plugin-b": "2.0.0", "plugin-c": "3.0.0"},
}, },
{ {
name: "multiple plugins mixed versions", name: "multiple plugins mixed versions",
@ -103,40 +103,45 @@ func TestPluginUpdateComplete(t *testing.T) {
args: []string{"@1.0.0"}, args: []string{"@1.0.0"},
wantErr: `invalid plugin reference "@1.0.0": plugin name must not be empty`, wantErr: `invalid plugin reference "@1.0.0": plugin name must not be empty`,
}, },
{
name: "v-prefixed version rejected",
args: []string{"myplugin@v1.2.3"},
wantErr: `invalid version "v1.2.3" for plugin "myplugin": must be an exact semver version (e.g. 1.2.3); the "v" prefix is not allowed`,
},
{ {
name: "tilde range version rejected", name: "tilde range version rejected",
args: []string{"myplugin@~1.2"}, args: []string{"myplugin@~1.2"},
wantErr: `invalid version "~1.2" for plugin "myplugin": must be an exact version (e.g. 1.2.3 or v1.2.3)`, wantErr: `invalid version "~1.2" for plugin "myplugin": must be an exact semver version (e.g. 1.2.3); the "v" prefix is not allowed`,
}, },
{ {
name: "caret range version rejected", name: "caret range version rejected",
args: []string{"myplugin@^1.2.3"}, args: []string{"myplugin@^1.2.3"},
wantErr: `invalid version "^1.2.3" for plugin "myplugin": must be an exact version (e.g. 1.2.3 or v1.2.3)`, wantErr: `invalid version "^1.2.3" for plugin "myplugin": must be an exact semver version (e.g. 1.2.3); the "v" prefix is not allowed`,
}, },
{ {
name: "gte constraint rejected", name: "gte constraint rejected",
args: []string{"myplugin@>=1.0.0"}, args: []string{"myplugin@>=1.0.0"},
wantErr: `invalid version ">=1.0.0" for plugin "myplugin": must be an exact version (e.g. 1.2.3 or v1.2.3)`, wantErr: `invalid version ">=1.0.0" for plugin "myplugin": must be an exact semver version (e.g. 1.2.3); the "v" prefix is not allowed`,
}, },
{ {
name: "wildcard version rejected", name: "wildcard version rejected",
args: []string{"myplugin@1.x"}, args: []string{"myplugin@1.x"},
wantErr: `invalid version "1.x" for plugin "myplugin": must be an exact version (e.g. 1.2.3 or v1.2.3)`, wantErr: `invalid version "1.x" for plugin "myplugin": must be an exact semver version (e.g. 1.2.3); the "v" prefix is not allowed`,
}, },
{ {
name: "range constraint rejected", name: "range constraint rejected",
args: []string{"myplugin@>=1.0.0, <2.0.0"}, args: []string{"myplugin@>=1.0.0, <2.0.0"},
wantErr: `invalid version ">=1.0.0, <2.0.0" for plugin "myplugin": must be an exact version (e.g. 1.2.3 or v1.2.3)`, wantErr: `invalid version ">=1.0.0, <2.0.0" for plugin "myplugin": must be an exact semver version (e.g. 1.2.3); the "v" prefix is not allowed`,
}, },
{ {
name: "garbage version rejected", name: "garbage version rejected",
args: []string{"myplugin@notaversion"}, args: []string{"myplugin@notaversion"},
wantErr: `invalid version "notaversion" for plugin "myplugin": must be an exact version (e.g. 1.2.3 or v1.2.3)`, wantErr: `invalid version "notaversion" for plugin "myplugin": must be an exact semver version (e.g. 1.2.3); the "v" prefix is not allowed`,
}, },
{ {
name: "range rejected among multiple plugins", name: "range rejected among multiple plugins",
args: []string{"plugin-a@1.0.0", "plugin-b@~2.0"}, args: []string{"plugin-a@1.0.0", "plugin-b@~2.0"},
wantErr: `invalid version "~2.0" for plugin "plugin-b": must be an exact version (e.g. 1.2.3 or v1.2.3)`, wantErr: `invalid version "~2.0" for plugin "plugin-b": must be an exact semver version (e.g. 1.2.3); the "v" prefix is not allowed`,
}, },
} }
for _, tt := range tests { for _, tt := range tests {

Loading…
Cancel
Save