17
17
-compile (export_all ).
18
18
19
19
-define (MOCK_OPAQUE_TOKEN , <<" some opaque token" >>).
20
- -define (MOCK_INTROSPECTION_ENDPOINT , <<" /introspection " >>).
20
+ -define (MOCK_INTROSPECTION_ENDPOINT , <<" /introspect " >>).
21
21
-define (MOCK_TOKEN_ENDPOINT , <<" /token" >>).
22
22
-define (AUTH_PORT , 8000 ).
23
23
-define (ISSUER_PATH , " /somepath" ).
@@ -47,12 +47,15 @@ groups() ->
47
47
cannot_introspect_due_to_missing_configuration ,
48
48
{with_introspection_endpoint , [], [
49
49
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
+ ]}
55
57
]}
58
+
56
59
]}
57
60
]}
58
61
]},
@@ -170,31 +173,31 @@ init_per_group(with_default_oauth_provider, Config) ->
170
173
171
174
init_per_group (with_introspection_endpoint , Config ) ->
172
175
application :set_env (rabbitmq_auth_backend_oauth2 , introspection_endpoint ,
173
- " https://introspection " ),
176
+ build_token_introspection_endpoint ( " https" ) ),
174
177
Config ;
175
178
176
179
init_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 ,
178
181
" 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 ,
180
183
" 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 ,
182
185
basic ),
183
- [{with_introspection_basic_client_credentials , [
186
+ [{can_introspect_token , [
184
187
{introspection_endpoint , build_http_mock_behaviour (
185
188
build_introspection_token_request (? MOCK_OPAQUE_TOKEN , basic , <<" some-client-id" >>,
186
189
<<" some-client-secret" >>),
187
190
build_http_200_introspection_token_response ())}
188
191
]} | Config ];
189
192
190
193
init_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 ,
192
195
" 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 ,
194
197
" 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 ,
196
199
request_param ),
197
- [{with_introspection_request_param_client_credentials , [
200
+ [{can_introspect_token , [
198
201
{introspection_endpoint , build_http_mock_behaviour (
199
202
build_introspection_token_request (? MOCK_OPAQUE_TOKEN , request_param , <<" some-client-id" >>,
200
203
<<" some-client-secret" >>),
@@ -365,6 +368,18 @@ end_per_group(with_introspection_endpoint, Config) ->
365
368
application :unset_env (rabbitmq_auth_backend_oauth2 , introspection_endpoint ),
366
369
Config ;
367
370
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
+
368
383
end_per_group (_ , Config ) ->
369
384
Config .
370
385
@@ -666,10 +681,10 @@ jwks_uri_takes_precedence_over_jwks_url(_Config) ->
666
681
667
682
668
683
cannot_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 ).
670
685
671
686
can_introspect_token (_Config ) ->
672
- {ok , _ } = oauth2_client :introspect_token (<< " some token " >> ).
687
+ {ok , _ } = oauth2_client :introspect_token (? MOCK_OPAQUE_TOKEN ).
673
688
674
689
% %% HELPERS
675
690
@@ -697,6 +712,12 @@ build_jwks_uri(Scheme, Path) ->
697
712
port => rabbit_data_coercion :to_integer (? AUTH_PORT ),
698
713
path => Path }).
699
714
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
+
700
721
build_access_token_request (Request ) ->
701
722
# access_token_request {
702
723
client_id = proplists :get_value (? REQUEST_CLIENT_ID , Request ),
@@ -748,6 +769,7 @@ start_https_oauth_server(Port, CertsDir, Expectations) when is_list(Expectations
748
769
{'_' , [{Path , oauth_http_mock , Expected } || #{request := #{path := Path }}
749
770
= Expected <- Expectations ]}
750
771
]),
772
+ ct :log (" start_https_oauth_server with Expectations: ~p " , [Expectations ]),
751
773
{ok , _ } = cowboy :start_tls (
752
774
mock_http_auth_listener ,
753
775
[{port , Port },
@@ -758,6 +780,7 @@ start_https_oauth_server(Port, CertsDir, Expectations) when is_list(Expectations
758
780
759
781
start_https_oauth_server (Port , CertsDir , #{request := #{path := Path }} = Expected ) ->
760
782
Dispatch = cowboy_router :compile ([{'_' , [{Path , oauth_http_mock , Expected }]}]),
783
+ ct :log (" start_https_oauth_server" ),
761
784
{ok , _ } = cowboy :start_tls (
762
785
mock_http_auth_listener ,
763
786
[{port , Port },
@@ -767,6 +790,7 @@ start_https_oauth_server(Port, CertsDir, #{request := #{path := Path}} = Expecte
767
790
#{env => #{dispatch => Dispatch }}).
768
791
769
792
stop_https_auth_server () ->
793
+ ct :log (" stop_https_auth_server" ),
770
794
cowboy :stop_listener (mock_http_auth_listener ).
771
795
772
796
-spec ssl_options (ssl :verify_type (), boolean (), file :filename ()) -> list ().
@@ -879,14 +903,14 @@ denies_access_token_expectation() ->
879
903
build_introspection_token_request (Token , basic , ClientId , ClientSecret ) ->
880
904
Map = build_http_request (
881
905
<<" POST" >>,
882
- ? MOCK_TOKEN_ENDPOINT ,
906
+ ? MOCK_INTROSPECTION_ENDPOINT ,
883
907
[
884
908
{? REQUEST_TOKEN , Token }
885
909
]),
886
910
Credentials = binary_to_list (<<ClientId /binary ," :" ,ClientSecret /binary >>),
887
911
AuthStr = base64 :encode_to_string (Credentials ),
888
912
maps :put (headers , #{
889
- <<" authorization" >> => " Basic " ++ AuthStr
913
+ <<" authorization" >> => list_to_binary ( " Basic " ++ AuthStr )
890
914
}, Map );
891
915
build_introspection_token_request (Token , request_param , ClientId , ClientSecret ) ->
892
916
build_http_request (
0 commit comments