Foo-Foo-MQ / foo-foo-mq

Abstractions around RabbitMQ
MIT License
48 stars 24 forks source link

Error when adding a forward slash to PLAIN credentials, throws "TypeError: Invalid URL" #55

Closed MartianH closed 2 months ago

MartianH commented 3 months ago

When adding credentials like a password with a forward slash, it either fails to be url encoded (Invalid Url) or when url encoded beforehand (using encodeURIComponent) it returns "host unreachable". The secrets are generated at random and injected so this is quite the problem.

steps to reproduce

  1. Create a rabbitmq instance (rabbitmq:3-management-alpine) with user dummy and password 54sd/d56: set credentials are valid using amqplib (encoded) or the management frontend.
version: '3.8'
services:
  rabbitmq:
    image: rabbitmq:3-management-alpine
    environment:
      - RABBITMQ_DEFAULT_USER=dummy
      - RABBITMQ_DEFAULT_PASS=54sd/d56
    ports:
      - 5672:5672
      - 15672:15672
  1. Connect to said broker with given credentials, first without encoding, which usually works, then with encoding.
const rabbit = require("foo-foo-mq");

rabbit
  .configure({
    connection: {
      user: 'dummy',
      pass: '54sd/d56', // with encoding: encodeURIComponent('54sd/d56'),
      server: ['localhost'],
      port: 5672,
      vhost: "%2f",
      replyQueue: false,
    },
    exchanges: [
      {
        name:  'text.ex.fx',
        type: 'fanout',
        durable: true,
      }
    ]
  }).then(async () => {
      await rabbit.publish( 'text.ex.fx', { body: { text: 'hello' } });
      console.log('published');
  }).catch((err) => console.log(err))
  1. Run code, it should throw: 1) TypeError: Invalid URL or 2) Logs No endpoints could be reached
  2. Edit docker-compose YAML, remove the slash (/) and recreate. It will now log published

Edit: tried encodeURI jut in case, to no avail.