##// END OF EJS Templates
tests: password reset hidden/disabled options tests fix #3944
lisaq -
r1036:54572a14 default
parent child Browse files
Show More
@@ -309,7 +309,7 b''
309 309 <div class="label">
310 310 <label for="password">${_('Password')}:</label>
311 311 %if h.HasPermissionAny('hg.password_reset.enabled')():
312 <span class="forgot_password">${h.link_to(_('(Forgot password?)'),h.route_path('reset_password'))}</span>
312 <span class="forgot_password">${h.link_to(_('(Forgot password?)'),h.route_path('reset_password'), class_='pwd_reset')}</span>
313 313 %endif
314 314 </div>
315 315 <div class="input">
@@ -25,7 +25,8 b' import pytest'
25 25
26 26 from rhodecode.config.routing import ADMIN_PREFIX
27 27 from rhodecode.tests import (
28 assert_session_flash, url, HG_REPO, TEST_USER_ADMIN_LOGIN)
28 TestController, assert_session_flash, clear_all_caches, url,
29 HG_REPO, TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS)
29 30 from rhodecode.tests.fixture import Fixture
30 31 from rhodecode.tests.utils import AssertResponse, get_session_from_response
31 32 from rhodecode.lib.auth import check_password, generate_auth_token
@@ -39,6 +40,7 b' fixture = Fixture()'
39 40
40 41 # Hardcode URLs because we don't have a request object to use
41 42 # pyramids URL generation methods.
43 index_url = '/'
42 44 login_url = ADMIN_PREFIX + '/login'
43 45 logut_url = ADMIN_PREFIX + '/logout'
44 46 register_url = ADMIN_PREFIX + '/register'
@@ -517,3 +519,70 b' class TestLoginController:'
517 519 repo_name=HG_REPO, revision='tip',
518 520 api_key=new_auth_token.api_key),
519 521 status=302)
522
523
524 class TestPasswordReset(TestController):
525
526 @pytest.mark.parametrize(
527 'pwd_reset_setting, show_link, show_reset', [
528 ('hg.password_reset.enabled', True, True),
529 ('hg.password_reset.hidden', False, True),
530 ('hg.password_reset.disabled', False, False),
531 ])
532 def test_password_reset_settings(
533 self, pwd_reset_setting, show_link, show_reset):
534 clear_all_caches()
535 self.log_user(TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS)
536 params = {
537 'csrf_token': self.csrf_token,
538 'anonymous': 'True',
539 'default_register': 'hg.register.auto_activate',
540 'default_register_message': '',
541 'default_password_reset': pwd_reset_setting,
542 'default_extern_activate': 'hg.extern_activate.auto',
543 }
544 resp = self.app.post(url('admin_permissions_application'), params=params)
545 self.logout_user()
546
547 login_page = self.app.get(login_url)
548 asr_login = AssertResponse(login_page)
549 index_page = self.app.get(index_url)
550 asr_index = AssertResponse(index_page)
551
552 if show_link:
553 asr_login.one_element_exists('a.pwd_reset')
554 asr_index.one_element_exists('a.pwd_reset')
555 else:
556 asr_login.no_element_exists('a.pwd_reset')
557 asr_index.no_element_exists('a.pwd_reset')
558
559 pwdreset_page = self.app.get(pwd_reset_url)
560
561 asr_reset = AssertResponse(pwdreset_page)
562 if show_reset:
563 assert 'Send password reset email' in pwdreset_page
564 asr_reset.one_element_exists('#email')
565 asr_reset.one_element_exists('#send')
566 else:
567 assert 'Password reset has been disabled.' in pwdreset_page
568 asr_reset.no_element_exists('#email')
569 asr_reset.no_element_exists('#send')
570
571 def test_password_form_disabled(self):
572 self.log_user(TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS)
573 params = {
574 'csrf_token': self.csrf_token,
575 'anonymous': 'True',
576 'default_register': 'hg.register.auto_activate',
577 'default_register_message': '',
578 'default_password_reset': 'hg.password_reset.disabled',
579 'default_extern_activate': 'hg.extern_activate.auto',
580 }
581 self.app.post(url('admin_permissions_application'), params=params)
582 self.logout_user()
583
584 pwdreset_page = self.app.post(
585 pwd_reset_url,
586 {'email': 'lisa@rhodecode.com',}
587 )
588 assert 'Password reset has been disabled.' in pwdreset_page
General Comments 0
You need to be logged in to leave comments. Login now