Refactor more test cases and add new ones
This commit is contained in:
parent
1f11349060
commit
ee7fb32e7e
|
|
@ -99,11 +99,13 @@ authSettings() ->
|
|||
_ -> case skip_unknown_resource_servers(OAuthResourceServers) of
|
||||
Map when map_size(Map) == 0 ->
|
||||
rabbit_log:error("Empty or unknown set of rabbitmq_management oauth_resource_servers"),
|
||||
ct:log("exit1"),
|
||||
[{oauth_enabled, false}];
|
||||
Map -> multi_resource_auth_settings(Map)
|
||||
end
|
||||
end;
|
||||
false ->
|
||||
ct:log("exit0"),
|
||||
[{oauth_enabled, false}]
|
||||
end.
|
||||
%% Ensure each resource has a client_id or there is a top level some_client_id
|
||||
|
|
@ -156,12 +158,14 @@ single_resource_auth_settings() ->
|
|||
case is_invalid([OAuthResourceId]) of
|
||||
true ->
|
||||
rabbit_log:error("Invalid rabbitmq_auth_backend_oauth2.resource_server_id ~p", [OAuthResourceId]),
|
||||
ct:log("exit3"),
|
||||
[{oauth_enabled, false}];
|
||||
false ->
|
||||
case is_invalid([OAuthClientId, OAuthProviderUrl]) of
|
||||
true ->
|
||||
rabbit_log:error("Invalid rabbitmq_management oauth_client_id ~p or resolved oauth_provider_url ~p",
|
||||
[OAuthResourceId, OAuthProviderUrl]),
|
||||
ct:log("Invalid rabbitmq_management oauth_client_id ~p or resolved oauth_provider_url ~p",
|
||||
[OAuthClientId, OAuthProviderUrl]),
|
||||
ct:log("exit4"),
|
||||
[{oauth_enabled, false}];
|
||||
false ->
|
||||
append_oauth_optional([
|
||||
|
|
@ -179,11 +183,13 @@ single_resource_auth_settings() ->
|
|||
case is_invalid([OAuthResourceId]) of
|
||||
true ->
|
||||
rabbit_log:error("Invalid rabbitmq_auth_backend_oauth2.resource_server_id ~p", [OAuthResourceId]),
|
||||
ct:log("exit5"),
|
||||
[{oauth_enabled, false}];
|
||||
false ->
|
||||
case is_invalid([OAuthProviderUrl]) of
|
||||
true ->
|
||||
rabbit_log:error("Invalid rabbitmq_management resolved oauth_provider_url ~p", [OAuthProviderUrl]),
|
||||
ct:log("exit6"),
|
||||
[{oauth_enabled, false}];
|
||||
false ->
|
||||
[{oauth_enabled, true},
|
||||
|
|
|
|||
|
|
@ -21,23 +21,32 @@ all() ->
|
|||
|
||||
groups() ->
|
||||
[
|
||||
{without_any_settings, [], {
|
||||
{without_any_settings, [], [
|
||||
should_return_disabled_auth_settings
|
||||
}},
|
||||
{with_oauth_disabled, [], {
|
||||
]},
|
||||
{with_oauth_disabled, [], [
|
||||
should_return_disabled_auth_settings
|
||||
}},
|
||||
{with_oauth_enabled, [], {
|
||||
]},
|
||||
{with_oauth_enabled, [], [
|
||||
should_return_disabled_auth_settings,
|
||||
{with_resource_server_id, [], {
|
||||
{with_client_id, [], {
|
||||
{with_resource_server_id, [], [
|
||||
{with_client_id, [], [
|
||||
should_return_disabled_auth_settings,
|
||||
{with_mgt_aouth_provider_url, [], {
|
||||
should_return_enabled_auth_settings
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
{with_root_issuer, [], [
|
||||
should_return_enabled_auth_settings_sp_initiated_logon,
|
||||
{with_mgt_aouth_provider_url, [], [
|
||||
should_return_enabled_auth_settings_sp_initiated_logon
|
||||
]}
|
||||
]},
|
||||
{with_mgt_aouth_provider_url, [], [
|
||||
should_return_enabled_auth_settings_sp_initiated_logon,
|
||||
{with_idp_initiated_logon, [], [
|
||||
should_return_enabled_auth_settings_idp_initiated_logon
|
||||
]}
|
||||
]}
|
||||
]}
|
||||
]}
|
||||
]}
|
||||
].
|
||||
|
||||
%% -------------------------------------------------------------------
|
||||
|
|
@ -45,7 +54,7 @@ groups() ->
|
|||
%% -------------------------------------------------------------------
|
||||
init_per_suite(Config) ->
|
||||
[ {resource_server_id, <<"rabbitmq">>},
|
||||
{client_id, <<"rabbitmq_client">>},
|
||||
{oauth_client_id, <<"rabbitmq_client">>},
|
||||
{oauth_scopes, <<>>},
|
||||
{oauth_disable_basic_auth, true} | Config].
|
||||
|
||||
|
|
@ -60,14 +69,20 @@ init_per_group(with_oauth_enabled, Config) ->
|
|||
Config;
|
||||
|
||||
init_per_group(with_resource_server_id, Config) ->
|
||||
application:set_env(rabbitmq_management, resource_server_id, ?config(resource_server_id, Config)),
|
||||
application:set_env(rabbitmq_auth_backend_oauth2, resource_server_id, ?config(resource_server_id, Config)),
|
||||
Config;
|
||||
init_per_group(with_client_id, Config) ->
|
||||
application:set_env(rabbitmq_management, client_id, ?config(client_id, Config)),
|
||||
application:set_env(rabbitmq_management, oauth_client_id, ?config(oauth_client_id, Config)),
|
||||
Config;
|
||||
init_per_group(with_mgt_aouth_provider_url, Config) ->
|
||||
application:set_env(rabbitmq_management, oauth_provider_url, <<"http://oauth_provider_url">>),
|
||||
[ {oauth_provider_url, <<"http://oauth_provider_url">>} | Config];
|
||||
init_per_group(with_root_issuer, Config) ->
|
||||
application:set_env(rabbitmq_auth_backend_oauth2, issuer, <<"http://issuer">>),
|
||||
[ {oauth_provider_url, <<"http://issuer">>} | Config];
|
||||
init_per_group(with_idp_initiated_logon, Config) ->
|
||||
application:set_env(rabbitmq_management, oauth_initiated_logon_type, idp_initiated),
|
||||
[ {oauth_initiated_logon_type, idp_initiated} | Config];
|
||||
|
||||
init_per_group(_, Config) ->
|
||||
Config.
|
||||
|
|
@ -79,35 +94,25 @@ end_per_group(with_oauth_enabled, Config) ->
|
|||
application:unset_env(rabbitmq_management, oauth_enabled),
|
||||
Config;
|
||||
end_per_group(with_resource_server_id, Config) ->
|
||||
application:unset_env(rabbitmq_management, resource_server_id),
|
||||
application:unset_env(rabbitmq_auth_backend_oauth2, resource_server_id),
|
||||
Config;
|
||||
end_per_group(with_mgt_aouth_provider_url, Config) ->
|
||||
application:unset_env(rabbitmq_management, oauth_provider_url),
|
||||
Config;
|
||||
end_per_group(with_root_issuer, Config) ->
|
||||
application:unset_env(rabbitmq_auth_backend_oauth2, issuer);
|
||||
|
||||
end_per_group(with_client_id, Config) ->
|
||||
application:unset_env(rabbitmq_management, client_id),
|
||||
application:unset_env(rabbitmq_management, oauth_client_id),
|
||||
Config;
|
||||
end_per_group(with_idp_initiated_logon, Config) ->
|
||||
application:set_env(rabbitmq_management, oauth_initiated_logon_type, idp_initiated),
|
||||
proplists:delete(oauth_initiated_logon_type, Config);
|
||||
|
||||
end_per_group(_, Config) ->
|
||||
Config.
|
||||
|
||||
|
||||
|
||||
init_per_testcase(_, Config) ->
|
||||
case application:get_all_env(rabbitmq_management) of
|
||||
{error, _} = Error -> Error;
|
||||
Env ->
|
||||
lists:foreach(fun({Key,_Value})->
|
||||
application:unset_env(rabbitmq_management, Key) end, Env),
|
||||
case application:get_all_env(rabbitmq_auth_backend_oauth2) of
|
||||
{error, _} = Error -> Error;
|
||||
Env2 -> lists:foreach(fun({Key,_Value})->
|
||||
application:unset_env(rabbitmq_auth_backend_oauth2, Key) end, Env2)
|
||||
end
|
||||
end,
|
||||
Config.
|
||||
|
||||
|
||||
|
||||
%% -------------------------------------------------------------------
|
||||
%% Test cases.
|
||||
%% -------------------------------------------------------------------
|
||||
|
|
@ -115,19 +120,34 @@ init_per_testcase(_, Config) ->
|
|||
should_return_disabled_auth_settings(_Config) ->
|
||||
[{oauth_enabled, false}] = rabbit_mgmt_wm_auth:authSettings().
|
||||
|
||||
should_return_enabled_auth_settings(Config) ->
|
||||
should_return_enabled_auth_settings_sp_initiated_logon(Config) ->
|
||||
ClientId = ?config(oauth_client_id, Config),
|
||||
ProviderUrl = ?config(oauth_provider_url, Config),
|
||||
ResourceId = ?config(resource_server_id, Config),
|
||||
Scopes = ?config(oauth_scopes, Config),
|
||||
ct:log("rabbitmq_management : ~p", [application:get_all_env(rabbitmq_management)]),
|
||||
ct:log("rabbitmq_auth_backend_oauth2 : ~p", [application:get_all_env(rabbitmq_auth_backend_oauth2)]),
|
||||
[
|
||||
{oauth_enabled, true},
|
||||
{oauth_disable_basic_auth, true},
|
||||
{oauth_client_id, ClientId},
|
||||
{oauth_provider_url, ProviderUrl},
|
||||
{oauth_resource_id, ResourceId},
|
||||
{oauth_scopes, Scopes},
|
||||
{oauth_metadata_url, <<>>}
|
||||
{oauth_metadata_url, <<>>},
|
||||
{oauth_resource_id, ResourceId}
|
||||
] = rabbit_mgmt_wm_auth:authSettings().
|
||||
|
||||
should_return_enabled_auth_settings_idp_initiated_logon(Config) ->
|
||||
ProviderUrl = ?config(oauth_provider_url, Config),
|
||||
ResourceId = ?config(resource_server_id, Config),
|
||||
ct:log("rabbitmq_management : ~p", [application:get_all_env(rabbitmq_management)]),
|
||||
ct:log("rabbitmq_auth_backend_oauth2 : ~p", [application:get_all_env(rabbitmq_auth_backend_oauth2)]),
|
||||
[
|
||||
{oauth_enabled, true},
|
||||
{oauth_disable_basic_auth, true},
|
||||
{oauth_initiated_logon_type, <<"idp_initiated">>},
|
||||
{oauth_provider_url, ProviderUrl},
|
||||
{oauth_resource_id, ResourceId}
|
||||
] = rabbit_mgmt_wm_auth:authSettings().
|
||||
|
||||
auth_settings_with_oauth_enabled(_Config) ->
|
||||
|
|
@ -144,18 +164,6 @@ auth_settings_with_oauth_enabled(_Config) ->
|
|||
{oauth_resource_id,<<"some_id">>}
|
||||
] = rabbit_mgmt_wm_auth:authSettings().
|
||||
|
||||
auth_settings_with_oauth_disabled_due_to_misconfig(_Config) ->
|
||||
application:set_env(rabbitmq_management, oauth_enabled, true),
|
||||
[{oauth_enabled, false}] = rabbit_mgmt_wm_auth:authSettings(),
|
||||
|
||||
application:set_env(rabbitmq_management, oauth_client_id, "some_id"),
|
||||
application:set_env(rabbitmq_management, oauth_resource_id, "some_resource_id"),
|
||||
[{oauth_enabled, false}] = rabbit_mgmt_wm_auth:authSettings(),
|
||||
|
||||
application:unset_env(rabbitmq_management, oauth_client_id),
|
||||
application:set_env(rabbitmq_management, oauth_provider_url, "http://localhost"),
|
||||
[{oauth_enabled, false}] = rabbit_mgmt_wm_auth:authSettings().
|
||||
|
||||
auth_settings_with_idp_initiated(_Config) ->
|
||||
application:set_env(rabbitmq_management, oauth_enabled, true),
|
||||
application:set_env(rabbitmq_management, oauth_initiated_logon_type, idp_initiated),
|
||||
|
|
|
|||
Loading…
Reference in New Issue