From 88478944213914ed96fb8ef3789afaf03a0f4272 Mon Sep 17 00:00:00 2001 From: Glandos Date: Sun, 6 Jun 2021 15:44:48 +0200 Subject: [PATCH] add option to select hash method this will fix tests --- ihatemoney/manage.py | 8 ++++++-- ihatemoney/tests/main_test.py | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ihatemoney/manage.py b/ihatemoney/manage.py index 805a07f3..2b252851 100755 --- a/ihatemoney/manage.py +++ b/ihatemoney/manage.py @@ -34,10 +34,14 @@ def runserver(ctx): @click.command(name="generate_password_hash") -def password_hash(): +@click.option( + "--method", + help="""Password method. See https://werkzeug.palletsprojects.com/en/2.0.x/utils/#werkzeug.security.generate_password_hash""", # NOQA +) +def password_hash(method): """Get password from user and hash it without printing it in clear text.""" password = getpass.getpass(prompt="Password: ") - print(generate_password_hash(password)) + print(generate_password_hash(password, method=method)) @click.command() diff --git a/ihatemoney/tests/main_test.py b/ihatemoney/tests/main_test.py index f052ee01..348cb669 100644 --- a/ihatemoney/tests/main_test.py +++ b/ihatemoney/tests/main_test.py @@ -89,8 +89,8 @@ class CommandTestCase(BaseTestCase): def test_generate_password_hash(self): runner = self.app.test_cli_runner() with patch("getpass.getpass", new=lambda prompt: "secret"): - result = runner.invoke(password_hash) - self.assertEqual(len(result.output.strip()), 94) + result = runner.invoke(password_hash, ["--method", "pbkdf2:sha256:260000"]) + self.assertEqual(len(result.output.strip()), 102) def test_demo_project_deletion(self): self.create_project("demo")