Receive plugins' versions with underscores. (#699)

* Receive plugins versions with underscores.

New jenkins plugin versions have underscores in them (example: https://plugins.jenkins.io/credentials/). The operator refuses configuration for such plug-ins as they do not match the existing regex.

* Add tests to underscores in plugin versions

Adds a new test to check that versions with underscores are valid.

* Synchronise regexps character order to avoid range

Make two related regexps more evidently similar to each other and re-order the symbols so that the - is not interpreted.
This commit is contained in:
João Valença 2022-01-27 09:58:27 +00:00 committed by GitHub
parent 0f507409cc
commit 424ec3fbc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -22,9 +22,9 @@ func (p Plugin) String() string {
var (
// NamePattern is the plugin name regex pattern
NamePattern = regexp.MustCompile(`^[0-9a-zA-Z-_]+$`)
NamePattern = regexp.MustCompile(`^[0-9a-zA-Z\-_]+$`)
// VersionPattern is the plugin version regex pattern
VersionPattern = regexp.MustCompile(`^[0-9a-zA-Z+\\.-]+$`)
VersionPattern = regexp.MustCompile(`^[0-9a-zA-Z\-_+\\.]+$`)
// DownloadURLPattern is the plugin download url regex pattern
DownloadURLPattern = regexp.MustCompile(`https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)`)
)

View File

@ -36,6 +36,10 @@ func TestValidatePlugin(t *testing.T) {
got := validatePlugin(validPluginName, "3.1.20180605-140134.c2e96c4", "")
assert.NoError(t, got)
})
t.Run("version 1074.v60e6c29b_b_44b_", func(t *testing.T) {
got := validatePlugin(validPluginName, "1074.v60e6c29b_b_44b_", "")
assert.NoError(t, got)
})
t.Run("invalid version !", func(t *testing.T) {
got := validatePlugin(validPluginName, "0.5.1!", "")
assert.Error(t, got)