|
20 | 20 | {vhost_path, "http://localhost:" ++ integer_to_list(?AUTH_PORT) ++ "/auth/vhost"}, |
21 | 21 | {resource_path, "http://localhost:" ++ integer_to_list(?AUTH_PORT) ++ "/auth/resource"}, |
22 | 22 | {topic_path, "http://localhost:" ++ integer_to_list(?AUTH_PORT) ++ "/auth/topic"}]). |
23 | | --define(ALLOWED_USER, #{username => <<"Ala">>, |
| 23 | +-define(ALLOWED_USER, #{username => <<"Ala1">>, |
24 | 24 | password => <<"Kocur">>, |
| 25 | + expected_credentials => [username, password], |
25 | 26 | tags => [policymaker, monitoring]}). |
26 | | --define(DENIED_USER, #{username => <<"Alice">>, password => <<"Cat">>}). |
| 27 | +-define(ALLOWED_USER_WITH_EXTRA_CREDENTIALS, #{username => <<"Ala2">>, |
| 28 | + password => <<"Kocur">>, |
| 29 | + client_id => <<"some_id">>, |
| 30 | + expected_credentials => [username, password, client_id], |
| 31 | + tags => [policymaker, monitoring]}). |
| 32 | +-define(DENIED_USER, #{username => <<"Alice">>, |
| 33 | + password => <<"Cat">> |
| 34 | + }). |
27 | 35 |
|
28 | | -all() -> [grants_access_to_user, denies_access_to_user]. |
| 36 | +all() -> [grants_access_to_user, |
| 37 | + denies_access_to_user, |
| 38 | + grants_access_to_user_passing_additional_required_authprops, |
| 39 | + grants_access_to_user_skipping_internal_authprops, |
| 40 | + grants_access_to_user_with_credentials_in_rabbit_auth_backend_http, |
| 41 | + grants_access_to_user_with_credentials_in_rabbit_auth_backend_cache]. |
29 | 42 |
|
30 | 43 | init_per_suite(Config) -> |
31 | 44 | configure_http_auth_backend(), |
32 | | - #{username := Username, password := Password, tags := Tags} = ?ALLOWED_USER, |
33 | | - start_http_auth_server(?AUTH_PORT, ?USER_PATH, #{Username => {Password, Tags}}), |
34 | | - [{allowed_user, ?ALLOWED_USER}, {denied_user, ?DENIED_USER} | Config]. |
| 45 | + {User1, Tuple1} = extractUserTuple(?ALLOWED_USER), |
| 46 | + {User2, Tuple2} = extractUserTuple(?ALLOWED_USER_WITH_EXTRA_CREDENTIALS), |
| 47 | + start_http_auth_server(?AUTH_PORT, ?USER_PATH, #{User1 => Tuple1, User2 => Tuple2}), |
| 48 | + [{allowed_user, ?ALLOWED_USER}, |
| 49 | + {allowed_user_with_extra_credentials, ?ALLOWED_USER_WITH_EXTRA_CREDENTIALS}, |
| 50 | + {denied_user, ?DENIED_USER} | Config]. |
| 51 | +extractUserTuple(User) -> |
| 52 | + #{username := Username, password := Password, tags := Tags, expected_credentials := ExpectedCredentials} = User, |
| 53 | + {Username, {Password, Tags, ExpectedCredentials}}. |
35 | 54 |
|
36 | 55 | end_per_suite(_Config) -> |
37 | 56 | stop_http_auth_server(). |
38 | 57 |
|
39 | 58 | grants_access_to_user(Config) -> |
40 | 59 | #{username := U, password := P, tags := T} = ?config(allowed_user, Config), |
41 | | - {ok, User} = rabbit_auth_backend_http:user_login_authentication(U, [{password, P}]), |
42 | | - ?assertMatch({U, T, P}, |
| 60 | + AuthProps = [{password, P}], |
| 61 | + {ok, User} = rabbit_auth_backend_http:user_login_authentication(U, AuthProps), |
| 62 | + |
| 63 | + ?assertMatch({U, T, AuthProps}, |
43 | 64 | {User#auth_user.username, User#auth_user.tags, (User#auth_user.impl)()}). |
44 | 65 |
|
45 | 66 | denies_access_to_user(Config) -> |
46 | 67 | #{username := U, password := P} = ?config(denied_user, Config), |
47 | 68 | ?assertMatch({refused, "Denied by the backing HTTP service", []}, |
48 | 69 | rabbit_auth_backend_http:user_login_authentication(U, [{password, P}])). |
49 | 70 |
|
| 71 | + |
| 72 | +grants_access_to_user_passing_additional_required_authprops(Config) -> |
| 73 | + #{username := U, password := P, tags := T, client_id := ClientId} = ?config(allowed_user_with_extra_credentials, Config), |
| 74 | + AuthProps = [{password, P}, {client_id, ClientId}], |
| 75 | + {ok, User} = rabbit_auth_backend_http:user_login_authentication(U, AuthProps), |
| 76 | + ?assertMatch({U, T, AuthProps}, |
| 77 | + {User#auth_user.username, User#auth_user.tags, (User#auth_user.impl)()}). |
| 78 | + |
| 79 | +grants_access_to_user_skipping_internal_authprops(Config) -> |
| 80 | + #{username := U, password := P, tags := T, client_id := ClientId} = ?config(allowed_user_with_extra_credentials, Config), |
| 81 | + AuthProps = [{password, P}, {client_id, ClientId}, {rabbit_any_internal_property, <<"some value">>}], |
| 82 | + {ok, User} = rabbit_auth_backend_http:user_login_authentication(U, AuthProps), |
| 83 | + |
| 84 | + ?assertMatch({U, T, AuthProps}, |
| 85 | + {User#auth_user.username, User#auth_user.tags, (User#auth_user.impl)()}). |
| 86 | + |
| 87 | +grants_access_to_user_with_credentials_in_rabbit_auth_backend_http(Config) -> |
| 88 | + #{username := U, password := P, tags := T, client_id := ClientId} = ?config(allowed_user_with_extra_credentials, Config), |
| 89 | + AuthProps = [{rabbit_auth_backend_http, fun() -> [{password, P}, {client_id, ClientId}] end}], |
| 90 | + {ok, User} = rabbit_auth_backend_http:user_login_authentication(U, AuthProps), |
| 91 | + |
| 92 | + ?assertMatch({U, T, AuthProps}, |
| 93 | + {User#auth_user.username, User#auth_user.tags, (User#auth_user.impl)()}). |
| 94 | + |
| 95 | +grants_access_to_user_with_credentials_in_rabbit_auth_backend_cache(Config) -> |
| 96 | + #{username := U, password := P, tags := T, client_id := ClientId} = ?config(allowed_user_with_extra_credentials, Config), |
| 97 | + AuthProps = [{rabbit_auth_backend_cache, fun() -> [{password, P}, {client_id, ClientId}] end}], |
| 98 | + {ok, User} = rabbit_auth_backend_http:user_login_authentication(U, AuthProps), |
| 99 | + |
| 100 | + ?assertMatch({U, T, AuthProps}, |
| 101 | + {User#auth_user.username, User#auth_user.tags, (User#auth_user.impl)()}). |
| 102 | + |
50 | 103 | %%% HELPERS |
51 | 104 |
|
52 | 105 | configure_http_auth_backend() -> |
|
0 commit comments