Skip to content

Commit

Permalink
This commit restores URI parsing functionality
Browse files Browse the repository at this point in the history
In ruby-amqp#159 functionality was added to hutch that meant that it would respect that when using `amqps://` as the URI scheme it would use TLS and also that when not specifying a port in the URI scheme it would default to the standard protocol ports (5671 for TLS connections, 5672 for non TLS connections).

This functionality appears to have been lost since and is restored by this commit it also adds a new test case to prevent another regression.
  • Loading branch information
Michael Lennox committed Jan 16, 2018
1 parent 47632a0 commit e83bdc7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/hutch/broker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,18 @@ def parse_uri

u = URI.parse(@config[:uri])

@config[:mq_tls] = u.scheme == 'amqps'
@config[:mq_host] = u.host
@config[:mq_port] = u.port
@config[:mq_port] = u.port || default_mq_port
@config[:mq_vhost] = u.path.sub(/^\//, "")
@config[:mq_username] = u.user
@config[:mq_password] = u.password
end

def default_mq_port
@config[:mq_tls] ? 5671 : 5672
end

def sanitized_uri
p = connection_params
scheme = p[:tls] ? "amqps" : "amqp"
Expand Down
30 changes: 30 additions & 0 deletions spec/hutch/broker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,36 @@

connection.close
end

context 'when configured with a URI' do
context 'which specifies the port' do
before { config[:uri] = 'amqp://guest:guest@127.0.0.1:5672/' }

it 'successfully connects' do
expect { broker.open_connection }.not_to raise_error
end
end

context 'which does not specify port and uses the amqp scheme' do
before { config[:uri] = 'amqp://guest:guest@127.0.0.1/' }

it 'successfully connects' do
expect { broker.open_connection }.not_to raise_error
end
end

context 'which specifies the amqps scheme' do
before { config[:uri] = 'amqps://guest:guest@127.0.0.1/' }

it 'utilises TLS' do
expect(Hutch::Adapter).to receive(:new).with(
hash_including(tls: true, port: 5671)
).and_return(instance_double('Hutch::Adapter', start: nil))

broker.open_connection
end
end
end
end

describe '#open_connection!' do
Expand Down

0 comments on commit e83bdc7

Please sign in to comment.