|
| 1 | +%% The contents of this file are subject to the Mozilla Public License |
| 2 | +%% Version 1.1 (the "License"); you may not use this file except in |
| 3 | +%% compliance with the License. You may obtain a copy of the License at |
| 4 | +%% http://www.mozilla.org/MPL/ |
| 5 | +%% |
| 6 | +%% Software distributed under the License is distributed on an "AS IS" |
| 7 | +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
| 8 | +%% License for the specific language governing rights and limitations |
| 9 | +%% under the License. |
| 10 | +%% |
| 11 | +%% The Original Code is RabbitMQ. |
| 12 | +%% |
| 13 | +%% The Initial Developer of the Original Code is GoPivotal, Inc. |
| 14 | +%% Copyright (c) 2011-2015 Pivotal Software, Inc. All rights reserved. |
| 15 | +%% |
| 16 | + |
| 17 | +-module(password_hashing_SUITE). |
| 18 | + |
| 19 | +-include_lib("common_test/include/ct.hrl"). |
| 20 | +-include_lib("rabbit_common/include/rabbit.hrl"). |
| 21 | + |
| 22 | +-compile(export_all). |
| 23 | + |
| 24 | +all() -> |
| 25 | + [ |
| 26 | + password_hashing, |
| 27 | + change_password |
| 28 | + ]. |
| 29 | + |
| 30 | +%% ------------------------------------------------------------------- |
| 31 | +%% Testsuite setup/teardown. |
| 32 | +%% ------------------------------------------------------------------- |
| 33 | + |
| 34 | +init_per_suite(Config) -> |
| 35 | + rabbit_ct_helpers:log_environment(), |
| 36 | + rabbit_ct_helpers:run_setup_steps(?MODULE, Config). |
| 37 | + |
| 38 | +end_per_suite(Config) -> |
| 39 | + rabbit_ct_helpers:run_teardown_steps(Config). |
| 40 | + |
| 41 | +%% --------------------------------------------------------------------------- |
| 42 | +%% Test cases |
| 43 | +%% --------------------------------------------------------------------------- |
| 44 | + |
| 45 | +password_hashing(Config) -> |
| 46 | + passed = rabbit_ct_broker_helpers:run_test_on_broker( |
| 47 | + ?config(rmq_nodename, Config), |
| 48 | + ?MODULE, password_hashing1, [Config]). |
| 49 | + |
| 50 | +password_hashing1(_Config) -> |
| 51 | + rabbit_password_hashing_sha256 = rabbit_password:hashing_mod(), |
| 52 | + application:set_env(rabbit, password_hashing_module, |
| 53 | + rabbit_password_hashing_md5), |
| 54 | + rabbit_password_hashing_md5 = rabbit_password:hashing_mod(), |
| 55 | + application:set_env(rabbit, password_hashing_module, |
| 56 | + rabbit_password_hashing_sha256), |
| 57 | + rabbit_password_hashing_sha256 = rabbit_password:hashing_mod(), |
| 58 | + |
| 59 | + rabbit_password_hashing_sha256 = |
| 60 | + rabbit_password:hashing_mod(rabbit_password_hashing_sha256), |
| 61 | + rabbit_password_hashing_md5 = |
| 62 | + rabbit_password:hashing_mod(rabbit_password_hashing_md5), |
| 63 | + rabbit_password_hashing_md5 = |
| 64 | + rabbit_password:hashing_mod(undefined), |
| 65 | + |
| 66 | + rabbit_password_hashing_md5 = |
| 67 | + rabbit_auth_backend_internal:hashing_module_for_user( |
| 68 | + #internal_user{}), |
| 69 | + rabbit_password_hashing_md5 = |
| 70 | + rabbit_auth_backend_internal:hashing_module_for_user( |
| 71 | + #internal_user{ |
| 72 | + hashing_algorithm = undefined |
| 73 | + }), |
| 74 | + rabbit_password_hashing_md5 = |
| 75 | + rabbit_auth_backend_internal:hashing_module_for_user( |
| 76 | + #internal_user{ |
| 77 | + hashing_algorithm = rabbit_password_hashing_md5 |
| 78 | + }), |
| 79 | + |
| 80 | + rabbit_password_hashing_sha256 = |
| 81 | + rabbit_auth_backend_internal:hashing_module_for_user( |
| 82 | + #internal_user{ |
| 83 | + hashing_algorithm = rabbit_password_hashing_sha256 |
| 84 | + }), |
| 85 | + |
| 86 | + passed. |
| 87 | + |
| 88 | +change_password(Config) -> |
| 89 | + passed = rabbit_ct_broker_helpers:run_test_on_broker( |
| 90 | + ?config(rmq_nodename, Config), |
| 91 | + ?MODULE, change_password1, [Config]). |
| 92 | + |
| 93 | +change_password1(_Config) -> |
| 94 | + UserName = <<"test_user">>, |
| 95 | + Password = <<"test_password">>, |
| 96 | + case rabbit_auth_backend_internal:lookup_user(UserName) of |
| 97 | + {ok, _} -> rabbit_auth_backend_internal:delete_user(UserName); |
| 98 | + _ -> ok |
| 99 | + end, |
| 100 | + ok = application:set_env(rabbit, password_hashing_module, |
| 101 | + rabbit_password_hashing_md5), |
| 102 | + ok = rabbit_auth_backend_internal:add_user(UserName, Password), |
| 103 | + {ok, #auth_user{username = UserName}} = |
| 104 | + rabbit_auth_backend_internal:user_login_authentication( |
| 105 | + UserName, [{password, Password}]), |
| 106 | + ok = application:set_env(rabbit, password_hashing_module, |
| 107 | + rabbit_password_hashing_sha256), |
| 108 | + {ok, #auth_user{username = UserName}} = |
| 109 | + rabbit_auth_backend_internal:user_login_authentication( |
| 110 | + UserName, [{password, Password}]), |
| 111 | + |
| 112 | + NewPassword = <<"test_password1">>, |
| 113 | + ok = rabbit_auth_backend_internal:change_password(UserName, NewPassword), |
| 114 | + {ok, #auth_user{username = UserName}} = |
| 115 | + rabbit_auth_backend_internal:user_login_authentication( |
| 116 | + UserName, [{password, NewPassword}]), |
| 117 | + |
| 118 | + {refused, _, [UserName]} = |
| 119 | + rabbit_auth_backend_internal:user_login_authentication( |
| 120 | + UserName, [{password, Password}]), |
| 121 | + passed. |
0 commit comments