ask users to repeat password

In case if password is asked via getpass, it is possible to make typo
and user will not see the mistake. In order to avoid it, additional
confirmation has been added
This commit is contained in:
2022-11-22 02:19:37 +02:00
parent 137d62e2f8
commit 78e6b48c24
3 changed files with 41 additions and 5 deletions

View File

@ -3,11 +3,12 @@ import pytest
from pathlib import Path
from pytest_mock import MockerFixture
from unittest.mock import call as MockCall
from ahriman.application.handlers import Users
from ahriman.core.configuration import Configuration
from ahriman.core.database import SQLite
from ahriman.core.exceptions import InitializeError
from ahriman.core.exceptions import InitializeError, PasswordError
from ahriman.models.action import Action
from ahriman.models.user import User
from ahriman.models.user_access import UserAccess
@ -214,14 +215,25 @@ def test_user_create_getpass(args: argparse.Namespace, mocker: MockerFixture) ->
"""
args = _default_args(args)
args.password = None
getpass_mock = mocker.patch("getpass.getpass", return_value="password")
generated = Users.user_create(args)
getpass_mock.assert_called_once_with()
generated = Users.user_create(args)
getpass_mock.assert_has_calls([MockCall(), MockCall("Repeat password: ")])
assert generated.password == "password"
def test_user_create_getpass_exception(args: argparse.Namespace, mocker: MockerFixture) -> None:
"""
must raise password error in case if password doesn't match
"""
args = _default_args(args)
args.password = None
mocker.patch("getpass.getpass", side_effect=lambda *_: User.generate_password(10))
with pytest.raises(PasswordError):
Users.user_create(args)
def test_disallow_auto_architecture_run() -> None:
"""
must not allow multi architecture run