Skip to content

Commit 2f1a878

Browse files
Always use list() type for urls
1 parent 1675b2e commit 2f1a878

File tree

7 files changed

+60
-40
lines changed

7 files changed

+60
-40
lines changed

deps/rabbitmq_auth_backend_oauth2/src/oauth2_schema.erl

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ translate_list_of_signing_keys(ListOfKidPath) ->
6969
-spec translate_endpoint_params(list(), [{list(), binary()}]) -> map().
7070
translate_endpoint_params(Variable, Conf) ->
7171
Params0 = cuttlefish_variable:filter_by_prefix("auth_oauth2." ++ Variable, Conf),
72-
Params = [{Param, V} || {["auth_oauth2", _, Param], V} <- Params0],
73-
maps:from_list(Params).
72+
[{list_to_binary(Param), list_to_binary(V)} || {["auth_oauth2", _, Param], V} <- Params0].
7473

7574
validator_file_exists(Attr, Filename) ->
7675
case file:read_file(Filename) of
@@ -81,10 +80,21 @@ validator_file_exists(Attr, Filename) ->
8180
cuttlefish:invalid(io_lib:format(
8281
"Invalid attribute (~p) value: file ~p does not exist or cannot be read by the node", [Attr, Filename]))
8382
end.
83+
84+
validator_uri(Attr, Uri) when is_binary(Uri) ->
85+
validator_uri(Attr, binary_to_list(Uri));
86+
validator_uri(Attr, Uri) when is_list(Uri) ->
87+
case uri_string:parse(Uri) of
88+
{error, _, _} = Error ->
89+
cuttlefish:invalid(io_lib:format(
90+
"Invalid attribute (~p) value: ~p (~p)", [Attr, Uri, Error]));
91+
_ -> Uri
92+
end.
93+
8494
validator_https_uri(Attr, Uri) when is_binary(Uri) ->
85-
list_to_binary(validator_https_uri(Attr, binary_to_list(Uri)));
95+
validator_https_uri(Attr, binary_to_list(Uri));
8696

87-
validator_https_uri(Attr, Uri) ->
97+
validator_https_uri(Attr, Uri) when is_list(Uri) ->
8898
case string:nth_lexeme(Uri, 1, "://") == "https" of
8999
true -> Uri;
90100
false ->
@@ -120,6 +130,7 @@ mapOauthProviderProperty({Key, Value}) ->
120130
jwks_uri -> validator_https_uri(Key, Value);
121131
end_session_endpoint -> validator_https_uri(Key, Value);
122132
authorization_endpoint -> validator_https_uri(Key, Value);
133+
discovery_endpoint_path -> validator_uri(Key, Value);
123134
discovery_endpoint_params ->
124135
cuttlefish:invalid(io_lib:format(
125136
"Invalid attribute (~p) value: should be a map of Key,Value pairs", [Key]));
@@ -167,7 +178,7 @@ extract_oauth_providers_endpoint_params(Variable, Settings) ->
167178
IndexedParams = [{Name, {list_to_binary(ParamName), list_to_binary(V)}} ||
168179
{["auth_oauth2","oauth_providers", Name, EndpointVar, ParamName], V}
169180
<- Settings, EndpointVar == atom_to_list(Variable) ],
170-
maps:map(fun(_K,V)-> [{Variable, maps:from_list(V)}] end,
181+
maps:map(fun(_K,V)-> [{Variable, V}] end,
171182
maps:groups_from_list(KeyFun, fun({_, V}) -> V end, IndexedParams)).
172183

173184
extract_oauth_providers_signing_keys(Settings) ->

deps/rabbitmq_auth_backend_oauth2/test/config_schema_SUITE_data/rabbitmq_auth_backend_oauth2.snippets

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
{verify_aud, true},
3434
{issuer, "https://my-jwt-issuer"},
3535
{discovery_endpoint_path, "/.well-known/openid-configuration"},
36-
{discovery_endpoint_params, #{
37-
"param1" => "value1"
38-
}},
36+
{discovery_endpoint_params, [
37+
{<<"param1">>, <<"value1">>}
38+
]},
3939
{key_config, [
4040
{default_key, <<"id1">>},
4141
{signing_keys,
@@ -142,6 +142,8 @@
142142
auth_oauth2.oauth_providers.keycloak.https.depth = 2
143143
auth_oauth2.oauth_providers.keycloak.default_key = token-key
144144
auth_oauth2.oauth_providers.keycloak.signing_keys.id1 = test/config_schema_SUITE_data/certs/key.pem
145+
auth_oauth2.oauth_providers.keycloak.discovery_endpoint_path = /.well-known/openid-configuration
146+
auth_oauth2.oauth_providers.keycloak.discovery_endpoint_params.param1 = value1
145147
auth_oauth2.oauth_providers.keycloak.algorithms.1 = HS256
146148
auth_oauth2.oauth_providers.keycloak.algorithms.2 = RS256",
147149
[
@@ -166,14 +168,18 @@
166168
{cacertfile, "test/config_schema_SUITE_data/certs/cacert.pem"}
167169
]},
168170
{algorithms, [<<"HS256">>, <<"RS256">>]},
171+
{discovery_endpoint_params, [
172+
{<<"param1">>, <<"value1">>}
173+
]},
174+
{discovery_endpoint_path, "/.well-known/openid-configuration"},
169175
{default_key, <<"token-key">>},
170-
{end_session_endpoint, <<"https://keycloak/logout">>},
171-
{authorization_endpoint, <<"https://keycloak/authorize">>},
172-
{jwks_uri, <<"https://keycloak/keys">>},
173-
{token_endpoint, <<"https://keycloak/token">>}
176+
{end_session_endpoint, "https://keycloak/logout"},
177+
{authorization_endpoint, "https://keycloak/authorize"},
178+
{jwks_uri, "https://keycloak/keys"},
179+
{token_endpoint, "https://keycloak/token"}
174180
],
175181
<<"uaa">> => [
176-
{issuer, <<"https://uaa">>}
182+
{issuer, "https://uaa"}
177183
]
178184

179185
}

deps/rabbitmq_auth_backend_oauth2/test/oauth2_schema_SUITE.erl

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ test_without_resource_servers(_) ->
4545
#{} = oauth2_schema:translate_resource_servers([]).
4646

4747
test_without_endpoint_params(_) ->
48-
#{} = translate_endpoint_params("oauth_discovery_endpoint_params", []).
48+
[] = translate_endpoint_params("oauth_discovery_endpoint_params", []).
4949

5050
test_with_invalid_endpoint_params(_) ->
5151
try translate_endpoint_params("discovery_endpoint_params", [
@@ -60,7 +60,7 @@ test_with_endpoint_params(_) ->
6060
{["auth_oauth2","discovery_endpoint_params","param1"], "some-value1"},
6161
{["auth_oauth2","discovery_endpoint_params","param2"], "some-value2"}
6262
],
63-
#{ "param1" := "some-value1", "param2" := "some-value2" } =
63+
[ {<<"param1">>, <<"some-value1">>}, {<<"param2">>, <<"some-value2">>} ] =
6464
translate_endpoint_params("discovery_endpoint_params", Conf).
6565

6666
test_invalid_oauth_providers_endpoint_params(_) ->
@@ -79,17 +79,20 @@ test_without_oauth_providers_with_endpoint_params(_) ->
7979
],
8080

8181
#{
82-
<<"A">> := [{discovery_endpoint_params,
83-
#{ <<"param1">> := <<"some-value1">>, <<"param2">> := <<"some-value2">> }}],
84-
<<"B">> := [{discovery_endpoint_params,
85-
#{ <<"param3">> := <<"some-value3">>}}
86-
]
82+
<<"A">> := [{discovery_endpoint_params, [
83+
{<<"param1">>, <<"some-value1">>},
84+
{<<"param2">>, <<"some-value2">>}
85+
]}],
86+
<<"B">> := [{discovery_endpoint_params, [
87+
{<<"param3">>, <<"some-value3">>}
88+
]}]
89+
8790
} = translate_oauth_providers(Conf).
8891

8992
test_with_one_oauth_provider(_) ->
9093
Conf = [{["auth_oauth2","oauth_providers","keycloak","issuer"],"https://rabbit"}
9194
],
92-
#{<<"keycloak">> := [{issuer, <<"https://rabbit">>}]
95+
#{<<"keycloak">> := [{issuer, "https://rabbit"}]
9396
} = oauth2_schema:translate_oauth_providers(Conf).
9497

9598
test_with_one_resource_server(_) ->
@@ -103,10 +106,10 @@ test_with_many_oauth_providers(_) ->
103106
{["auth_oauth2","oauth_providers","uaa","issuer"],"https://uaa"},
104107
{["auth_oauth2","oauth_providers","uaa","discovery_endpoint_path"],"/some-path"}
105108
],
106-
#{<<"keycloak">> := [{issuer, <<"https://keycloak">>}
109+
#{<<"keycloak">> := [{issuer, "https://keycloak"}
107110
],
108-
<<"uaa">> := [{issuer, <<"https://uaa">>},
109-
{discovery_endpoint_path, <<"/some-path">>}
111+
<<"uaa">> := [{issuer, "https://uaa"},
112+
{discovery_endpoint_path, "/some-path"}
110113
]
111114
} = oauth2_schema:translate_oauth_providers(Conf).
112115

@@ -126,7 +129,7 @@ test_oauth_providers_attributes(_) ->
126129
{["auth_oauth2","oauth_providers","keycloak","default_key"],"token-key"}
127130
],
128131
#{<<"keycloak">> := [{default_key, <<"token-key">>},
129-
{issuer, <<"https://keycloak">>}
132+
{issuer, "https://keycloak"}
130133
]
131134
} = sort_settings(oauth2_schema:translate_oauth_providers(Conf)).
132135

@@ -173,7 +176,7 @@ test_oauth_providers_algorithms(_) ->
173176
{["auth_oauth2","oauth_providers","keycloak","algorithms","1"],"RS256"}
174177
],
175178
#{<<"keycloak">> := [{algorithms, [<<"RS256">>, <<"HS256">>]},
176-
{issuer, <<"https://keycloak">>}
179+
{issuer, "https://keycloak"}
177180
]
178181
} = sort_settings(oauth2_schema:translate_oauth_providers(Conf)).
179182

@@ -196,7 +199,7 @@ test_oauth_providers_https(Conf) ->
196199
{fail_if_no_peer_cert, true},
197200
{cacertfile, _CaCertFile}
198201
]},
199-
{issuer, <<"https://keycloak">>}
202+
{issuer, "https://keycloak"}
200203
]
201204
} = sort_settings(oauth2_schema:translate_oauth_providers(CuttlefishConf)).
202205

@@ -216,7 +219,7 @@ test_oauth_providers_signing_keys(Conf) ->
216219
{["auth_oauth2","oauth_providers","keycloak","signing_keys","2"], cert_filename(Conf)},
217220
{["auth_oauth2","oauth_providers","keycloak","signing_keys","1"], cert_filename(Conf)}
218221
],
219-
#{<<"keycloak">> := [{issuer, <<"https://keycloak">>},
222+
#{<<"keycloak">> := [{issuer, "https://keycloak"},
220223
{signing_keys, SigningKeys}
221224
]
222225
} = sort_settings(oauth2_schema:translate_oauth_providers(CuttlefishConf)),

deps/rabbitmq_management/src/rabbit_mgmt_schema.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ translate_oauth_resource_servers(Conf) ->
3939
-spec translate_endpoint_params(list(), [{list(), binary()}]) -> map().
4040
translate_endpoint_params(Variable, Conf) ->
4141
Params0 = cuttlefish_variable:filter_by_prefix("management." ++ Variable, Conf),
42-
Params = [{Param, list_to_binary(V)} || {["management", _, Param], V} <- Params0].
42+
[{list_to_binary(Param), list_to_binary(V)} || {["management", _, Param], V} <- Params0].
4343

4444
merge_list_of_maps(ListOfMaps) ->
4545
lists:foldl(fun(Elem, AccIn) -> maps:merge_with(fun(_K,V1,V2) -> V1 ++ V2 end,
@@ -62,7 +62,7 @@ extract_resource_server_endpoint_params(Variable, Settings) ->
6262
KeyFun = fun extract_key/1,
6363

6464
rabbit_log:debug("extract_resource_server_endpoint_params ~p ~p", [Variable, Settings]),
65-
IndexedParams = [{Name, {ParamName, list_to_binary(V)}} ||
65+
IndexedParams = [{Name, {list_to_binary(ParamName), list_to_binary(V)}} ||
6666
{["management","oauth_resource_servers", Name, EndpointVar, ParamName], V}
6767
<- Settings, EndpointVar == atom_to_list(Variable) ],
6868
maps:map(fun(_K,V)-> [{Variable, V}] end,

deps/rabbitmq_management/test/config_schema_SUITE_data/rabbitmq_management.snippets

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@
627627
[
628628
{rabbitmq_management, [
629629
{oauth_authorization_endpoint_params, [
630-
{"param1", <<"value1">>}
630+
{<<"param1">>, <<"value1">>}
631631
]},
632632
{oauth_enabled, true},
633633
{oauth_provider_url, "http://localhost:8080"},
@@ -667,7 +667,7 @@
667667
],
668668
"resource-one" => [
669669
{oauth_token_endpoint_params, [
670-
{"param2", <<"value2">>}
670+
{<<"param2">>, <<"value2">>}
671671
]},
672672
{oauth_scopes, "openid profile rabbitmq.*"},
673673
{oauth_client_id, "one"},
@@ -677,7 +677,7 @@
677677
],
678678
"resource-two" => [
679679
{oauth_authorization_endpoint_params, [
680-
{"param1", <<"value1">>}
680+
{<<"param1">>, <<"value1">>}
681681
]},
682682
{oauth_client_id, "two"},
683683
{id, "resource-two"},

deps/rabbitmq_management/test/rabbit_mgmt_schema_SUITE.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ all() ->
2424

2525

2626
test_empty_endpoint_params(_) ->
27-
#{} = translate_endpoint_params("oauth_authorization_endpoint_params", []),
28-
#{} = translate_endpoint_params("oauth_token_endpoint_params", []).
27+
[] = translate_endpoint_params("oauth_authorization_endpoint_params", []),
28+
[] = translate_endpoint_params("oauth_token_endpoint_params", []).
2929

3030
test_invalid_endpoint_params(_) ->
3131
try translate_endpoint_params("oauth_authorization_endpoint_params", [
@@ -36,7 +36,7 @@ test_invalid_endpoint_params(_) ->
3636
end.
3737

3838
test_translate_endpoint_params(_) ->
39-
#{ "param1" := "some-value1" } =
39+
[ {<<"param1">>, <<"some-value1">>} ] =
4040
translate_endpoint_params("oauth_authorization_endpoint_params", [
4141
{["management","oauth_authorization_endpoint_params","param1"], "some-value1"}
4242
]).

deps/rabbitmq_management/test/rabbit_mgmt_wm_auth_SUITE.erl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,10 @@ init_per_suite(Config) ->
361361
{w, <<"w">>},
362362
{z, <<"z">>},
363363
{x, <<"x">>},
364-
{authorization_params_0, [{"a-param0", "value0"}]},
365-
{authorization_params_1, [{"a-param1", "value1"}]},
366-
{token_params_0, [{"t-param0", "value0"}]},
367-
{token_params_1, [{"t-param1", "value1"}]},
364+
{authorization_params_0, [{<<"a-param0">>, <<"value0">>}]},
365+
{authorization_params_1, [{<<"a-param1">>, <<"value1">>}]},
366+
{token_params_0, [{<<"t-param0">>, <<"value0">>}]},
367+
{token_params_1, [{<<"t-param1">>, <<"value1">>}]},
368368
{admin_mgt, <<"admin mgt">>},
369369
{read_write, <<"read write">>} | Config].
370370

0 commit comments

Comments
 (0)