summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcial Rosales <mrosales@pivotal.io>2023-04-26 13:43:29 +0200
committerMarcial Rosales <mrosales@pivotal.io>2023-05-16 08:40:29 +0200
commit1cd84b36ec127d462f0ee1321636ff9f7dd0b22f (patch)
tree504008906ed8b61ec4823b79fb85dec213b33b0d
parentea4074c1dfc704c40ff9007bb9b692bd52a9c3f0 (diff)
downloadrabbitmq-server-git-1cd84b36ec127d462f0ee1321636ff9f7dd0b22f.tar.gz
Test scope prefix within scope alias mapping
-rw-r--r--deps/rabbitmq_auth_backend_oauth2/test/unit_SUITE.erl46
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}) ->