Skip to content

Commit 8b5b022

Browse files
committed
remove user name in case of tls
Signed-off-by: Gabriele Santomaggio <[email protected]>
1 parent cb85fac commit 8b5b022

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

pkg/rabbitmqamqp/amqp_connection.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ func (a *AmqpConnection) open(ctx context.Context, address string, connOptions *
262262
WriteTimeout: connOptions.WriteTimeout,
263263
}
264264
azureConnection, err = amqp.Dial(ctx, address, amqpLiteConnOptions)
265+
if err != nil && (connOptions.TLSConfig != nil || uri.Scheme == AMQPS) {
266+
Error("Failed to open TLS connection", fmt.Sprintf("%s://%s", uri.Scheme, uri.Host), err, "ID", connOptions.Id)
267+
return fmt.Errorf("failed to open TLS connection: %w", err)
268+
}
265269
if err != nil {
266270
Error("Failed to open connection", ExtractWithoutPassword(address), err, "ID", connOptions.Id)
267271
return fmt.Errorf("failed to open connection: %w", err)

pkg/rabbitmqamqp/amqp_connection_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,16 @@ var _ = Describe("AMQP connection Test", func() {
164164
}()
165165
})
166166

167+
Describe("AMQP TLS connection should fail with error.", func() {
168+
tlsConfig := &tls.Config{}
169+
170+
// Dial the AMQP server with TLS configuration
171+
connection, err := Dial(context.Background(), "amqps://does_not_exist:5671", &AmqpConnOptions{
172+
TLSConfig: tlsConfig,
173+
})
174+
Expect(connection).To(BeNil())
175+
Expect(err).NotTo(BeNil())
176+
Expect(err.Error()).To(ContainSubstring("failed to open TLS connection"))
177+
})
178+
167179
})

pkg/rabbitmqamqp/common.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
// public consts
1212

13+
const AMQPS = "amqps"
1314
const StreamFilterValue = "x-stream-filter-value"
1415

1516
const (

0 commit comments

Comments
 (0)