1212
1313-include_lib (" oauth2_client.hrl" ).
1414-import (oauth2_client , [
15- build_openid_discovery_endpoint /3 ]).
15+ build_openid_discovery_endpoint /3
16+ ]).
1617
1718-compile (export_all ).
1819
@@ -27,8 +28,7 @@ all() ->
2728[
2829 {group , https_down },
2930 {group , https },
30- {group , with_all_oauth_provider_settings },
31- {group , without_all_oauth_providers_settings }
31+ {group , with_all_oauth_provider_settings }
3232
3333].
3434
@@ -83,10 +83,14 @@ init_per_suite(Config) ->
8383 [
8484 {jwks_url , build_jwks_uri (" https" , " /certs4url" )},
8585 {jwks_uri , build_jwks_uri (" https" )},
86- {denies_access_token , [ {token_endpoint , denies_access_token_expectation ()} ]},
87- {auth_server_error , [ {token_endpoint , auth_server_error_when_access_token_request_expectation ()} ]},
88- {non_json_payload , [ {token_endpoint , non_json_payload_when_access_token_request_expectation ()} ]},
89- {grants_refresh_token , [ {token_endpoint , grants_refresh_token_expectation ()} ]}
86+ {denies_access_token , [
87+ {token_endpoint , denies_access_token_expectation ()} ]},
88+ {auth_server_error , [
89+ {token_endpoint , auth_server_error_when_access_token_request_expectation ()} ]},
90+ {non_json_payload , [
91+ {token_endpoint , non_json_payload_when_access_token_request_expectation ()} ]},
92+ {grants_refresh_token , [
93+ {token_endpoint , grants_refresh_token_expectation ()} ]}
9094 | Config ].
9195
9296end_per_suite (Config ) ->
@@ -234,7 +238,7 @@ configure_all_oauth_provider_settings(Config) ->
234238 application :set_env (rabbitmq_auth_backend_oauth2 , key_config , KeyConfig ).
235239
236240configure_minimum_oauth_provider_settings (Config ) ->
237- OAuthProvider = ? config (oauth_provider_with_issuer , Config ),
241+ OAuthProvider = ? config (oauth_provider , Config ),
238242 OAuthProviders = #{ ? config (oauth_provider_id , Config ) =>
239243 oauth_provider_to_proplist (OAuthProvider ) },
240244 application :set_env (rabbitmq_auth_backend_oauth2 , oauth_providers ,
@@ -279,6 +283,9 @@ init_per_testcase(TestCase, Config0) ->
279283 https ->
280284 start_https_oauth_server (? AUTH_PORT , ? config (rmq_certsdir , Config ),
281285 ListOfExpectations );
286+ without_all_oauth_providers_settings ->
287+ start_https_oauth_server (? AUTH_PORT , ? config (rmq_certsdir , Config ),
288+ ListOfExpectations );
282289 _ ->
283290 do_nothing
284291 end ,
@@ -295,6 +302,8 @@ end_per_testcase(_, Config) ->
295302 case ? config (group , Config ) of
296303 https ->
297304 stop_https_auth_server ();
305+ without_all_oauth_providers_settings ->
306+ stop_https_auth_server ();
298307 _ ->
299308 do_nothing
300309 end ,
@@ -504,9 +513,9 @@ verify_get_oauth_provider_returns_root_oauth_provider() ->
504513 token_endpoint = TokenEndPoint ,
505514 jwks_uri = Jwks_uri }} =
506515 oauth2_client :get_oauth_provider ([issuer , token_endpoint , jwks_uri ]),
507- ExpectedIssuer = application : get_env (rabbitmq_auth_backend_oauth2 , issuer , undefined ),
508- ExpectedTokenEndPoint = application : get_env (rabbitmq_auth_backend_oauth2 , token_endpoint , undefined ),
509- ExpectedJwks_uri = application : get_env (rabbitmq_auth_backend_oauth2 , jwks_uri , undefined ),
516+ ExpectedIssuer = get_env (issuer ),
517+ ExpectedTokenEndPoint = get_env (token_endpoint ),
518+ ExpectedJwks_uri = get_env (jwks_uri ),
510519 ? assertEqual (root , Id ),
511520 ? assertEqual (ExpectedIssuer , Issuer ),
512521 ? assertEqual (ExpectedTokenEndPoint , TokenEndPoint ),
@@ -523,7 +532,7 @@ verify_get_oauth_provider_returns_default_oauth_provider(DefaultOAuthProviderId)
523532get_oauth_provider (Config ) ->
524533 case ? config (with_all_oauth_provider_settings , Config ) of
525534 true ->
526- case application : get_env (rabbitmq_auth_backend_oauth2 , default_oauth_provider , undefined ) of
535+ case get_env (default_oauth_provider ) of
527536 undefined ->
528537 verify_get_oauth_provider_returns_root_oauth_provider ();
529538 DefaultOAuthProviderId ->
@@ -556,8 +565,7 @@ get_oauth_provider_given_oauth_provider_id(Config) ->
556565 [issuer , token_endpoint , jwks_uri , authorization_endpoint ,
557566 end_session_endpoint ]),
558567
559- OAuthProviders = application :get_env (rabbitmq_auth_backend_oauth2 ,
560- oauth_providers , #{}),
568+ OAuthProviders = get_env (oauth_providers , #{}),
561569 ExpectedProvider = maps :get (Id , OAuthProviders , []),
562570 ? assertEqual (proplists :get_value (issuer , ExpectedProvider ),
563571 Issuer ),
@@ -599,16 +607,13 @@ jwks_url_is_used_in_absense_of_jwks_uri(Config) ->
599607 {ok , # oauth_provider {
600608 jwks_uri = Jwks_uri }} = oauth2_client :get_oauth_provider ([jwks_uri ]),
601609 ? assertEqual (
602- proplists :get_value (jwks_url ,
603- application :get_env (rabbitmq_auth_backend_oauth2 , key_config , []), undefined ),
610+ proplists :get_value (jwks_url , get_env (key_config , []), undefined ),
604611 Jwks_uri ).
605612
606613jwks_uri_takes_precedence_over_jwks_url (Config ) ->
607614 {ok , # oauth_provider {
608615 jwks_uri = Jwks_uri }} = oauth2_client :get_oauth_provider ([jwks_uri ]),
609- ? assertEqual (
610- application :get_env (rabbitmq_auth_backend_oauth2 , jwks_uri , undefined ),
611- Jwks_uri ).
616+ ? assertEqual (get_env (jwks_uri ), Jwks_uri ).
612617
613618
614619% %% HELPERS
@@ -671,11 +676,11 @@ oauth_provider_to_proplist(#oauth_provider{
671676 authorization_endpoint = AuthorizationEndpoint ,
672677 ssl_options = SslOptions ,
673678 jwks_uri = Jwks_uri }) ->
674- [ { issuer , Issuer },
679+ [ { issuer , Issuer },
675680 {token_endpoint , TokenEndpoint },
676681 {end_session_endpoint , EndSessionEndpoint },
677682 {authorization_endpoint , AuthorizationEndpoint },
678- { https ,
683+ {https ,
679684 case SslOptions of
680685 undefined -> [];
681686 Value -> Value
@@ -725,6 +730,11 @@ token(ExpiresIn) ->
725730 EncodedToken .
726731
727732
733+ get_env (Par ) ->
734+ application :get_env (rabbitmq_auth_backend_oauth2 , Par , undefined ).
735+ get_env (Par , Default ) ->
736+ application :get_env (rabbitmq_auth_backend_oauth2 , Par , Default ).
737+
728738
729739build_http_mock_behaviour (Request , Response ) ->
730740 #{request => Request , response => Response }.
0 commit comments