mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
An optional password should be either empty or strong enough
This commit is contained in:
parent
93fd101663
commit
f0d3d36365
2 changed files with 20 additions and 1 deletions
|
@ -2498,7 +2498,8 @@ class PasswordArgumentParser(YunoHostArgumentFormatParser):
|
||||||
if any(char in question.value for char in self.forbidden_chars):
|
if any(char in question.value for char in self.forbidden_chars):
|
||||||
raise YunohostError('pattern_password_app', forbidden_chars=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
|
from yunohost.utils.password import assert_password_is_strong_enough
|
||||||
assert_password_is_strong_enough('user', question.value)
|
assert_password_is_strong_enough('user', question.value)
|
||||||
|
|
||||||
|
|
|
@ -418,6 +418,24 @@ def test_parse_args_in_yunohost_format_password_strong_enough():
|
||||||
_parse_args_in_yunohost_format({"some_password": "password"}, questions)
|
_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():
|
def test_parse_args_in_yunohost_format_path():
|
||||||
questions = [{"name": "some_path", "type": "path", }]
|
questions = [{"name": "some_path", "type": "path", }]
|
||||||
answers = {"some_path": "some_value"}
|
answers = {"some_path": "some_value"}
|
||||||
|
|
Loading…
Add table
Reference in a new issue