Skip to content

Commit 65fb229

Browse files
wildumdjaglowskiatoulme
authored
[receiver/solace]: Update the auth validation step (#36386)
<!--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]>
1 parent f86a2d2 commit 65fb229

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: breaking
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: solacereceiver
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Update validation step to allow only one auth method.
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [36386]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: []

receiver/solacereceiver/config.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const (
1919

2020
var (
2121
errMissingAuthDetails = errors.New("authentication details are required, either for plain user name password or XOAUTH2 or client certificate")
22+
errTooManyAuthDetails = errors.New("only one authentication method must be used")
2223
errMissingQueueName = errors.New("queue definition is required, queue definition has format queue://<queuename>")
2324
errMissingPlainTextParams = errors.New("missing plain text auth params: Username, Password")
2425
errMissingXauth2Params = errors.New("missing xauth2 text auth params: Username, Bearer")
@@ -46,9 +47,22 @@ type Config struct {
4647

4748
// Validate checks the receiver configuration is valid
4849
func (cfg *Config) Validate() error {
49-
if cfg.Auth.PlainText == nil && cfg.Auth.External == nil && cfg.Auth.XAuth2 == nil {
50+
authMethod := 0
51+
if cfg.Auth.PlainText != nil {
52+
authMethod++
53+
}
54+
if cfg.Auth.External != nil {
55+
authMethod++
56+
}
57+
if cfg.Auth.XAuth2 != nil {
58+
authMethod++
59+
}
60+
if authMethod == 0 {
5061
return errMissingAuthDetails
5162
}
63+
if authMethod > 1 {
64+
return errTooManyAuthDetails
65+
}
5266
if len(strings.TrimSpace(cfg.Queue)) == 0 {
5367
return errMissingQueueName
5468
}

receiver/solacereceiver/config_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@ func TestConfigValidateMissingAuth(t *testing.T) {
8787
assert.Equal(t, errMissingAuthDetails, err)
8888
}
8989

90+
func TestConfigValidateMultipleAuth(t *testing.T) {
91+
cfg := createDefaultConfig().(*Config)
92+
cfg.Queue = "someQueue"
93+
cfg.Auth.PlainText = &SaslPlainTextConfig{"Username", "Password"}
94+
cfg.Auth.XAuth2 = &SaslXAuth2Config{"Username", "Bearer"}
95+
err := component.ValidateConfig(cfg)
96+
assert.Equal(t, errTooManyAuthDetails, err)
97+
}
98+
9099
func TestConfigValidateMissingQueue(t *testing.T) {
91100
cfg := createDefaultConfig().(*Config)
92101
cfg.Auth.PlainText = &SaslPlainTextConfig{"Username", "Password"}

0 commit comments

Comments
 (0)