@@ -54,8 +54,26 @@ groups() ->
54
54
{with_introspection_request_param_client_credentials , [], [
55
55
can_introspect_token
56
56
]}
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
57
65
]}
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
+ ]}
59
77
]}
60
78
]}
61
79
]},
@@ -176,18 +194,26 @@ init_per_group(with_introspection_endpoint, Config) ->
176
194
build_token_introspection_endpoint (" https" )),
177
195
Config ;
178
196
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
+
179
202
init_per_group (with_introspection_basic_client_credentials , Config ) ->
180
203
application :set_env (rabbitmq_auth_backend_oauth2 , introspection_client_id ,
181
204
" some-client-id" ),
182
205
application :set_env (rabbitmq_auth_backend_oauth2 , introspection_client_secret ,
183
206
" some-client-secret" ),
184
207
application :set_env (rabbitmq_auth_backend_oauth2 , introspection_client_auth_method ,
185
- basic ),
208
+ basic ),
186
209
[{can_introspect_token , [
187
210
{introspection_endpoint , build_http_mock_behaviour (
188
211
build_introspection_token_request (? MOCK_OPAQUE_TOKEN , basic , <<" some-client-id" >>,
189
212
<<" 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
+
191
217
]} | Config ];
192
218
193
219
init_per_group (with_introspection_request_param_client_credentials , Config ) ->
@@ -202,7 +228,7 @@ init_per_group(with_introspection_request_param_client_credentials, Config) ->
202
228
build_introspection_token_request (? MOCK_OPAQUE_TOKEN , request_param , <<" some-client-id" >>,
203
229
<<" some-client-secret" >>),
204
230
build_http_200_introspection_token_response ())}
205
- ]} | Config ];
231
+ ]} | Config ];
206
232
207
233
208
234
init_per_group (_ , Config ) ->
@@ -214,20 +240,24 @@ get_http_oauth_server_expectations(TestCase, Config) ->
214
240
undefined ->
215
241
[ {token_endpoint , build_http_mock_behaviour (build_http_access_token_request (),
216
242
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 )}
218
244
];
219
245
Expectations ->
220
246
Expectations
221
247
end .
222
- get_openid_configuration_http_expectation (TestCaseAtom ) ->
248
+ get_openid_configuration_http_expectation (TestCaseAtom , Config ) ->
223
249
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
231
261
end ,
232
262
Path = case string :find (TestCase , " path" ) of
233
263
nomatch -> " " ;
@@ -244,7 +274,6 @@ lookup_expectation(Endpoint, Config) ->
244
274
proplists :get_value (Endpoint , ? config (oauth_server_expectations , Config )).
245
275
246
276
247
-
248
277
configure_all_oauth_provider_settings (Config ) ->
249
278
OAuthProvider = ? config (oauth_provider , Config ),
250
279
OAuthProviders = #{ ? config (oauth_provider_id , Config ) =>
@@ -681,7 +710,15 @@ jwks_uri_takes_precedence_over_jwks_url(_Config) ->
681
710
682
711
683
712
cannot_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 ).
685
722
686
723
can_introspect_token (_Config ) ->
687
724
{ok , _ } = oauth2_client :introspect_token (? MOCK_OPAQUE_TOKEN ).
0 commit comments