Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug:Fix AMQPS url #2462

Merged
merged 3 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/rabbitmq/rabbitmq.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (c *RabbitMQContainer) AmqpURL(ctx context.Context) (string, error) {

// AmqpURL returns the URL for AMQPS clients.
func (c *RabbitMQContainer) AmqpsURL(ctx context.Context) (string, error) {
endpoint, err := c.PortEndpoint(ctx, nat.Port(DefaultAMQPPort), "")
endpoint, err := c.PortEndpoint(ctx, nat.Port(DefaultAMQPSPort), "")
if err != nil {
return "", err
}
Expand Down
57 changes: 57 additions & 0 deletions modules/rabbitmq/rabbitmq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ package rabbitmq_test

import (
"context"
"crypto/tls"
"crypto/x509"
"fmt"
"io"
"io/ioutil"
"path/filepath"
"strings"
"testing"

Expand Down Expand Up @@ -42,6 +46,59 @@ func TestRunContainer_connectUsingAmqp(t *testing.T) {
}
}

func TestRunContainer_connectUsingAmqps(t *testing.T) {
ctx := context.Background()

sslSettings := rabbitmq.SSLSettings{
CACertFile: filepath.Join("testdata", "certs", "server_ca.pem"),
CertFile: filepath.Join("testdata", "certs", "server_cert.pem"),
KeyFile: filepath.Join("testdata", "certs", "server_key.pem"),
VerificationMode: rabbitmq.SSLVerificationModePeer,
FailIfNoCert: false,
VerificationDepth: 1,
}

rabbitmqContainer, err := rabbitmq.RunContainer(ctx, rabbitmq.WithSSL(sslSettings))
if err != nil {
t.Fatal(err)
}

defer func() {
if err := rabbitmqContainer.Terminate(ctx); err != nil {
t.Fatal(err)
}
}()

amqpsURL, err := rabbitmqContainer.AmqpsURL(ctx)
if err != nil {
t.Fatal(err)
}

if !strings.HasPrefix(amqpsURL, "amqps") {
t.Fatal(fmt.Errorf("AMQPS Url should begin with `amqps`"))
}

certs := x509.NewCertPool()

pemData, err := ioutil.ReadFile(sslSettings.CACertFile)
if err != nil {
t.Fatal(err)
}
certs.AppendCertsFromPEM(pemData)

amqpsConnection, err := amqp.DialTLS(amqpsURL, &tls.Config{InsecureSkipVerify: false, RootCAs: certs})
if err != nil {
t.Fatal(err)
}

if amqpsConnection.IsClosed() {
t.Fatal(fmt.Errorf("AMQPS Connection unexpectdely closed"))
}
if err = amqpsConnection.Close(); err != nil {
t.Fatal(err)
}
}

func TestRunContainer_withAllSettings(t *testing.T) {
ctx := context.Background()

Expand Down