[mod] password argument can't have a default value

This commit is contained in:
Laurent Peuch 2020-06-01 12:02:04 +02:00
parent 40dc8397c1
commit dc6a12f14b
3 changed files with 9 additions and 1 deletions

View file

@ -13,6 +13,7 @@
"app_already_up_to_date": "{app:s} is already up-to-date", "app_already_up_to_date": "{app:s} is already up-to-date",
"app_argument_choice_invalid": "Use one of these choices '{choices:s}' for the argument '{name:s}'", "app_argument_choice_invalid": "Use one of these choices '{choices:s}' for the argument '{name:s}'",
"app_argument_invalid": "Pick a valid value for the argument '{name:s}': {error:s}", "app_argument_invalid": "Pick a valid value for the argument '{name:s}': {error:s}",
"app_argument_password_no_default": "Error while parsing password argument '{name}': password argument can't have a default value for security reason",
"app_argument_required": "Argument '{name:s}' is required", "app_argument_required": "Argument '{name:s}' is required",
"app_change_url_failed_nginx_reload": "Could not reload NGINX. Here is the output of 'nginx -t':\n{nginx_errors:s}", "app_change_url_failed_nginx_reload": "Could not reload NGINX. Here is the output of 'nginx -t':\n{nginx_errors:s}",
"app_change_url_identical_domains": "The old and new domain/url_path are identical ('{domain:s}{path:s}'), nothing to do.", "app_change_url_identical_domains": "The old and new domain/url_path are identical ('{domain:s}{path:s}'), nothing to do.",

View file

@ -2468,6 +2468,14 @@ class PasswordArgumentParser(YunoHostArgumentFormatParser):
argument_type = "password" argument_type = "password"
default_value = "" default_value = ""
def parse_question(self, question, user_answers):
question = super(PasswordArgumentParser, self).parse_question(question, user_answers)
if question.default is not None:
raise YunohostError('app_argument_password_no_default', name=question.name)
return question
class PathArgumentParser(YunoHostArgumentFormatParser): class PathArgumentParser(YunoHostArgumentFormatParser):
argument_type = "path" argument_type = "path"

View file

@ -276,7 +276,6 @@ def test_parse_args_in_yunohost_format_password_optional_with_input_without_ask(
assert _parse_args_in_yunohost_format(answers, questions) == expected_result assert _parse_args_in_yunohost_format(answers, questions) == expected_result
@pytest.mark.skip # this should raises
def test_parse_args_in_yunohost_format_password_no_input_default(): def test_parse_args_in_yunohost_format_password_no_input_default():
questions = [ questions = [
{ {