[fix] re-put assert password is strong enough

This commit is contained in:
Laurent Peuch 2020-07-03 00:57:09 +02:00
parent 2eb5f6b6da
commit bcd2364d74
2 changed files with 24 additions and 2 deletions

View file

@ -2484,6 +2484,9 @@ class PasswordArgumentParser(YunoHostArgumentFormatParser):
if any(char in question.value for char in self.forbidden_chars):
raise YunohostError('pattern_password_app', forbidden_chars=self.forbidden_chars)
from yunohost.utils.password import assert_password_is_strong_enough
assert_password_is_strong_enough('user', question.value)
return super(PasswordArgumentParser, self)._post_parse_value(question)

View file

@ -247,8 +247,9 @@ def test_parse_args_in_yunohost_format_password_input_no_ask():
def test_parse_args_in_yunohost_format_password_no_input_optional():
questions = [{"name": "some_password", "type": "password", "optional": True,}]
answers = {}
expected_result = OrderedDict({"some_password": ("", "password")})
assert _parse_args_in_yunohost_format(answers, questions) == expected_result
with pytest.raises(YunohostError):
_parse_args_in_yunohost_format(answers, questions)
def test_parse_args_in_yunohost_format_password_optional_with_input():
@ -374,6 +375,24 @@ def test_parse_args_in_yunohost_format_password_bad_chars():
_parse_args_in_yunohost_format({"some_password": i * 8}, questions)
def test_parse_args_in_yunohost_format_password_strong_enough():
questions = [
{
"name": "some_password",
"type": "password",
"ask": "some question",
"example": "some_value",
}
]
with pytest.raises(YunohostError):
# too short
_parse_args_in_yunohost_format({"some_password": "a"}, questions)
with pytest.raises(YunohostError):
_parse_args_in_yunohost_format({"some_password": "password"}, questions)
def test_parse_args_in_yunohost_format_path():
questions = [{"name": "some_path", "type": "path",}]
answers = {"some_path": "some_value"}