@@ -19,8 +19,12 @@ all() ->
19
19
test_validate_payload_resource_server_id_mismatch ,
20
20
test_validate_payload_with_scope_prefix ,
21
21
test_validate_payload ,
22
+ test_validate_payload_without_scope ,
22
23
test_validate_payload_when_verify_aud_false ,
23
24
test_successful_access_with_a_token ,
25
+ test_successful_authentication_without_scopes ,
26
+ test_successful_authorization_without_scopes ,
27
+ test_unsuccessful_access_without_scopes ,
24
28
test_successful_access_with_a_token_with_variables_in_scopes ,
25
29
test_successful_access_with_a_parsed_token ,
26
30
test_successful_access_with_a_token_that_has_tag_scopes ,
@@ -609,6 +613,30 @@ post_process_payload_with_complex_claim_authorization(Authorization) ->
609
613
{true , Payload } = uaa_jwt_jwt :decode_and_verify (Jwk , EncodedToken ),
610
614
rabbit_auth_backend_oauth2 :post_process_payload (Payload ).
611
615
616
+ test_successful_authentication_without_scopes (_ ) ->
617
+ Jwk = ? UTIL_MOD :fixture_jwk (),
618
+ UaaEnv = [{signing_keys , #{<<" token-key" >> => {map , Jwk }}}],
619
+ application :set_env (rabbitmq_auth_backend_oauth2 , key_config , UaaEnv ),
620
+ application :set_env (rabbitmq_auth_backend_oauth2 , resource_server_id , <<" rabbitmq" >>),
621
+
622
+ Username = <<" username" >>,
623
+ Token = ? UTIL_MOD :sign_token_hs (? UTIL_MOD :token_with_sub (? UTIL_MOD :fixture_token (), Username ), Jwk ),
624
+
625
+ {ok , # auth_user {username = Username } } =
626
+ rabbit_auth_backend_oauth2 :user_login_authentication (Username , [{password , Token }]).
627
+
628
+ test_successful_authorization_without_scopes (_ ) ->
629
+ Jwk = ? UTIL_MOD :fixture_jwk (),
630
+ UaaEnv = [{signing_keys , #{<<" token-key" >> => {map , Jwk }}}],
631
+ application :set_env (rabbitmq_auth_backend_oauth2 , key_config , UaaEnv ),
632
+ application :set_env (rabbitmq_auth_backend_oauth2 , resource_server_id , <<" rabbitmq" >>),
633
+
634
+ Username = <<" username" >>,
635
+ Token = ? UTIL_MOD :sign_token_hs (? UTIL_MOD :token_with_sub (? UTIL_MOD :fixture_token (), Username ), Jwk ),
636
+
637
+ {ok , _ } =
638
+ rabbit_auth_backend_oauth2 :user_login_authorization (Username , [{password , Token }]).
639
+
612
640
test_successful_access_with_a_token (_ ) ->
613
641
% % Generate a token with JOSE
614
642
% % Check authorization with the token
@@ -980,6 +1008,21 @@ test_unsuccessful_access_with_a_bogus_token(_) ->
980
1008
? assertMatch ({refused , _ , _ },
981
1009
rabbit_auth_backend_oauth2 :user_login_authentication (Username , [{password , <<" not a token" >>}])).
982
1010
1011
+ test_unsuccessful_access_without_scopes (_ ) ->
1012
+ Username = <<" username" >>,
1013
+ application :set_env (rabbitmq_auth_backend_oauth2 , resource_server_id , <<" rabbitmq" >>),
1014
+
1015
+ Jwk = ? UTIL_MOD :fixture_jwk (),
1016
+ Token = ? UTIL_MOD :sign_token_hs (? UTIL_MOD :token_with_sub (? UTIL_MOD :token_without_scopes (), Username ), Jwk ),
1017
+ UaaEnv = [{signing_keys , #{<<" token-key" >> => {map , Jwk }}}],
1018
+ application :set_env (rabbitmq_auth_backend_oauth2 , key_config , UaaEnv ),
1019
+
1020
+ {ok , # auth_user {username = Username , tags = [], impl = CredentialsFun } = AuthUser } =
1021
+ rabbit_auth_backend_oauth2 :user_login_authentication (Username , [{password , Token }]),
1022
+
1023
+ ct :log (" authuser ~p ~p " , [AuthUser , CredentialsFun ()]),
1024
+ assert_vhost_access_denied (AuthUser , <<" vhost" >>).
1025
+
983
1026
test_restricted_vhost_access_with_a_valid_token (_ ) ->
984
1027
Username = <<" username" >>,
985
1028
application :set_env (rabbitmq_auth_backend_oauth2 , resource_server_id , <<" rabbitmq" >>),
@@ -1277,6 +1320,12 @@ test_validate_payload(_) ->
1277
1320
<<" scope" >> => [<<" bar" >>, <<" other.third" >>]}},
1278
1321
rabbit_auth_backend_oauth2 :validate_payload (KnownResourceServerId , ? RESOURCE_SERVER_ID , ? DEFAULT_SCOPE_PREFIX )).
1279
1322
1323
+ test_validate_payload_without_scope (_ ) ->
1324
+ KnownResourceServerId = #{<<" aud" >> => [? RESOURCE_SERVER_ID ]
1325
+ },
1326
+ ? assertEqual ({ok , #{<<" aud" >> => [? RESOURCE_SERVER_ID ] }},
1327
+ rabbit_auth_backend_oauth2 :validate_payload (KnownResourceServerId , ? RESOURCE_SERVER_ID , ? DEFAULT_SCOPE_PREFIX )).
1328
+
1280
1329
test_validate_payload_when_verify_aud_false (_ ) ->
1281
1330
WithoutAud = #{
1282
1331
<<" scope" >> => [<<" foo" >>, <<" rabbitmq.bar" >>,
0 commit comments