浏览代码

[minor] ignore password strength test in frappe.in_test (#3423)

* Fixed issue #frappe WN-SUP25323 for password strength error

* [hotfix] fixes in password strength test

* [hotfix] ignore password strength test in tests
version-14
Makarand Bauskar 8 年前
committed by Nabin Hait
父节点
当前提交
c45b575a93
共有 2 个文件被更改,包括 15 次插入6 次删除
  1. +6
    -3
      frappe/core/doctype/user/user.py
  2. +9
    -3
      frappe/utils/password_strength.py

+ 6
- 3
frappe/core/doctype/user/user.py 查看文件

@@ -49,7 +49,9 @@ class User(Document):
self.__new_password = self.new_password
self.new_password = ""

self.password_strength_test()
if not frappe.flags.in_test:
self.password_strength_test()

if self.name not in STANDARD_USERS:
self.validate_email_type(self.email)
self.validate_email_type(self.name)
@@ -409,7 +411,8 @@ class User(Document):
self.username = ""

def password_strength_test(self):
if self.__new_password:
""" test password strength """
if frappe.db.get_single_value("System Settings", "enable_password_policy") and self.__new_password:
user_data = (self.first_name, self.middle_name, self.last_name, self.email, self.birth_date)
result = test_password_strength(self.__new_password, '', None, user_data)

@@ -869,4 +872,4 @@ def handle_password_test_fail(result):
suggestions = result['feedback']['suggestions'][0] if result['feedback']['suggestions'] else ''
warning = result['feedback']['warning'] if 'warning' in result['feedback'] else ''
suggestions += "<br>" + _("Hint: Include symbols, numbers and capital letters in the password") + '<br>'
frappe.throw(_('Invalid Password: ' + ' '.join([warning, suggestions])))
frappe.throw(_('Invalid Password: ' + ' '.join([warning, suggestions])))

+ 9
- 3
frappe/utils/password_strength.py 查看文件

@@ -2,8 +2,10 @@
# MIT License. See license.txt

from __future__ import unicode_literals
from frappe import _
import zxcvbn
import frappe
from frappe import _

def test_password_strength(password, user_inputs=None):
'''Wrapper around zxcvbn.password_strength'''
@@ -35,12 +37,14 @@ def get_feedback (score, sequence):
"""
Returns the feedback dictionary consisting of ("warning","suggestions") for the given sequences.
"""
minimum_password_score = frappe.db.get_single_value("System Settings", "minimum_password_score")

global default_feedback
# Starting feedback
if len(sequence) == 0:
return default_feedback
# No feedback if score is good or great
if score > 2:
if score > minimum_password_score:
return dict({"warning": "","suggestions": []})
# Tie feedback to the longest match for longer sequences
longest_match = max(sequence, key=lambda x: len(x['token']))
@@ -132,7 +136,9 @@ def get_match_feedback(match, is_sole_match):
"date": fun_date,
"year": fun_date
}
return(patterns[match['pattern']]())
pattern_fn = patterns.get(match['pattern'])
if pattern_fn:
return(pattern_fn())

def get_dictionary_match_feedback(match, is_sole_match):
"""


正在加载...
取消
保存