@@ -54,8 +54,26 @@ groups() ->
5454 {with_introspection_request_param_client_credentials , [], [
5555 can_introspect_token
5656 ]}
57+ ]}
58+ ]},
59+ {https , [], [
60+ {with_introspection_basic_client_credentials , [], [
61+ cannot_introspect_due_to_missing_configuration
62+ ]},
63+ {with_introspection_request_param_client_credentials , [], [
64+ cannot_introspect_due_to_missing_configuration
5765 ]}
58-
66+ ]},
67+ {with_discovered_introspection_endpoint , [], [
68+ cannot_introspect_due_to_missing_configuration ,
69+ {https , [], [
70+ {with_introspection_basic_client_credentials , [], [
71+ can_introspect_token
72+ ]},
73+ {with_introspection_request_param_client_credentials , [], [
74+ can_introspect_token
75+ ]}
76+ ]}
5977 ]}
6078 ]}
6179 ]},
@@ -176,18 +194,26 @@ init_per_group(with_introspection_endpoint, Config) ->
176194 build_token_introspection_endpoint (" https" )),
177195 Config ;
178196
197+ init_per_group (with_discovered_introspection_endpoint , Config ) ->
198+ Payload1 = [ {? RESPONSE_INTROSPECTION_ENDPOINT , build_token_introspection_endpoint (" https" )} |
199+ build_http_get_openid_configuration_payload () ],
200+ [{expected_openid_configuration_payload , Payload1 } | Config ];
201+
179202init_per_group (with_introspection_basic_client_credentials , Config ) ->
180203 application :set_env (rabbitmq_auth_backend_oauth2 , introspection_client_id ,
181204 " some-client-id" ),
182205 application :set_env (rabbitmq_auth_backend_oauth2 , introspection_client_secret ,
183206 " some-client-secret" ),
184207 application :set_env (rabbitmq_auth_backend_oauth2 , introspection_client_auth_method ,
185- basic ),
208+ basic ),
186209 [{can_introspect_token , [
187210 {introspection_endpoint , build_http_mock_behaviour (
188211 build_introspection_token_request (? MOCK_OPAQUE_TOKEN , basic , <<" some-client-id" >>,
189212 <<" some-client-secret" >>),
190- build_http_200_introspection_token_response ())}
213+ build_http_200_introspection_token_response ())},
214+ {get_openid_configuration , get_openid_configuration_http_expectation (
215+ with_introspection_basic_client_credentials , Config )}
216+
191217 ]} | Config ];
192218
193219init_per_group (with_introspection_request_param_client_credentials , Config ) ->
@@ -202,7 +228,7 @@ init_per_group(with_introspection_request_param_client_credentials, Config) ->
202228 build_introspection_token_request (? MOCK_OPAQUE_TOKEN , request_param , <<" some-client-id" >>,
203229 <<" some-client-secret" >>),
204230 build_http_200_introspection_token_response ())}
205- ]} | Config ];
231+ ]} | Config ];
206232
207233
208234init_per_group (_ , Config ) ->
@@ -214,20 +240,24 @@ get_http_oauth_server_expectations(TestCase, Config) ->
214240 undefined ->
215241 [ {token_endpoint , build_http_mock_behaviour (build_http_access_token_request (),
216242 build_http_200_access_token_response ())},
217- {get_openid_configuration , get_openid_configuration_http_expectation (TestCase )}
243+ {get_openid_configuration , get_openid_configuration_http_expectation (TestCase , Config )}
218244 ];
219245 Expectations ->
220246 Expectations
221247 end .
222- get_openid_configuration_http_expectation (TestCaseAtom ) ->
248+ get_openid_configuration_http_expectation (TestCaseAtom , Config ) ->
223249 TestCase = binary_to_list (atom_to_binary (TestCaseAtom )),
224- Payload = case string :find (TestCase , " returns_partial_payload" ) of
225- nomatch ->
226- build_http_get_openid_configuration_payload ();
227- _ ->
228- List0 = proplists :delete (authorization_endpoint ,
229- build_http_get_openid_configuration_payload ()),
230- proplists :delete (end_session_endpoint , List0 )
250+ Payload = case ? config (expected_openid_configuration_payload , Config ) of
251+ undefined ->
252+ case string :find (TestCase , " returns_partial_payload" ) of
253+ nomatch ->
254+ build_http_get_openid_configuration_payload ();
255+ _ ->
256+ List0 = proplists :delete (authorization_endpoint ,
257+ build_http_get_openid_configuration_payload ()),
258+ proplists :delete (end_session_endpoint , List0 )
259+ end ;
260+ P -> P
231261 end ,
232262 Path = case string :find (TestCase , " path" ) of
233263 nomatch -> " " ;
@@ -244,7 +274,6 @@ lookup_expectation(Endpoint, Config) ->
244274 proplists :get_value (Endpoint , ? config (oauth_server_expectations , Config )).
245275
246276
247-
248277configure_all_oauth_provider_settings (Config ) ->
249278 OAuthProvider = ? config (oauth_provider , Config ),
250279 OAuthProviders = #{ ? config (oauth_provider_id , Config ) =>
@@ -681,7 +710,15 @@ jwks_uri_takes_precedence_over_jwks_url(_Config) ->
681710
682711
683712cannot_introspect_due_to_missing_configuration (_Config )->
684- {error , not_found_introspection_endpoint } = oauth2_client :introspect_token (? MOCK_OPAQUE_TOKEN ).
713+ {error , not_found_introspection_endpoint } = oauth2_client :introspect_token (? MOCK_OPAQUE_TOKEN ),
714+
715+ application :set_env (rabbitmq_auth_backend_oauth2 , introspection_client_id , " some-client-id" ),
716+ {error , not_found_introspection_endpoint } = oauth2_client :introspect_token (? MOCK_OPAQUE_TOKEN ),
717+ application :unset_env (rabbitmq_auth_backend_oauth2 , introspection_client_id ),
718+
719+ application :set_env (rabbitmq_auth_backend_oauth2 , introspection_client_secret , " some-client-secret" ),
720+ {error , not_found_introspection_endpoint } = oauth2_client :introspect_token (? MOCK_OPAQUE_TOKEN ),
721+ application :unset_env (rabbitmq_auth_backend_oauth2 , introspection_client_secret ).
685722
686723can_introspect_token (_Config ) ->
687724 {ok , _ } = oauth2_client :introspect_token (? MOCK_OPAQUE_TOKEN ).
0 commit comments