Skip to content

Commit f0cd2ca

Browse files
Fix schema mapping issues
And location of cert files when running multioauth test suites locally
1 parent 2f1a878 commit f0cd2ca

File tree

7 files changed

+53
-34
lines changed

7 files changed

+53
-34
lines changed

deps/rabbitmq_management/src/rabbit_mgmt_schema.erl

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ extract_value({_Name,V}) -> V.
2121
translate_oauth_resource_servers(Conf) ->
2222
Settings = cuttlefish_variable:filter_by_prefix(
2323
"management.oauth_resource_servers", Conf),
24-
rabbit_log:debug("Settings: ~p", [Settings]),
2524
Map = merge_list_of_maps([
2625
extract_resource_server_properties(Settings),
2726
extract_resource_server_endpoint_params(oauth_authorization_endpoint_params, Settings),
@@ -45,23 +44,23 @@ merge_list_of_maps(ListOfMaps) ->
4544
lists:foldl(fun(Elem, AccIn) -> maps:merge_with(fun(_K,V1,V2) -> V1 ++ V2 end,
4645
Elem, AccIn) end, #{}, ListOfMaps).
4746

47+
convert_list_to_binary(V) when is_list(V) ->
48+
list_to_binary(V);
49+
convert_list_to_binary(V) ->
50+
V.
4851

4952
extract_resource_server_properties(Settings) ->
50-
KeyFun = fun extract_key/1,
53+
KeyFun = fun extract_key_as_binary/1,
5154
ValueFun = fun extract_value/1,
5255

53-
OAuthProviders = [{Name, {list_to_atom(Key), V}}
56+
OAuthResourceServers = [{Name, {list_to_atom(Key), convert_list_to_binary(V)}}
5457
|| {["management","oauth_resource_servers", Name, Key], V} <- Settings ],
55-
rabbit_log:debug("extract_resource_server_properties ~p", [Settings]),
56-
Result = maps:groups_from_list(KeyFun, ValueFun, OAuthProviders),
57-
rabbit_log:debug("extract_resource_server_properties -> ~p", [Result]),
58+
maps:groups_from_list(KeyFun, ValueFun, OAuthResourceServers).
5859

59-
Result.
6060

6161
extract_resource_server_endpoint_params(Variable, Settings) ->
62-
KeyFun = fun extract_key/1,
62+
KeyFun = fun extract_key_as_binary/1,
6363

64-
rabbit_log:debug("extract_resource_server_endpoint_params ~p ~p", [Variable, Settings]),
6564
IndexedParams = [{Name, {list_to_binary(ParamName), list_to_binary(V)}} ||
6665
{["management","oauth_resource_servers", Name, EndpointVar, ParamName], V}
6766
<- Settings, EndpointVar == atom_to_list(Variable) ],

deps/rabbitmq_management/src/rabbit_mgmt_wm_auth.erl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ extract_oauth2_and_mgt_resources(OAuth2BackendProps, ManagementProps) ->
8080
MgtResources = maps:map(
8181
fun(K,V) -> merge_oauth_provider_info(maps:get(K, OAuth2Resources, #{}), V, ManagementProps) end,
8282
skip_disabled_mgt_resource_servers(MgtResources1)),
83+
rabbit_log:debug("ManagementProps: ~p", [ManagementProps]),
84+
rabbit_log:debug("extract_oauth2_and_mgt_resources OAuth2Resources: ~p, MgtResources0: ~p MgtResources1: ~p MgtResources: ~p",
85+
[OAuth2Resources, MgtResources0, MgtResources1, MgtResources]),
8386
case maps:size(MgtResources) of
8487
0 -> {};
8588
_ -> {MgtResources}

deps/rabbitmq_management/test/config_schema_SUITE_data/rabbitmq_management.snippets

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@
636636
{oauth_scopes, "openid profile rabbitmq.*"},
637637
{oauth_initiated_logon_type, idp_initiated},
638638
{oauth_token_endpoint_params, [
639-
{"param2", <<"value2">>}
639+
{<<"param2">>, <<"value2">>}
640640
]}
641641
]}
642642
], [rabbitmq_management]
@@ -660,28 +660,28 @@
660660
{oauth_enabled, true},
661661
{oauth_resource_servers,
662662
#{
663-
"3" => [
664-
{oauth_provider_url, "http://three"},
663+
<<"3">> => [
664+
{oauth_provider_url, <<"http://three">>},
665665
{oauth_initiated_logon_type, idp_initiated},
666-
{id, "3"}
666+
{id, <<"3">>}
667667
],
668-
"resource-one" => [
668+
<<"resource-one">> => [
669669
{oauth_token_endpoint_params, [
670670
{<<"param2">>, <<"value2">>}
671671
]},
672-
{oauth_scopes, "openid profile rabbitmq.*"},
673-
{oauth_client_id, "one"},
674-
{label, "One"},
675-
{id, "resource-one"},
676-
{oauth_provider_url, "http://one:8080"}
672+
{oauth_scopes, <<"openid profile rabbitmq.*">>},
673+
{oauth_client_id, <<"one">>},
674+
{label, <<"One">>},
675+
{id, <<"resource-one">>},
676+
{oauth_provider_url, <<"http://one:8080">>}
677677
],
678-
"resource-two" => [
678+
<<"resource-two">> => [
679679
{oauth_authorization_endpoint_params, [
680680
{<<"param1">>, <<"value1">>}
681681
]},
682-
{oauth_client_id, "two"},
683-
{id, "resource-two"},
684-
{oauth_provider_url, "http://two"}
682+
{oauth_client_id, <<"two">>},
683+
{id, <<"resource-two">>},
684+
{oauth_provider_url, <<"http://two">>}
685685
]
686686
}
687687
}

deps/rabbitmq_management/test/rabbit_mgmt_schema_SUITE.erl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ test_with_one_resource_server(_) ->
4646
{["management","oauth_resource_servers","rabbitmq1","id"],"rabbitmq1"}
4747
],
4848
#{
49-
"rabbitmq1" := [
50-
{id, "rabbitmq1"}
49+
<<"rabbitmq1">> := [
50+
{id, <<"rabbitmq1">>}
5151
]
5252
} = translate_oauth_resource_servers(Conf).
5353

@@ -57,13 +57,13 @@ test_with_many_resource_servers(_) ->
5757
{["management","oauth_resource_servers","uaa","label"],"Uaa"}
5858
],
5959
#{
60-
"keycloak" := [
61-
{label, "Keycloak"},
62-
{id, "keycloak"}
60+
<<"keycloak">> := [
61+
{label, <<"Keycloak">>},
62+
{id, <<"keycloak">>}
6363
],
64-
"uaa" := [
65-
{label, "Uaa"},
66-
{id, "uaa"}
64+
<<"uaa">> := [
65+
{label, <<"Uaa">>},
66+
{id, <<"uaa">>}
6767
]
6868
} = translate_oauth_resource_servers(Conf).
6969

deps/rabbitmq_management/test/rabbit_mgmt_wm_auth_SUITE.erl

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ all() ->
2222
{group, verify_mgt_oauth_provider_url_with_single_resource_and_another_resource},
2323
{group, verify_end_session_endpoint_with_single_resource},
2424
{group, verify_end_session_endpoint_with_single_resource_and_another_resource},
25+
{group, verify_multi_resource_and_provider},
2526
{group, verify_oauth_initiated_logon_type_for_sp_initiated},
2627
{group, verify_oauth_initiated_logon_type_for_idp_initiated},
2728
{group, verify_oauth_disable_basic_auth},
@@ -31,6 +32,22 @@ all() ->
3132

3233
groups() ->
3334
[
35+
36+
{verify_multi_resource_and_provider, [], [
37+
{with_oauth_enabled, [], [
38+
{with_oauth_providers_idp1_idp2, [], [
39+
{with_default_oauth_provider_idp1, [], [
40+
{with_resource_server_a, [], [
41+
should_return_disabled_auth_settings,
42+
{with_mgt_resource_server_a_with_client_id_x, [], [
43+
should_return_oauth_enabled,
44+
should_return_oauth_resource_server_a_with_client_id_x
45+
]}
46+
]}
47+
]}
48+
]}
49+
]}
50+
]},
3451
{without_any_settings, [], [
3552
should_return_disabled_auth_settings
3653
]},
@@ -325,7 +342,6 @@ groups() ->
325342
{with_mgt_resource_server_a_with_token_endpoint_params_1, [], [
326343
should_return_mgt_oauth_resource_a_with_token_endpoint_params_1
327344
]}
328-
329345
]}
330346
]}
331347
]}
@@ -452,6 +468,7 @@ init_per_group(with_mgt_resource_server_a_with_client_id_x, Config) ->
452468
set_attribute_in_entry_for_env_variable(rabbitmq_management, oauth_resource_servers,
453469
?config(a, Config), oauth_client_id, ?config(x, Config)),
454470
Config;
471+
455472
init_per_group(with_default_oauth_provider_idp1, Config) ->
456473
set_env(rabbitmq_auth_backend_oauth2, default_oauth_provider, ?config(idp1, Config)),
457474
Config;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export DEVKEYCLOAK_URL=https://localhost:8442/realms/dev
2-
export DEVKEYCLOAK_CA_CERT=test/multi-oauth/devkeycloak/ca_certificate.pem
2+
export DEVKEYCLOAK_CA_CERT=${SELENIUM}/test/multi-oauth/devkeycloak/ca_certificate.pem
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export PRODKEYCLOAK_URL=https://localhost:8443/realms/prod
2-
export PRODKEYCLOAK_CA_CERT=test/multi-oauth/prodkeycloak/ca_certificate.pem
2+
export PRODKEYCLOAK_CA_CERT=${SELENIUM}/test/multi-oauth/prodkeycloak/ca_certificate.pem

0 commit comments

Comments
 (0)