testcontainers-java icon indicating copy to clipboard operation
testcontainers-java copied to clipboard

[Bug]: Started RabbitMQContainer doesn't allow to connect to rabbitmq

Open FoKas90 opened this issue 2 years ago • 4 comments

Module

RabbitMQ

Testcontainers version

1.20.4

Using the latest Testcontainers version?

Yes

Host OS

macOS

Host Arch

x86

Docker version

Client: Docker Engine - Community
 Version:           27.3.1
 API version:       1.46 (downgraded from 1.47)
 Go version:        go1.23.1
 Git commit:        ce1223035a
 Built:             Fri Sep 20 11:01:47 2024
 OS/Arch:           darwin/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          27.1.1
  API version:      1.46 (minimum version 1.24)
  Go version:       go1.21.12
  Git commit:       cc13f95
  Built:            Tue Jul 23 19:57:14 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.7.19
  GitCommit:        2bf793ef6dc9a18e00cb12efb64355c2c9d5eb41
 runc:
  Version:          1.7.19
  GitCommit:        v1.1.13-0-g58aa920
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

What happened?

Hi! I start RabbitMQContainer like this

        @Bean
        RabbitMQContainer rabbitMQContainer(DynamicPropertyRegistry registry) {

            var imageName = DockerImageName.parse("library/rabbitmq:3-management")
                    .asCompatibleSubstituteFor("rabbitmq");
            var container = new RabbitMQContainer(imageName)
                    .withEnv(Map.of( 
                    "RABBITMQ_DEFAULT_USER", "user", 
                    "RABBITMQ_DEFAULT_PASS", "pass", 
                    "RABBITMQ_DEFAULT_VHOST", "vhost" 
            ));
            registry.add("property.port", container::getAmqpPort);
            registry.add("property.host", container::getHost);
            return container;
        }
    }

It starts normally. But any try to connect to rabbitmq end with error. Test log contains ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. For details see the broker logfile RabbitMQ's log contains

2024-11-26 14:36:03.282923+00:00 [error] <0.839.0> Error on AMQP connection <0.839.0> (192.168.64.1:49308 -> 172.26.0.3:5672, state: starting):
2024-11-26T14:36:03.283748836Z 2024-11-26 14:36:03.282923+00:00 [error] <0.839.0> PLAIN login refused: user 'user' - invalid credentials

Even though I can't authorize into admin panel (http://localhost:15672), I get an relevant error about incorrect creds.

But when I start container in traditional way docker run -d -p '15672:15672' --hostname my-rabbit --name some-rabbit -e RABBITMQ_DEFAULT_USER=user -e RABBITMQ_DEFAULT_PASS= pass -e RABBITMQ_DEFAULT_VHOST=vhost rabbitmq:3-management I don't get any problems with connection and authorization.

Relevant log output


Additional Information

No response

FoKas90 avatar Nov 26 '24 14:11 FoKas90

How are you setting rabbitmq credentials in spring? RABBITMQ_DEFAULT_USER and RABBITMQ_DEFAULT_PASS are the right env vars to set the credentials in the container. So, the client must use the same value user and pass. Can you provide a minimal reproducer, please?

eddumelendez avatar Nov 26 '24 17:11 eddumelendez

@eddumelendez Hi! Thanks for response! I built a little example https://github.com/FoKas90/testcontainers-rabbitmq-bug reproducing unexpectable behaviour

FoKas90 avatar Nov 26 '24 18:11 FoKas90

The code shared is different than the snippet reported in this issue. I've merged #9571, which should fix the issue with ServiceConnection

eddumelendez avatar Nov 26 '24 18:11 eddumelendez

I wanted emphasize the minimal configuration with defaults still doesn't work (to my mind). Thank you for fast fix!

FoKas90 avatar Nov 26 '24 19:11 FoKas90