Skip to content

Commit 8e0d6fc

Browse files
committed
Fix default value check when setting SASL authentication from URI
1 parent 2e14735 commit 8e0d6fc

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

connection.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,22 @@ func DialConfig(url string, config Config) (*Connection, error) {
206206
}
207207

208208
if config.SASL == nil {
209-
config.SASL = []Authentication{uri.PlainAuth()}
209+
if uri.AuthMechanism != nil {
210+
for _, identifier := range uri.AuthMechanism {
211+
switch strings.ToUpper(identifier) {
212+
case "PLAIN":
213+
config.SASL = append(config.SASL, uri.PlainAuth())
214+
case "AMQPLAIN":
215+
config.SASL = append(config.SASL, uri.AMQPlainAuth())
216+
case "EXTERNAL":
217+
config.SASL = append(config.SASL, &ExternalAuth{})
218+
default:
219+
return nil, fmt.Errorf("unsupported auth_mechanism: %v", identifier)
220+
}
221+
}
222+
} else {
223+
config.SASL = []Authentication{uri.PlainAuth()}
224+
}
210225
}
211226

212227
if config.Vhost == "" {
@@ -226,21 +241,6 @@ func DialConfig(url string, config Config) (*Connection, error) {
226241
connectionTimeout = time.Duration(uri.ConnectionTimeout) * time.Millisecond
227242
}
228243

229-
if config.SASL == nil && uri.AuthMechanism != nil {
230-
for _, identifier := range uri.AuthMechanism {
231-
switch strings.ToUpper(identifier) {
232-
case "PLAIN":
233-
config.SASL = append(config.SASL, uri.PlainAuth())
234-
case "AMQPLAIN":
235-
config.SASL = append(config.SASL, uri.AMQPlainAuth())
236-
case "EXTERNAL":
237-
config.SASL = append(config.SASL, &ExternalAuth{})
238-
default:
239-
return nil, fmt.Errorf("unsupported auth_mechanism: %v", identifier)
240-
}
241-
}
242-
}
243-
244244
addr := net.JoinHostPort(uri.Host, strconv.FormatInt(int64(uri.Port), 10))
245245

246246
dialer := config.Dial

0 commit comments

Comments
 (0)