1414-import (rabbit_mgmt_test_util , [req /5 ]).
1515-compile (export_all ).
1616
17+ -import (rabbit_mgmt_test_util , [assert_list /2 , assert_item /2 , test_item /2 ,
18+ assert_keys /2 , assert_no_keys /2 ,
19+ decode_body /1 ,
20+ http_get /2 , http_get /3 , http_get /5 ,
21+ http_get_no_auth /3 ,
22+ http_get_no_decode /5 ,
23+ http_put /4 , http_put /6 ,
24+ http_post /4 , http_post /6 ,
25+ http_post_json /4 ,
26+ http_upload_raw /8 ,
27+ http_delete /3 , http_delete /4 , http_delete /5 ,
28+ http_put_raw /4 , http_post_accept_json /4 ,
29+ req /4 , auth_header /2 ,
30+ assert_permanent_redirect /3 ,
31+ uri_base_from /2 , format_for_upload /1 ,
32+ amqp_port /1 , req /6 ]).
1733all () ->
1834 [
1935 {group , without_any_settings },
@@ -36,6 +52,7 @@ groups() ->
3652 [
3753 {run_with_broker , [], [
3854 {verify_introspection_endpoint , [], [
55+ test_login ,
3956 introspect_opaque_token_returns_active_jwt_token
4057 ]}
4158 ]},
@@ -897,9 +914,50 @@ should_return_mgt_oauth_resource_a_with_token_endpoint_params_1(Config) ->
897914 assertEqual_on_attribute_for_oauth_resource_server (authSettings (),
898915 Config , a , oauth_token_endpoint_params , token_params_1 ).
899916
900- introspect_opaque_token_returns_active_jwt_token (Config ) ->
901- _Result = req (Config , 0 , post , " /introspect" , [{" Authorization" , " Bearer active" }]).
902-
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 .
946+
947+
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 ).
903961
904962% % -------------------------------------------------------------------
905963% % Utility/helper functions
0 commit comments