diff options
author | Marcial Rosales <mrosales@pivotal.io> | 2023-04-26 13:43:29 +0200 |
---|---|---|
committer | Marcial Rosales <mrosales@pivotal.io> | 2023-04-26 13:43:29 +0200 |
commit | 0d9867cde2cfa4081f7ba29f97c5934dd09bd648 (patch) | |
tree | 8641962f747a44ae5c8a09601f70fafb5874d69e | |
parent | fcd8a17ea681125422a40896a548ed836df6b0a7 (diff) | |
download | rabbitmq-server-git-configurable-oauth2-scope-prefix.tar.gz |
Test scope prefix within scope alias mappingconfigurable-oauth2-scope-prefix
-rw-r--r-- | deps/rabbitmq_auth_backend_oauth2/test/unit_SUITE.erl | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/deps/rabbitmq_auth_backend_oauth2/test/unit_SUITE.erl b/deps/rabbitmq_auth_backend_oauth2/test/unit_SUITE.erl index e9d775bf90..3d47146a3a 100644 --- a/deps/rabbitmq_auth_backend_oauth2/test/unit_SUITE.erl +++ b/deps/rabbitmq_auth_backend_oauth2/test/unit_SUITE.erl @@ -40,6 +40,7 @@ all() -> test_post_process_token_payload_complex_claims, test_successful_access_with_a_token_that_uses_single_scope_alias_in_scope_field, test_successful_access_with_a_token_that_uses_multiple_scope_aliases_in_scope_field, + test_successful_access_with_a_token_that_uses_single_scope_alias_in_scope_field_and_custom_scope_prefix, test_unsuccessful_access_with_a_token_that_uses_missing_scope_alias_in_scope_field, test_successful_access_with_a_token_that_uses_single_scope_alias_in_extra_scope_source_field, test_successful_access_with_a_token_that_uses_multiple_scope_aliases_in_extra_scope_source_field, @@ -721,6 +722,49 @@ test_successful_access_with_a_token_that_uses_single_scope_alias_in_scope_field( application:unset_env(rabbitmq_auth_backend_oauth2, key_config), application:unset_env(rabbitmq_auth_backend_oauth2, resource_server_id). + +test_successful_access_with_a_token_that_uses_single_scope_alias_in_scope_field_and_custom_scope_prefix(_) -> + Jwk = ?UTIL_MOD:fixture_jwk(), + UaaEnv = [{signing_keys, #{<<"token-key">> => {map, Jwk}}}], + application:set_env(rabbitmq_auth_backend_oauth2, key_config, UaaEnv), + application:set_env(rabbitmq_auth_backend_oauth2, resource_server_id, <<"rabbitmq">>), + application:set_env(rabbitmq_auth_backend_oauth2, scope_prefix, <<>>), + Alias = <<"client-alias-1">>, + application:set_env(rabbitmq_auth_backend_oauth2, scope_aliases, #{ + Alias => [ + <<"configure:vhost/one">>, + <<"write:vhost/two">>, + <<"read:vhost/one">>, + <<"read:vhost/two">>, + <<"read:vhost/two/abc">>, + <<"tag:management">>, + <<"tag:custom">> + ] + }), + + VHost = <<"vhost">>, + Username = <<"username">>, + Token = ?UTIL_MOD:sign_token_hs(?UTIL_MOD:token_with_sub( + ?UTIL_MOD:token_with_scope_alias_in_scope_field(Alias), Username), Jwk), + + {ok, #auth_user{username = Username, tags = [custom, management]} = AuthUser} = + rabbit_auth_backend_oauth2:user_login_authentication(Username, [{password, Token}]), + assert_vhost_access_granted(AuthUser, VHost), + assert_vhost_access_denied(AuthUser, <<"some-other-vhost">>), + + assert_resource_access_granted(AuthUser, VHost, <<"one">>, configure), + assert_resource_access_granted(AuthUser, VHost, <<"one">>, read), + assert_resource_access_granted(AuthUser, VHost, <<"two">>, read), + assert_resource_access_granted(AuthUser, VHost, <<"two">>, write), + assert_resource_access_denied(AuthUser, VHost, <<"three">>, configure), + assert_resource_access_denied(AuthUser, VHost, <<"three">>, read), + assert_resource_access_denied(AuthUser, VHost, <<"three">>, write), + + application:unset_env(rabbitmq_auth_backend_oauth2, scope_aliases), + application:unset_env(rabbitmq_auth_backend_oauth2, key_config), + application:unset_env(rabbitmq_auth_backend_oauth2, scope_prefix), + application:unset_env(rabbitmq_auth_backend_oauth2, resource_server_id). + test_successful_access_with_a_token_that_uses_multiple_scope_aliases_in_scope_field(_) -> Jwk = ?UTIL_MOD:fixture_jwk(), UaaEnv = [{signing_keys, #{<<"token-key">> => {map, Jwk}}}], @@ -1216,7 +1260,7 @@ test_validate_payload_with_scope_prefix(_) -> <<"scope">> => [<<"some-prefix::foo">>, <<"foo.bar">>, <<"some-prefix::other.third">> ]}, [<<"foo">>, <<"other.third">>] } - + ], lists:map(fun({ ScopePrefix, Token, ExpectedScopes}) -> |