Skip to content

Commit f0a9130

Browse files
Merge pull request #8132 from rabbitmq/mergify/bp/v3.11.x/pr-8131
Correctly use AMQP URI query parameter `password` (backport #8130) (backport #8131)
2 parents 2058f7b + 5eda3d2 commit f0a9130

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

deps/amqp_client/src/amqp_uri.erl

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,15 @@ broker_add_query(Params, ParsedUri, Fields) ->
204204
return({ParamsN, Pos1});
205205
Value ->
206206
try
207-
ValueParsed = parse_amqp_param(Field, Value),
208-
return(
209-
{setelement(Pos, ParamsN, ValueParsed), Pos1})
207+
case parse_amqp_param(Field, Value) of
208+
ignore ->
209+
return({ParamsN, Pos1});
210+
ValueParsed ->
211+
return({setelement(Pos, ParamsN, ValueParsed), Pos1})
212+
end
210213
catch throw:Reason ->
211-
fail({invalid_amqp_params_parameter,
212-
Field, Value, Query, Reason})
214+
fail({invalid_amqp_params_parameter,
215+
Field, Value, Query, Reason})
213216
end
214217
end
215218
end || Field <- Fields], {Params, 2}),
@@ -221,8 +224,11 @@ parse_amqp_param(Field, String) when Field =:= channel_max orelse
221224
Field =:= connection_timeout orelse
222225
Field =:= depth ->
223226
find_integer_parameter(String);
224-
parse_amqp_param(Field, String) when Field =:= password ->
225-
find_identity_parameter(String);
227+
parse_amqp_param(Field, _String) when Field =:= password ->
228+
%% https://github.com/rabbitmq/rabbitmq-server/issues/8129
229+
%% Ignore `password` here since the parameter is used for setting a
230+
%% certificate password, NOT an AMQP login password
231+
return(ignore);
226232
parse_amqp_param(Field, String) ->
227233
fail({parameter_unconfigurable_in_query, Field, String}).
228234

deps/amqp_client/test/unit_SUITE.erl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,9 @@ amqp_uri_parsing(_Config) ->
147147
{server_name_indication,"host3"}],
148148
?assertEqual(lists:usort(Exp3), lists:usort(TLSOpts3)),
149149

150-
{ok, #amqp_params_network{host = "host4", ssl_options = TLSOpts4}} =
151-
amqp_uri:parse("amqps://host4/%2f?cacertfile=/path/to/cacertfile.pem"
150+
{ok, #amqp_params_network{username = <<"user">>, password = <<"pass">>,
151+
host = "host4", ssl_options = TLSOpts4}} =
152+
amqp_uri:parse("amqps://user:pass@host4/%2f?cacertfile=/path/to/cacertfile.pem"
152153
"&certfile=/path/to/certfile.pem"
153154
"&password=topsecret"
154155
"&depth=5"),
@@ -171,8 +172,9 @@ amqp_uri_parsing(_Config) ->
171172
{verify, verify_none}]),
172173
lists:usort(TLSOpts8)),
173174

174-
{ok, #amqp_params_network{host = "127.0.0.1", ssl_options = TLSOpts9}} =
175-
amqp_uri:parse("amqps://127.0.0.1/%2f?cacertfile=/path/to/cacertfile.pem"
175+
{ok, #amqp_params_network{username = <<"user">>, password = <<"pass">>,
176+
host = "127.0.0.1", ssl_options = TLSOpts9}} =
177+
amqp_uri:parse("amqps://user:[email protected]/%2f?cacertfile=/path/to/cacertfile.pem"
176178
"&certfile=/path/to/certfile.pem"
177179
"&password=topsecret"
178180
"&depth=5"),

0 commit comments

Comments
 (0)