From 424ec3fbc2bb2b54006c491fd851bf8bb1f6946e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Valen=C3=A7a?= Date: Thu, 27 Jan 2022 09:58:27 +0000 Subject: [PATCH] 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. --- pkg/plugins/plugin.go | 4 ++-- pkg/plugins/plugin_test.go | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/plugins/plugin.go b/pkg/plugins/plugin.go index 2288dcd1..3c3b8732 100644 --- a/pkg/plugins/plugin.go +++ b/pkg/plugins/plugin.go @@ -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()@:%_\+.~#?&//=]*)`) ) diff --git a/pkg/plugins/plugin_test.go b/pkg/plugins/plugin_test.go index 0c46f597..eea2de9b 100644 --- a/pkg/plugins/plugin_test.go +++ b/pkg/plugins/plugin_test.go @@ -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)