Skip to content

Commit

Permalink
[receiver/solace]: Update the auth validation step (#36386)
Browse files Browse the repository at this point in the history
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

The validation step should not allow configuring several auth methods
when only one will be considered (the first one that's not nil in this
order plain > xauth2 > external).

(technically this is a breaking change because some users might have
several auth methods configured, but that doesn't make sense so it's
unlikely to break many users if any)

<!--Describe what testing was performed and which tests were added.-->
#### Testing
One test with multiple auth methods was added.

---------

Co-authored-by: Daniel Jaglowski <[email protected]>
Co-authored-by: Antoine Toulme <[email protected]>
  • Loading branch information
3 people authored Jan 24, 2025
1 parent f86a2d2 commit 65fb229
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
27 changes: 27 additions & 0 deletions .chloggen/solace-receiver-validation-improvements.yaml
Original file line number Diff line number Diff line change
@@ -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: []
16 changes: 15 additions & 1 deletion receiver/solacereceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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://<queuename>")
errMissingPlainTextParams = errors.New("missing plain text auth params: Username, Password")
errMissingXauth2Params = errors.New("missing xauth2 text auth params: Username, Bearer")
Expand Down Expand Up @@ -46,9 +47,22 @@ 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 == 0 {
return errMissingAuthDetails
}
if authMethod > 1 {
return errTooManyAuthDetails
}
if len(strings.TrimSpace(cfg.Queue)) == 0 {
return errMissingQueueName
}
Expand Down
9 changes: 9 additions & 0 deletions receiver/solacereceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, errTooManyAuthDetails, err)
}

func TestConfigValidateMissingQueue(t *testing.T) {
cfg := createDefaultConfig().(*Config)
cfg.Auth.PlainText = &SaslPlainTextConfig{"Username", "Password"}
Expand Down

0 comments on commit 65fb229

Please sign in to comment.