An optional password should be either empty or strong enough

This commit is contained in:
Kay0u 2020-11-25 11:41:00 +01:00
parent 93fd101663
commit f0d3d36365
No known key found for this signature in database
GPG key ID: AAFEEB16CFA2AE2D
2 changed files with 20 additions and 1 deletions

View file

@ -2498,7 +2498,8 @@ 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)
if not question.optional:
# If it's an optional argument the value should be empty or strong enough
if not question.optional or question.value:
from yunohost.utils.password import assert_password_is_strong_enough
assert_password_is_strong_enough('user', question.value)

View file

@ -418,6 +418,24 @@ def test_parse_args_in_yunohost_format_password_strong_enough():
_parse_args_in_yunohost_format({"some_password": "password"}, questions)
def test_parse_args_in_yunohost_format_password_optional_strong_enough():
questions = [
{
"name": "some_password",
"ask": "some question",
"type": "password",
"optional": True,
}
]
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"}