@@ -52,7 +52,6 @@ groups() ->
5252 [
5353 {run_with_broker , [], [
5454 {verify_introspection_endpoint , [], [
55- test_login ,
5655 introspect_opaque_token_returns_active_jwt_token
5756 ]}
5857 ]},
@@ -543,16 +542,20 @@ init_per_group(verify_introspection_endpoint, Config) ->
543542
544543 PortBase = rabbit_ct_broker_helpers :get_node_config (Config , 0 , tcp_ports_base ),
545544 Port = PortBase + 100 ,
546-
545+ AuthorizationServerURL = uri_string :normalize (#{
546+ scheme => " https" ,port => Port ,path => " /introspect" ,host => " localhost" }),
547+
547548 CertsDir = ? config (rmq_certsdir , Config ),
548- Endpoints = [ {" /introspect" , introspect_endpoint , []}],
549+ Endpoints = [ {" /introspect" , introspect_http_handler , []}],
549550 Dispatch = cowboy_router :compile ([{'_' , Endpoints }]),
550551 {ok , _ } = cowboy :start_tls (introspection_http_listener ,
551552 [{port , Port },
552553 {certfile , filename :join ([CertsDir , " server" , " cert.pem" ])},
553554 {keyfile , filename :join ([CertsDir , " server" , " key.pem" ])}],
554555 #{env => #{dispatch => Dispatch }}),
555- Config ;
556+
557+ [ {authorization_server_url , AuthorizationServerURL },
558+ {authorization_server_ca_cert , filename :join ([CertsDir , " testca" , " cacert.pem" ])} | Config ];
556559
557560init_per_group (_ , Config ) ->
558561 Config .
@@ -690,22 +693,45 @@ end_per_group(verify_introspection_endpoint, Config) ->
690693end_per_group (_ , Config ) ->
691694 Config .
692695
693-
696+ init_per_testcase (introspect_opaque_token_returns_active_jwt_token , Config ) ->
697+ ok = rabbit_ct_broker_helpers :rpc (Config , 0 , application , set_env ,
698+ [rabbitmq_auth_backend_oauth2 , introspection_endpoint ,
699+ ? config (authorization_server_url , Config )]),
700+ ok = rabbit_ct_broker_helpers :rpc (Config , 0 , application , set_env ,
701+ [rabbitmq_auth_backend_oauth2 , introspection_client_id , " some-id" ]),
702+ ok = rabbit_ct_broker_helpers :rpc (Config , 0 , application , set_env ,
703+ [rabbitmq_auth_backend_oauth2 , introspection_client_secret , " some-secret" ]),
704+ CaCertFile = ? config (authorization_server_ca_cert , Config ),
705+
706+ ok = rabbit_ct_broker_helpers :rpc (Config , 0 , application , set_env ,
707+ [rabbitmq_auth_backend_oauth2 , key_config , [{cacertfile , CaCertFile }]]),
708+
709+ rabbit_ct_helpers :testcase_started (Config , introspect_opaque_token_returns_active_jwt_token ).
710+
711+ end_per_testcase (introspect_opaque_token_returns_active_jwt_token , Config ) ->
712+ ok = rabbit_ct_broker_helpers :rpc (Config , 0 , application , unset_env ,
713+ [rabbitmq_auth_backend_oauth2 , introspection_endpoint ]),
714+ ok = rabbit_ct_broker_helpers :rpc (Config , 0 , application , unset_env ,
715+ [rabbitmq_auth_backend_oauth2 , introspection_client_id ]),
716+ ok = rabbit_ct_broker_helpers :rpc (Config , 0 , application , unset_env ,
717+ [rabbitmq_auth_backend_oauth2 , introspection_client_secret ]),
718+ Config .
719+
694720start_broker (Config ) ->
695- Setup0 = rabbit_ct_broker_helpers :setup_steps (),
696- Setup1 = rabbit_ct_client_helpers :setup_steps (),
697- Steps = Setup0 ++ Setup1 ,
698- case rabbit_ct_helpers :run_setup_steps (Config , Steps ) of
699- {skip , _ } = Skip ->
700- Skip ;
701- Config1 ->
702- Ret = rabbit_ct_broker_helpers :enable_feature_flag (
703- Config1 , 'rabbitmq_4.0.0' ),
704- case Ret of
705- ok -> Config1 ;
706- _ -> Ret
707- end
708- end .
721+ Setup0 = rabbit_ct_broker_helpers :setup_steps (),
722+ Setup1 = rabbit_ct_client_helpers :setup_steps (),
723+ Steps = Setup0 ++ Setup1 ,
724+ case rabbit_ct_helpers :run_setup_steps (Config , Steps ) of
725+ {skip , _ } = Skip ->
726+ Skip ;
727+ Config1 ->
728+ Ret = rabbit_ct_broker_helpers :enable_feature_flag (
729+ Config1 , 'rabbitmq_4.0.0' ),
730+ case Ret of
731+ ok -> Config1 ;
732+ _ -> Ret
733+ end
734+ end .
709735finish_init (Group , Config ) ->
710736 rabbit_ct_helpers :log_environment (),
711737 inets :start (),
@@ -914,50 +940,14 @@ should_return_mgt_oauth_resource_a_with_token_endpoint_params_1(Config) ->
914940 assertEqual_on_attribute_for_oauth_resource_server (authSettings (),
915941 Config , a , oauth_token_endpoint_params , token_params_1 ).
916942
917- test_login (Config ) ->
918- http_put (Config , " /users/myuser" , [{password , <<" myuser" >>},
919- {tags , <<" management" >>}], {group , '2xx' }),
920- % % Let's do a post without any other form of authorization
921- {ok , {{_ , CodeAct , _ }, Headers , _ }} =
922- req (Config , 0 , post , " /login" ,
923- [{" content-type" , " application/x-www-form-urlencoded" }],
924- <<" username=myuser&password=myuser" >>),
925- ? assertEqual (200 , CodeAct ),
926-
927- % % Extract the authorization header
928- Cookie = list_to_binary (proplists :get_value (" set-cookie" , Headers )),
929- [_ , Auth ] = binary :split (Cookie , <<" =" >>, []),
930-
931- % % Request the overview with the auth obtained
932- {ok , {{_ , CodeAct1 , _ }, _ , _ }} =
933- req (Config , get , " /overview" , [{" Authorization" , " Basic " ++ binary_to_list (Auth )}]),
934- ? assertEqual (200 , CodeAct1 ),
935-
936- % % Let's request a login with an unknown user
937- {ok , {{_ , CodeAct2 , _ }, Headers2 , _ }} =
938- req (Config , 0 , post , " /login" ,
939- [{" content-type" , " application/x-www-form-urlencoded" }],
940- <<" username=misteryusernumber1&password=myuser" >>),
941- ? assertEqual (401 , CodeAct2 ),
942- ? assert (not proplists :is_defined (" set-cookie" , Headers2 )),
943-
944- http_delete (Config , " /users/myuser" , {group , '2xx' }),
945- passed .
943+ introspect_opaque_token_returns_active_jwt_token (Config ) ->
944+ {ok , {{_HTTP , _ , _ }, _Headers , ResBody }} = req (Config , 0 , post , " /auth/introspect" , [
945+ {" authorization" , " bearer active" }], []),
946+ JSON = rabbit_json :decode (rabbit_data_coercion :to_binary (ResBody )),
947+ ? assertEqual (true , maps :get (<<" active" >>, JSON )),
948+ ? assertEqual (" rabbitmq.tag:administrator" , maps :get (<<" scope" >>, JSON )).
946949
947950
948- introspect_opaque_token_returns_active_jwt_token (Config ) ->
949- Result2 = req (Config , 0 , post , " /auth/introspect" , [
950- {" Authorization" , " Bearer active" }, {" Accept" , " application/json" }], []),
951-
952- ct :log (" Result: ~p " , [Result2 ]).
953- % _Result2 = httpc:request(post, {uri_base_from(Config, 0, "auth/introspect"),
954- % [{"Authorization", "Bearer active"}]}, [], []).
955-
956- uri_base_from (Config , Node , Base ) ->
957- Port = rabbit_ct_broker_helpers :get_node_config (Config , Node , tcp_port_mgmt ),
958- Prefix = " /api" ,
959- Uri = list_to_binary (lists :flatten (io_lib :format (" http://localhost:~w~ts /~ts " , [Port , Prefix , Base ]))),
960- binary_to_list (Uri ).
961951
962952% % -------------------------------------------------------------------
963953% % Utility/helper functions
0 commit comments