Skip to content

Commit

Permalink
Verify multi providers + end_session_endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcialRosales committed May 23, 2024
1 parent 9fef822 commit ad023f6
Showing 1 changed file with 69 additions and 2 deletions.
71 changes: 69 additions & 2 deletions deps/rabbitmq_management/test/rabbit_mgmt_wm_auth_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ all() ->
{group, verify_mgt_oauth_provider_url_with_single_resource},
{group, verify_mgt_oauth_provider_url_with_single_resource_and_another_resource},
{group, verify_end_session_endpoint_with_single_resource},
{group, verify_end_session_endpoint_with_single_resource_and_another_resource},
{group, verify_oauth_initiated_logon_type_for_sp_initiated},
{group, verify_oauth_initiated_logon_type_for_idp_initiated},
{group, verify_oauth_disable_basic_auth},
Expand Down Expand Up @@ -129,6 +130,38 @@ groups() ->
]}
]}
]},
{verify_end_session_endpoint_with_single_resource_and_another_resource, [], [
{with_resource_server_id_rabbit, [], [
{with_resource_server_a, [], [
{with_root_issuer_url1, [], [
{with_oauth_enabled, [], [
should_return_disabled_auth_settings,
{with_mgt_oauth_client_id_z, [], [
should_not_return_end_session_endpoint,
should_return_oauth_resource_server_a_without_end_session_endpoint,
{with_root_end_session_endpoint_0, [], [
should_return_end_session_endpoint_0,
should_return_oauth_resource_server_a_with_end_session_endpoint_0
]},
{with_oauth_providers_idp1_idp2, [], [
{with_default_oauth_provider_idp1, [], [
{with_end_session_endpoint_for_idp1_1, [], [
should_return_end_session_endpoint_1,
should_return_oauth_resource_server_a_with_end_session_endpoint_1,
{with_oauth_provider_idp2_for_resource_server_a, [], [
{with_end_session_endpoint_for_idp2_2, [], [
should_return_oauth_resource_server_a_with_end_session_endpoint_2
]}
]}
]}
]}
]}
]}
]}
]}
]}
]}
]},
{verify_mgt_oauth_provider_url_with_single_resource_and_another_resource, [], [
{with_resource_server_id_rabbit, [], [
{with_resource_server_a, [], [
Expand Down Expand Up @@ -272,6 +305,7 @@ init_per_suite(Config) ->
{url1, <<"https://url1">>},
{logout_url_0, <<"https://logout_0">>},
{logout_url_1, <<"https://logout_1">>},
{logout_url_2, <<"https://logout_2">>},
{a, <<"a">>},
{b, <<"b">>},
{q, <<"q">>},
Expand Down Expand Up @@ -371,6 +405,15 @@ init_per_group(with_end_session_endpoint_for_idp1_1, Config) ->
set_attribute_in_entry_for_env_variable(rabbitmq_auth_backend_oauth2, oauth_providers,
?config(idp1, Config), end_session_endpoint, ?config(logout_url_1, Config)),
Config;
init_per_group(with_end_session_endpoint_for_idp2_2, Config) ->
set_attribute_in_entry_for_env_variable(rabbitmq_auth_backend_oauth2, oauth_providers,
?config(idp2, Config), end_session_endpoint, ?config(logout_url_2, Config)),
Config;

init_per_group(with_oauth_provider_idp2_for_resource_server_a, Config) ->
set_attribute_in_entry_for_env_variable(rabbitmq_auth_backend_oauth2, resource_servers,
?config(a, Config), oauth_provider_id, ?config(idp2, Config)),
Config;

init_per_group(_, Config) ->
Config.
Expand Down Expand Up @@ -459,6 +502,15 @@ end_per_group(with_end_session_endpoint_for_idp1_1, Config) ->
remove_attribute_from_entry_from_env_variable(rabbitmq_auth_backend_oauth2, oauth_providers,
?config(idp1, Config), end_session_endpoint),
Config;
end_per_group(with_end_session_endpoint_for_idp2_2, Config) ->
remove_attribute_from_entry_from_env_variable(rabbitmq_auth_backend_oauth2, oauth_providers,
?config(idp2, Config), end_session_endpoint),
Config;
end_per_group(with_oauth_provider_idp2_for_resource_server_a, Config) ->
remove_attribute_from_entry_from_env_variable(rabbitmq_auth_backend_oauth2, resource_servers,
?config(a, Config), oauth_provider_id),
Config;

end_per_group(_, Config) ->
Config.

Expand Down Expand Up @@ -589,15 +641,28 @@ should_not_return_end_session_endpoint(Config) ->
Config, rabbit, end_session_endpoint).

should_return_end_session_endpoint_0(Config) ->
ct:log("settings: ~p", [rabbit_mgmt_wm_auth:authSettings()]),
assertEqual_on_attribute_for_oauth_resource_server(rabbit_mgmt_wm_auth:authSettings(),
Config, rabbit, end_session_endpoint, ?config(logout_url_0, Config)).

should_return_end_session_endpoint_1(Config) ->
ct:log("settings: ~p", [rabbit_mgmt_wm_auth:authSettings()]),
assertEqual_on_attribute_for_oauth_resource_server(rabbit_mgmt_wm_auth:authSettings(),
Config, rabbit, end_session_endpoint, ?config(logout_url_1, Config)).

should_return_oauth_resource_server_a_without_end_session_endpoint(Config) ->
assert_attribute_not_defined_for_oauth_resource_server(rabbit_mgmt_wm_auth:authSettings(),
Config, a, end_session_endpoint).

should_return_oauth_resource_server_a_with_end_session_endpoint_0(Config) ->
assertEqual_on_attribute_for_oauth_resource_server(rabbit_mgmt_wm_auth:authSettings(),
Config, a, end_session_endpoint, ?config(logout_url_0, Config)).

should_return_oauth_resource_server_a_with_end_session_endpoint_1(Config) ->
assertEqual_on_attribute_for_oauth_resource_server(rabbit_mgmt_wm_auth:authSettings(),
Config, a, end_session_endpoint, ?config(logout_url_1, Config)).

should_return_oauth_resource_server_a_with_end_session_endpoint_2(Config) ->
assertEqual_on_attribute_for_oauth_resource_server(rabbit_mgmt_wm_auth:authSettings(),
Config, a, end_session_endpoint, ?config(logout_url_2, Config)).

%% -------------------------------------------------------------------
%% Utility/helper functions
Expand Down Expand Up @@ -647,7 +712,9 @@ assert_not_defined_oauth_resource_server(Actual, Config, ConfigKey) ->

set_attribute_in_entry_for_env_variable(Application, EnvVar, Key, Attribute, Value) ->
Map = application:get_env(Application, EnvVar, #{}),
ct:log("set_attribute_in_entry_for_env_variable before ~p", [Map]),
Map1 = maps:put(Key, [ { Attribute, Value} | maps:get(Key, Map, []) ], Map),
ct:log("set_attribute_in_entry_for_env_variable after ~p", [Map1]),
application:set_env(Application, EnvVar, Map1).

log(AuthSettings) ->
Expand Down

0 comments on commit ad023f6

Please sign in to comment.