From 850845f10b6dae2f983185a427046d8967e4b04f Mon Sep 17 00:00:00 2001 From: William Dumont Date: Fri, 15 Nov 2024 10:43:16 +0100 Subject: [PATCH 1/3] update the auth validation step --- receiver/solacereceiver/config.go | 12 +++++++++++- receiver/solacereceiver/config_test.go | 9 +++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/receiver/solacereceiver/config.go b/receiver/solacereceiver/config.go index e8eaffa48894..d0f6857a542e 100644 --- a/receiver/solacereceiver/config.go +++ b/receiver/solacereceiver/config.go @@ -46,7 +46,17 @@ type Config struct { // Validate checks the receiver configuration is valid func (cfg *Config) Validate() error { - if cfg.Auth.PlainText == nil && cfg.Auth.External == nil && cfg.Auth.XAuth2 == nil { + authMethod := 0 + if cfg.Auth.PlainText != nil { + authMethod++ + } + if cfg.Auth.External != nil { + authMethod++ + } + if cfg.Auth.XAuth2 != nil { + authMethod++ + } + if authMethod != 1 { return errMissingAuthDetails } if len(strings.TrimSpace(cfg.Queue)) == 0 { diff --git a/receiver/solacereceiver/config_test.go b/receiver/solacereceiver/config_test.go index e0169e79c27d..a38c62726dca 100644 --- a/receiver/solacereceiver/config_test.go +++ b/receiver/solacereceiver/config_test.go @@ -87,6 +87,15 @@ func TestConfigValidateMissingAuth(t *testing.T) { assert.Equal(t, errMissingAuthDetails, err) } +func TestConfigValidateMultipleAuth(t *testing.T) { + cfg := createDefaultConfig().(*Config) + cfg.Queue = "someQueue" + cfg.Auth.PlainText = &SaslPlainTextConfig{"Username", "Password"} + cfg.Auth.XAuth2 = &SaslXAuth2Config{"Username", "Bearer"} + err := component.ValidateConfig(cfg) + assert.Equal(t, errMissingAuthDetails, err) +} + func TestConfigValidateMissingQueue(t *testing.T) { cfg := createDefaultConfig().(*Config) cfg.Auth.PlainText = &SaslPlainTextConfig{"Username", "Password"} From 64bb18623c6e68051e5121e5901f9caee343e7cc Mon Sep 17 00:00:00 2001 From: William Dumont Date: Fri, 15 Nov 2024 10:52:43 +0100 Subject: [PATCH 2/3] changelog --- ...lace-receiver-validation-improvements.yaml | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .chloggen/solace-receiver-validation-improvements.yaml diff --git a/.chloggen/solace-receiver-validation-improvements.yaml b/.chloggen/solace-receiver-validation-improvements.yaml new file mode 100644 index 000000000000..9bf32f5b1b64 --- /dev/null +++ b/.chloggen/solace-receiver-validation-improvements.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: breaking + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: solacereceiver + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Update validation step to allow only one auth method. + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [36386] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] From 15fa05cd04589da3b58bdf5740313443eace21e7 Mon Sep 17 00:00:00 2001 From: William Dumont Date: Mon, 18 Nov 2024 10:28:03 +0100 Subject: [PATCH 3/3] update auth error msg --- receiver/solacereceiver/config.go | 6 +++++- receiver/solacereceiver/config_test.go | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/receiver/solacereceiver/config.go b/receiver/solacereceiver/config.go index d0f6857a542e..ceae502ecde7 100644 --- a/receiver/solacereceiver/config.go +++ b/receiver/solacereceiver/config.go @@ -19,6 +19,7 @@ const ( var ( errMissingAuthDetails = errors.New("authentication details are required, either for plain user name password or XOAUTH2 or client certificate") + errTooManyAuthDetails = errors.New("only one authentication method must be used") errMissingQueueName = errors.New("queue definition is required, queue definition has format queue://") errMissingPlainTextParams = errors.New("missing plain text auth params: Username, Password") errMissingXauth2Params = errors.New("missing xauth2 text auth params: Username, Bearer") @@ -56,9 +57,12 @@ func (cfg *Config) Validate() error { if cfg.Auth.XAuth2 != nil { authMethod++ } - if authMethod != 1 { + if authMethod == 0 { return errMissingAuthDetails } + if authMethod > 1 { + return errTooManyAuthDetails + } if len(strings.TrimSpace(cfg.Queue)) == 0 { return errMissingQueueName } diff --git a/receiver/solacereceiver/config_test.go b/receiver/solacereceiver/config_test.go index a38c62726dca..230027892180 100644 --- a/receiver/solacereceiver/config_test.go +++ b/receiver/solacereceiver/config_test.go @@ -93,7 +93,7 @@ func TestConfigValidateMultipleAuth(t *testing.T) { cfg.Auth.PlainText = &SaslPlainTextConfig{"Username", "Password"} cfg.Auth.XAuth2 = &SaslXAuth2Config{"Username", "Bearer"} err := component.ValidateConfig(cfg) - assert.Equal(t, errMissingAuthDetails, err) + assert.Equal(t, errTooManyAuthDetails, err) } func TestConfigValidateMissingQueue(t *testing.T) {