test_password_reset.py
94 lines
| 3.6 KiB
| text/x-python
|
PythonLexer
r5608 | # Copyright (C) 2010-2024 RhodeCode GmbH | |||
r1941 | # | |||
# This program is free software: you can redistribute it and/or modify | ||||
# it under the terms of the GNU Affero General Public License, version 3 | ||||
# (only), as published by the Free Software Foundation. | ||||
# | ||||
# This program is distributed in the hope that it will be useful, | ||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
# GNU General Public License for more details. | ||||
# | ||||
# You should have received a copy of the GNU Affero General Public License | ||||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
# | ||||
# This program is dual-licensed. If you wish to learn more about the | ||||
# RhodeCode Enterprise Edition, including its added features, Support services, | ||||
# and proprietary license terms, please see https://rhodecode.com/licenses/ | ||||
import pytest | ||||
from rhodecode.lib import helpers as h | ||||
from rhodecode.tests import ( | ||||
r2883 | TestController, clear_cache_regions, | |||
r1941 | TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS) | |||
r5607 | from rhodecode.tests.fixtures.rc_fixture import Fixture | |||
r1941 | from rhodecode.tests.utils import AssertResponse | |||
r5173 | from rhodecode.tests.routes import route_path | |||
r1941 | ||||
r5173 | fixture = Fixture() | |||
r1941 | ||||
class TestPasswordReset(TestController): | ||||
@pytest.mark.parametrize( | ||||
'pwd_reset_setting, show_link, show_reset', [ | ||||
('hg.password_reset.enabled', True, True), | ||||
('hg.password_reset.hidden', False, True), | ||||
('hg.password_reset.disabled', False, False), | ||||
]) | ||||
def test_password_reset_settings( | ||||
self, pwd_reset_setting, show_link, show_reset): | ||||
r2883 | clear_cache_regions() | |||
r1941 | self.log_user(TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS) | |||
params = { | ||||
'csrf_token': self.csrf_token, | ||||
'anonymous': 'True', | ||||
'default_register': 'hg.register.auto_activate', | ||||
'default_register_message': '', | ||||
'default_password_reset': pwd_reset_setting, | ||||
'default_extern_activate': 'hg.extern_activate.auto', | ||||
} | ||||
r3386 | resp = self.app.post( | |||
route_path('admin_permissions_application_update'), params=params) | ||||
r1941 | self.logout_user() | |||
login_page = self.app.get(route_path('login')) | ||||
asr_login = AssertResponse(login_page) | ||||
if show_link: | ||||
asr_login.one_element_exists('a.pwd_reset') | ||||
else: | ||||
asr_login.no_element_exists('a.pwd_reset') | ||||
response = self.app.get(route_path('reset_password')) | ||||
r3981 | assert_response = response.assert_response() | |||
r1941 | if show_reset: | |||
response.mustcontain('Send password reset email') | ||||
assert_response.one_element_exists('#email') | ||||
assert_response.one_element_exists('#send') | ||||
else: | ||||
response.mustcontain('Password reset is disabled.') | ||||
assert_response.no_element_exists('#email') | ||||
assert_response.no_element_exists('#send') | ||||
def test_password_form_disabled(self): | ||||
self.log_user(TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS) | ||||
params = { | ||||
'csrf_token': self.csrf_token, | ||||
'anonymous': 'True', | ||||
'default_register': 'hg.register.auto_activate', | ||||
'default_register_message': '', | ||||
'default_password_reset': 'hg.password_reset.disabled', | ||||
'default_extern_activate': 'hg.extern_activate.auto', | ||||
} | ||||
self.app.post(route_path('admin_permissions_application_update'), params=params) | ||||
self.logout_user() | ||||
response = self.app.post( | ||||
route_path('reset_password'), {'email': 'lisa@rhodecode.com',} | ||||
) | ||||
response = response.follow() | ||||
response.mustcontain('Password reset is disabled.') | ||||