1717-compile (export_all ).
1818
1919-define (MOCK_OPAQUE_TOKEN , <<" some opaque token" >>).
20- -define (MOCK_INTROSPECTION_ENDPOINT , <<" /introspection " >>).
20+ -define (MOCK_INTROSPECTION_ENDPOINT , <<" /introspect " >>).
2121-define (MOCK_TOKEN_ENDPOINT , <<" /token" >>).
2222-define (AUTH_PORT , 8000 ).
2323-define (ISSUER_PATH , " /somepath" ).
@@ -47,12 +47,15 @@ groups() ->
4747 cannot_introspect_due_to_missing_configuration ,
4848 {with_introspection_endpoint , [], [
4949 cannot_introspect_due_to_missing_configuration ,
50- {with_introspection_basic_client_credentials , [], [
51- can_introspect_token
52- ]},
53- {with_introspection_request_param_client_credentials , [], [
54- can_introspect_token
50+ {https , [], [
51+ {with_introspection_basic_client_credentials , [], [
52+ can_introspect_token
53+ ]},
54+ {with_introspection_request_param_client_credentials , [], [
55+ can_introspect_token
56+ ]}
5557 ]}
58+
5659 ]}
5760 ]}
5861 ]},
@@ -170,31 +173,31 @@ init_per_group(with_default_oauth_provider, Config) ->
170173
171174init_per_group (with_introspection_endpoint , Config ) ->
172175 application :set_env (rabbitmq_auth_backend_oauth2 , introspection_endpoint ,
173- " https://introspection " ),
176+ build_token_introspection_endpoint ( " https" ) ),
174177 Config ;
175178
176179init_per_group (with_introspection_basic_client_credentials , Config ) ->
177- application :set_env (rabbitmq_auth_backend_oauth2 , introspection_endpoint_client_id ,
180+ application :set_env (rabbitmq_auth_backend_oauth2 , introspection_client_id ,
178181 " some-client-id" ),
179- application :set_env (rabbitmq_auth_backend_oauth2 , introspection_endpoint_client_secret ,
182+ application :set_env (rabbitmq_auth_backend_oauth2 , introspection_client_secret ,
180183 " some-client-secret" ),
181- application :set_env (rabbitmq_auth_backend_oauth2 , introspection_endpoint_client_auth_method ,
184+ application :set_env (rabbitmq_auth_backend_oauth2 , introspection_client_auth_method ,
182185 basic ),
183- [{with_introspection_basic_client_credentials , [
186+ [{can_introspect_token , [
184187 {introspection_endpoint , build_http_mock_behaviour (
185188 build_introspection_token_request (? MOCK_OPAQUE_TOKEN , basic , <<" some-client-id" >>,
186189 <<" some-client-secret" >>),
187190 build_http_200_introspection_token_response ())}
188191 ]} | Config ];
189192
190193init_per_group (with_introspection_request_param_client_credentials , Config ) ->
191- application :set_env (rabbitmq_auth_backend_oauth2 , introspection_endpoint_client_id ,
194+ application :set_env (rabbitmq_auth_backend_oauth2 , introspection_client_id ,
192195 " some-client-id" ),
193- application :set_env (rabbitmq_auth_backend_oauth2 , introspection_endpoint_client_secret ,
196+ application :set_env (rabbitmq_auth_backend_oauth2 , introspection_client_secret ,
194197 " some-client-secret" ),
195- application :set_env (rabbitmq_auth_backend_oauth2 , introspection_endpoint_client_auth_method ,
198+ application :set_env (rabbitmq_auth_backend_oauth2 , introspection_client_auth_method ,
196199 request_param ),
197- [{with_introspection_request_param_client_credentials , [
200+ [{can_introspect_token , [
198201 {introspection_endpoint , build_http_mock_behaviour (
199202 build_introspection_token_request (? MOCK_OPAQUE_TOKEN , request_param , <<" some-client-id" >>,
200203 <<" some-client-secret" >>),
@@ -365,6 +368,18 @@ end_per_group(with_introspection_endpoint, Config) ->
365368 application :unset_env (rabbitmq_auth_backend_oauth2 , introspection_endpoint ),
366369 Config ;
367370
371+ end_per_group (with_introspection_basic_client_credentials , Config ) ->
372+ application :unset_env (rabbitmq_auth_backend_oauth2 , introspection_endpoint_client_id ),
373+ application :unset_env (rabbitmq_auth_backend_oauth2 , introspection_endpoint_client_secret ),
374+ application :unset_env (rabbitmq_auth_backend_oauth2 , introspection_endpoint_client_auth_method ),
375+ Config ;
376+
377+ end_per_group (with_introspection_request_param_client_credentials , Config ) ->
378+ application :unset_env (rabbitmq_auth_backend_oauth2 , introspection_endpoint_client_id ),
379+ application :unset_env (rabbitmq_auth_backend_oauth2 , introspection_endpoint_client_secret ),
380+ application :unset_env (rabbitmq_auth_backend_oauth2 , introspection_endpoint_client_auth_method ),
381+ Config ;
382+
368383end_per_group (_ , Config ) ->
369384 Config .
370385
@@ -666,10 +681,10 @@ jwks_uri_takes_precedence_over_jwks_url(_Config) ->
666681
667682
668683cannot_introspect_due_to_missing_configuration (_Config )->
669- {error , not_found_introspection_endpoint } = oauth2_client :introspect_token (<< " some token " >> ).
684+ {error , not_found_introspection_endpoint } = oauth2_client :introspect_token (? MOCK_OPAQUE_TOKEN ).
670685
671686can_introspect_token (_Config ) ->
672- {ok , _ } = oauth2_client :introspect_token (<< " some token " >> ).
687+ {ok , _ } = oauth2_client :introspect_token (? MOCK_OPAQUE_TOKEN ).
673688
674689% %% HELPERS
675690
@@ -697,6 +712,12 @@ build_jwks_uri(Scheme, Path) ->
697712 port => rabbit_data_coercion :to_integer (? AUTH_PORT ),
698713 path => Path }).
699714
715+ build_token_introspection_endpoint (Scheme ) ->
716+ uri_string :recompose (#{scheme => Scheme ,
717+ host => " localhost" ,
718+ port => rabbit_data_coercion :to_integer (? AUTH_PORT ),
719+ path => " /introspect" }).
720+
700721build_access_token_request (Request ) ->
701722 # access_token_request {
702723 client_id = proplists :get_value (? REQUEST_CLIENT_ID , Request ),
@@ -748,6 +769,7 @@ start_https_oauth_server(Port, CertsDir, Expectations) when is_list(Expectations
748769 {'_' , [{Path , oauth_http_mock , Expected } || #{request := #{path := Path }}
749770 = Expected <- Expectations ]}
750771 ]),
772+ ct :log (" start_https_oauth_server with Expectations: ~p " , [Expectations ]),
751773 {ok , _ } = cowboy :start_tls (
752774 mock_http_auth_listener ,
753775 [{port , Port },
@@ -758,6 +780,7 @@ start_https_oauth_server(Port, CertsDir, Expectations) when is_list(Expectations
758780
759781start_https_oauth_server (Port , CertsDir , #{request := #{path := Path }} = Expected ) ->
760782 Dispatch = cowboy_router :compile ([{'_' , [{Path , oauth_http_mock , Expected }]}]),
783+ ct :log (" start_https_oauth_server" ),
761784 {ok , _ } = cowboy :start_tls (
762785 mock_http_auth_listener ,
763786 [{port , Port },
@@ -767,6 +790,7 @@ start_https_oauth_server(Port, CertsDir, #{request := #{path := Path}} = Expecte
767790 #{env => #{dispatch => Dispatch }}).
768791
769792stop_https_auth_server () ->
793+ ct :log (" stop_https_auth_server" ),
770794 cowboy :stop_listener (mock_http_auth_listener ).
771795
772796-spec ssl_options (ssl :verify_type (), boolean (), file :filename ()) -> list ().
@@ -879,14 +903,14 @@ denies_access_token_expectation() ->
879903build_introspection_token_request (Token , basic , ClientId , ClientSecret ) ->
880904 Map = build_http_request (
881905 <<" POST" >>,
882- ? MOCK_TOKEN_ENDPOINT ,
906+ ? MOCK_INTROSPECTION_ENDPOINT ,
883907 [
884908 {? REQUEST_TOKEN , Token }
885909 ]),
886910 Credentials = binary_to_list (<<ClientId /binary ," :" ,ClientSecret /binary >>),
887911 AuthStr = base64 :encode_to_string (Credentials ),
888912 maps :put (headers , #{
889- <<" authorization" >> => " Basic " ++ AuthStr
913+ <<" authorization" >> => list_to_binary ( " Basic " ++ AuthStr )
890914 }, Map );
891915build_introspection_token_request (Token , request_param , ClientId , ClientSecret ) ->
892916 build_http_request (
0 commit comments