Merge pull request #108 from rabbitmq/rabbitmq-erlang-client-107

AMQP(S) URI that specifies port without host should be an error
This commit is contained in:
Michael Klishin 2018-08-09 18:00:18 +02:00 committed by GitHub
commit 054b811252
2 changed files with 27 additions and 8 deletions

View File

@ -128,14 +128,19 @@ build_broker(ParsedUri, DefaultVHost) ->
end
end,
UserInfo = proplists:get_value(userinfo, ParsedUri),
set_user_info(case unescape_string(Host) of
undefined -> #amqp_params_direct{virtual_host = VHost};
Host1 -> Mech = mechanisms(ParsedUri),
#amqp_params_network{host = Host1,
port = Port,
virtual_host = VHost,
auth_mechanisms = Mech}
end, UserInfo).
Record = case {unescape_string(Host), Port} of
{undefined, undefined} ->
#amqp_params_direct{virtual_host = VHost};
{undefined, _Port} ->
fail(port_requires_host);
{Host1, Port1} ->
Mech = mechanisms(ParsedUri),
#amqp_params_network{host = Host1,
port = Port1,
virtual_host = VHost,
auth_mechanisms = Mech}
end,
set_user_info(Record, UserInfo).
set_user_info(Ps, UserInfo) ->
case UserInfo of

View File

@ -58,6 +58,14 @@ amqp_uri_parsing(_Config) ->
?assertMatch({ok, #amqp_params_direct{username = <<"">>,
virtual_host = <<"">>}},
amqp_uri:parse("amqp://:@/")),
% https://github.com/rabbitmq/rabbitmq-server/issues/1663
?assertEqual({error,{port_requires_host,"amqp://:1234"}},
amqp_uri:parse("amqp://:1234")),
?assertMatch({ok, #amqp_params_network{host = "localhost",
port = 1234}},
amqp_uri:parse("amqp://localhost:1234")),
?assertMatch({ok, #amqp_params_network{username = <<"">>,
password = <<"">>,
virtual_host = <<"">>,
@ -126,6 +134,12 @@ amqp_uri_parsing(_Config) ->
amqp_uri:parse("amqp://user:pass@[::1]:100")),
%% TLS options
?assertEqual({error,{port_requires_host,"amqps://:5671"}},
amqp_uri:parse("amqps://:5671")),
?assertMatch({ok, #amqp_params_network{host = "localhost",
port = 5671}},
amqp_uri:parse("amqps://localhost:5671")),
{ok, #amqp_params_network{host = "host1", ssl_options = TLSOpts1}} =
amqp_uri:parse("amqps://host1/%2f?cacertfile=/path/to/cacertfile.pem"),
Exp1 = [{cacertfile,"/path/to/cacertfile.pem"}],