1616-define (USER_PATH , " /auth/user" ).
1717-define (ALLOWED_USER , #{username => <<" Ala1" >>,
1818 password => <<" Kocur" >>,
19- expected_credentials => [username , password ],
19+ expected_credentials => [username , password ],
2020 tags => [policymaker , monitoring ]}).
2121-define (ALLOWED_USER_WITH_EXTRA_CREDENTIALS , #{username => <<" Ala2" >>,
22- password => <<" Kocur" >>,
23- client_id => <<" some_id" >>,
24- expected_credentials => [username , password , client_id ],
25- tags => [policymaker , monitoring ]}).
22+ password => <<" Kocur" >>,
23+ client_id => <<" some_id" >>,
24+ expected_credentials => [username , password , client_id ],
25+ tags => [policymaker , monitoring ]}).
2626-define (DENIED_USER , #{username => <<" Alice" >>,
27- password => <<" Cat" >>
28- }).
27+ password => <<" Cat" >>
28+ }).
2929
30- all () ->
30+ all () ->
3131 [
3232 {group , over_https },
3333 {group , over_http }
@@ -49,31 +49,30 @@ shared() ->
4949 grants_access_to_user_with_credentials_in_rabbit_auth_backend_cache
5050 ].
5151
52- init_per_suite (Config ) ->
53- rabbit_ct_helpers :run_setup_steps (Config ) ++
52+ init_per_suite (Config ) ->
53+ rabbit_ct_helpers :run_setup_steps (Config ) ++
5454 [{allowed_user , ? ALLOWED_USER },
5555 {allowed_user_with_extra_credentials , ? ALLOWED_USER_WITH_EXTRA_CREDENTIALS },
5656 {denied_user , ? DENIED_USER }].
5757
5858init_per_group (over_http , Config ) ->
5959 configure_http_auth_backend (" http" , Config ),
6060 {User1 , Tuple1 } = extractUserTuple (? ALLOWED_USER ),
61- {User2 , Tuple2 } = extractUserTuple (? ALLOWED_USER_WITH_EXTRA_CREDENTIALS ),
61+ {User2 , Tuple2 } = extractUserTuple (? ALLOWED_USER_WITH_EXTRA_CREDENTIALS ),
6262 start_http_auth_server (? AUTH_PORT , ? USER_PATH , #{User1 => Tuple1 , User2 => Tuple2 }),
6363 Config ;
6464
6565init_per_group (over_https , Config ) ->
6666 configure_http_auth_backend (" https" , Config ),
6767 {User1 , Tuple1 } = extractUserTuple (? ALLOWED_USER ),
68- {User2 , Tuple2 } = extractUserTuple (? ALLOWED_USER_WITH_EXTRA_CREDENTIALS ),
68+ {User2 , Tuple2 } = extractUserTuple (? ALLOWED_USER_WITH_EXTRA_CREDENTIALS ),
6969 CertsDir = ? config (rmq_certsdir , Config ),
7070 start_https_auth_server (? AUTH_PORT , CertsDir , ? USER_PATH , #{User1 => Tuple1 , User2 => Tuple2 }),
7171 Config .
7272
73-
7473extractUserTuple (User ) ->
75- #{username := Username , password := Password , tags := Tags , expected_credentials := ExpectedCredentials } = User ,
76- {Username , {Password , Tags , ExpectedCredentials }}.
74+ #{username := Username , password := Password , tags := Tags , expected_credentials := ExpectedCredentials } = User ,
75+ {Username , {Password , Tags , ExpectedCredentials }}.
7776
7877end_per_suite (Config ) ->
7978 Config .
@@ -87,7 +86,7 @@ end_per_group(over_https, Config) ->
8786
8887grants_access_to_user (Config ) ->
8988 #{username := U , password := P , tags := T } = ? config (allowed_user , Config ),
90- AuthProps = [{password , P }],
89+ AuthProps = [{password , P }],
9190 {ok , User } = rabbit_auth_backend_http :user_login_authentication (U , AuthProps ),
9291
9392 ? assertMatch ({U , T , AuthProps },
@@ -98,33 +97,32 @@ denies_access_to_user(Config) ->
9897 ? assertMatch ({refused , " Denied by the backing HTTP service" , []},
9998 rabbit_auth_backend_http :user_login_authentication (U , [{password , P }])).
10099
101-
102100grants_access_to_user_passing_additional_required_authprops (Config ) ->
103101 #{username := U , password := P , tags := T , client_id := ClientId } = ? config (allowed_user_with_extra_credentials , Config ),
104- AuthProps = [{password , P }, {client_id , ClientId }],
102+ AuthProps = [{password , P }, {client_id , ClientId }],
105103 {ok , User } = rabbit_auth_backend_http :user_login_authentication (U , AuthProps ),
106- ? assertMatch ({U , T , AuthProps },
104+ ? assertMatch ({U , T , AuthProps },
107105 {User # auth_user .username , User # auth_user .tags , (User # auth_user .impl )()}).
108106
109107grants_access_to_user_skipping_internal_authprops (Config ) ->
110108 #{username := U , password := P , tags := T , client_id := ClientId } = ? config (allowed_user_with_extra_credentials , Config ),
111- AuthProps = [{password , P }, {client_id , ClientId }, {rabbit_any_internal_property , <<" some value" >>}],
109+ AuthProps = [{password , P }, {client_id , ClientId }, {rabbit_any_internal_property , <<" some value" >>}],
112110 {ok , User } = rabbit_auth_backend_http :user_login_authentication (U , AuthProps ),
113111
114- ? assertMatch ({U , T , AuthProps },
112+ ? assertMatch ({U , T , AuthProps },
115113 {User # auth_user .username , User # auth_user .tags , (User # auth_user .impl )()}).
116114
117115grants_access_to_user_with_credentials_in_rabbit_auth_backend_http (Config ) ->
118116 #{username := U , password := P , tags := T , client_id := ClientId } = ? config (allowed_user_with_extra_credentials , Config ),
119- AuthProps = [{rabbit_auth_backend_http , fun () -> [{password , P }, {client_id , ClientId }] end }],
117+ AuthProps = [{rabbit_auth_backend_http , fun () -> [{password , P }, {client_id , ClientId }] end }],
120118 {ok , User } = rabbit_auth_backend_http :user_login_authentication (U , AuthProps ),
121119
122120 ? assertMatch ({U , T , AuthProps },
123121 {User # auth_user .username , User # auth_user .tags , (User # auth_user .impl )()}).
124122
125123grants_access_to_user_with_credentials_in_rabbit_auth_backend_cache (Config ) ->
126124 #{username := U , password := P , tags := T , client_id := ClientId } = ? config (allowed_user_with_extra_credentials , Config ),
127- AuthProps = [{rabbit_auth_backend_cache , fun () -> [{password , P }, {client_id , ClientId }] end }],
125+ AuthProps = [{rabbit_auth_backend_cache , fun () -> [{password , P }, {client_id , ClientId }] end }],
128126 {ok , User } = rabbit_auth_backend_http :user_login_authentication (U , AuthProps ),
129127
130128 ? assertMatch ({U , T , AuthProps },
@@ -134,39 +132,38 @@ grants_access_to_user_with_credentials_in_rabbit_auth_backend_cache(Config) ->
134132
135133configure_http_auth_backend (Scheme , Config ) ->
136134 [application :set_env (rabbitmq_auth_backend_http , K , V ) || {K , V } <- generate_backend_config (Scheme , Config )].
137- undo_configure_http_auth_backend (Scheme , Config ) ->
135+ undo_configure_http_auth_backend (Scheme , Config ) ->
138136 [application :unset_env (rabbitmq_auth_backend_http , K ) || {K , _V } <- generate_backend_config (Scheme , Config )].
139137
140138start_http_auth_server (Port , Path , Users ) ->
141139 {ok , _ } = application :ensure_all_started (inets ),
142- application :ensure_all_started (cowboy ),
140+ { ok , _ } = application :ensure_all_started (cowboy ),
143141 Dispatch = cowboy_router :compile ([{'_' , [{Path , auth_http_mock , Users }]}]),
144142 {ok , _ } = cowboy :start_clear (
145143 mock_http_auth_listener , [{port , Port }], #{env => #{dispatch => Dispatch }}).
146144
147145start_https_auth_server (Port , CertsDir , Path , Users ) ->
148146 {ok , _ } = application :ensure_all_started (inets ),
149147 {ok , _ } = application :ensure_all_started (ssl ),
150- {ok , _ } = application :ensure_all_started (cowboy ),
151-
148+ {ok , _ } = application :ensure_all_started (cowboy ),
152149 Dispatch = cowboy_router :compile ([{'_' , [{Path , auth_http_mock , Users }]}]),
153150 {ok , _ } = cowboy :start_tls (mock_http_auth_listener ,
154151 [{port , Port },
155152 {certfile , filename :join ([CertsDir , " server" , " cert.pem" ])},
156153 {keyfile , filename :join ([CertsDir , " server" , " key.pem" ])}],
157154 #{env => #{dispatch => Dispatch }}).
158-
155+
159156stop_http_auth_server () ->
160157 cowboy :stop_listener (mock_http_auth_listener ).
161158
162159generate_backend_config (Scheme , Config ) ->
163160 Config0 = [{http_method , get },
164161 {user_path , Scheme ++ " ://localhost:" ++ integer_to_list (? AUTH_PORT ) ++ ? USER_PATH },
165- {vhost_path , Scheme ++ " ://localhost:" ++ integer_to_list (? AUTH_PORT ) ++ " /auth/vhost" },
162+ {vhost_path , Scheme ++ " ://localhost:" ++ integer_to_list (? AUTH_PORT ) ++ " /auth/vhost" },
166163 {resource_path , Scheme ++ " ://localhost:" ++ integer_to_list (? AUTH_PORT ) ++ " /auth/resource" },
167- {topic_path , Scheme ++ " ://localhost:" ++ integer_to_list (? AUTH_PORT ) ++ " /auth/topic" }],
168- Config1 = case Scheme of
169- " https" ->
164+ {topic_path , Scheme ++ " ://localhost:" ++ integer_to_list (? AUTH_PORT ) ++ " /auth/topic" }],
165+ Config1 = case Scheme of
166+ " https" ->
170167 CertsDir = ? config (rmq_certsdir , Config ),
171168 [{ssl_options , [
172169 {cacertfile , filename :join ([CertsDir , " testca" , " cacert.pem" ])},
@@ -177,4 +174,4 @@ generate_backend_config(Scheme, Config) ->
177174 }];
178175 " http" -> []
179176 end ,
180- Config0 ++ Config1 .
177+ Config0 ++ Config1 .
0 commit comments