Skip to content

Commit e093f06

Browse files
Test invalid token parameter config
1 parent 59f5da5 commit e093f06

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
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
@@ -72,7 +72,7 @@ translate_list_of_signing_keys(ListOfKidPath) ->
7272
translate_endpoint_params(Variable, Conf) ->
7373
Params0 = cuttlefish_variable:filter_by_prefix("auth_oauth2." ++ Variable, Conf),
7474
Params = [{list_to_binary(Param), list_to_binary(V)} ||
75-
{["auth_oauth2", Name, Param], V} <- Params0],
75+
{["auth_oauth2", _, Param], V} <- Params0],
7676
maps:from_list(Params).
7777

7878
validator_file_exists(Attr, Filename) ->
@@ -104,9 +104,10 @@ extract_oauth_providers_properties(Settings) ->
104104
ValueFun = fun extract_value/1,
105105

106106
OAuthProviders = [{Name, mapOauthProviderProperty({list_to_atom(Key), list_to_binary(V)})}
107-
|| {["auth_oauth2","oauth_providers", Name, Key], V} <- Settings ],
107+
|| {["auth_oauth2", "oauth_providers", Name, Key], V} <- Settings],
108108
maps:groups_from_list(KeyFun, ValueFun, OAuthProviders).
109109

110+
110111
extract_resource_server_properties(Settings) ->
111112
KeyFun = fun extract_key_as_binary/1,
112113
ValueFun = fun extract_value/1,
@@ -122,6 +123,15 @@ mapOauthProviderProperty({Key, Value}) ->
122123
jwks_uri -> validator_https_uri(Key, Value);
123124
end_session_endpoint -> validator_https_uri(Key, Value);
124125
authorization_endpoint -> validator_https_uri(Key, Value);
126+
token_endpoint_params ->
127+
cuttlefish:invalid(io_lib:format(
128+
"Invalid attribute (~p) value: should be a map of Key,Value pairs", [Key]));
129+
authorization_endpoint_params ->
130+
cuttlefish:invalid(io_lib:format(
131+
"Invalid attribute (~p) value: should be a map of Key,Value pairs", [Key]));
132+
discovery_endpoint_params ->
133+
cuttlefish:invalid(io_lib:format(
134+
"Invalid attribute (~p) value: should be a map of Key,Value pairs", [Key]));
125135
_ -> Value
126136
end}.
127137

@@ -163,9 +173,10 @@ extract_resource_server_preferred_username_claims(Settings) ->
163173
extract_oauth_providers_endpoint_params(Variable, Settings) ->
164174
KeyFun = fun extract_key_as_binary/1,
165175

166-
IndexedParams = [{Name, {ParamName, list_to_binary(V)}} ||
167-
{["auth_oauth2","oauth_providers", Name, EndpointVar, ParamName], V} <- Settings, EndpointVar == Variable ],
168-
maps:map(fun(_K,V)-> [{Variable, V}] end,
176+
IndexedParams = [{Name, {list_to_binary(ParamName), list_to_binary(V)}} ||
177+
{["auth_oauth2","oauth_providers", Name, EndpointVar, ParamName], V}
178+
<- Settings, EndpointVar == atom_to_list(Variable) ],
179+
maps:map(fun(_K,V)-> [{Variable, maps:from_list(V)}] end,
169180
maps:groups_from_list(KeyFun, fun({_, V}) -> V end, IndexedParams)).
170181

171182
extract_oauth_providers_signing_keys(Settings) ->

deps/rabbitmq_auth_backend_oauth2/test/oauth2_schema_SUITE.erl

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@ all() ->
2727
test_oauth_providers_signing_keys,
2828
test_without_endpoint_params,
2929
test_with_endpoint_params,
30+
test_with_invalid_endpoint_params,
3031
test_without_resource_servers,
3132
test_with_one_resource_server,
3233
test_with_many_resource_servers,
33-
test_resource_servers_attributes
34+
test_resource_servers_attributes,
35+
test_invalid_oauth_providers_endpoint_params,
36+
test_without_oauth_providers_with_endpoint_params
3437

3538
].
3639

@@ -46,6 +49,14 @@ test_without_endpoint_params(_) ->
4649
#{} = translate_endpoint_params("token_endpoint_params", []),
4750
#{} = translate_endpoint_params("authorization_endpoint_params", []).
4851

52+
test_with_invalid_endpoint_params(_) ->
53+
try translate_endpoint_params("discovery_endpoint_params", [
54+
{["auth_oauth2","discovery_endpoint_params"], "some-value1"}]) of
55+
_ -> {throw, should_have_failed}
56+
catch
57+
_ -> ok
58+
end.
59+
4960
test_with_endpoint_params(_) ->
5061
Conf = [
5162
{["auth_oauth2","discovery_endpoint_params","param1"], "some-value1"},
@@ -60,6 +71,30 @@ test_with_endpoint_params(_) ->
6071
#{ <<"resource">> := <<"some-resource">>} =
6172
translate_endpoint_params("authorization_endpoint_params", Conf).
6273

74+
test_invalid_oauth_providers_endpoint_params() ->
75+
try oauth2_schema:translate_oauth_providers([
76+
{["auth_oauth2","oauth_providers", "X", "discovery_endpoint_params"], ""}]) of
77+
_ -> {throw, should_have_failed}
78+
catch
79+
_ -> ok
80+
end.
81+
test_without_oauth_providers_with_endpoint_params(_) ->
82+
Conf = [
83+
{["auth_oauth2","oauth_providers", "A", "discovery_endpoint_params","param1"], "some-value1"},
84+
{["auth_oauth2","oauth_providers", "A", "discovery_endpoint_params","param2"], "some-value2"},
85+
{["auth_oauth2","oauth_providers", "B", "token_endpoint_params","audience"], "some-audience"},
86+
{["auth_oauth2","oauth_providers", "C", "authorization_endpoint_params","resource"], "some-resource"}
87+
],
88+
89+
#{
90+
<<"A">> := [{discovery_endpoint_params,
91+
#{ <<"param1">> := <<"some-value1">>, <<"param2">> := <<"some-value2">> }}],
92+
<<"B">> := [{token_endpoint_params,
93+
#{ <<"audience">> := <<"some-audience">>}}],
94+
<<"C">> := [{authorization_endpoint_params,
95+
#{ <<"resource">> := <<"some-resource">>}}]
96+
} = translate_oauth_providers(Conf).
97+
6398
test_with_one_oauth_provider(_) ->
6499
Conf = [{["auth_oauth2","oauth_providers","keycloak","issuer"],"https://rabbit"}
65100
],

0 commit comments

Comments
 (0)