Skip to content

Commit

Permalink
Merge 28d6d81 into 316c261
Browse files Browse the repository at this point in the history
  • Loading branch information
jugmac00 committed Dec 19, 2020
2 parents 316c261 + 28d6d81 commit 2a1fe45
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def read(*parts):
zip_safe=True,
install_requires=[
"click>=7.1.2",
"pykeepass>=3.2.0",
"pykeepass>=3.2.1",
"httpx>=0.13.3",
],
entry_points={"console_scripts": ["hibpcli = hibpcli.cli:main"]},
Expand Down
4 changes: 3 additions & 1 deletion src/hibpcli/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Optional

import click
from hibpcli.exceptions import ApiError
from hibpcli.exceptions import ApiError, KeepassError
from hibpcli.keepass import check_passwords_from_db
from hibpcli.password import Password

Expand All @@ -23,6 +23,8 @@ def check_keepass(path: str, password: Optional[str]) -> None:
)
try:
rv = check_passwords_from_db(path=path, master_password=password)
except KeepassError:
click.echo("The entered password is not correct. Please try again.")
except ApiError as e:
click.echo(str(e))
else:
Expand Down
4 changes: 4 additions & 0 deletions src/hibpcli/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ class HibpError(Exception):

class ApiError(HibpError):
pass


class KeepassError(HibpError):
pass
16 changes: 12 additions & 4 deletions src/hibpcli/keepass.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
from typing import List

from hibpcli.exceptions import KeepassError
from hibpcli.password import Password
from pykeepass import PyKeePass # type: ignore
from pykeepass.exceptions import CredentialsError


def check_passwords_from_db(path: str, master_password: str) -> List[str]:
""" - """
kp = PyKeePass(path, password=master_password)
return [
entry for entry in kp.entries if Password(password=entry.password).is_leaked()
]
try:
kp = PyKeePass(path, password=master_password)
except CredentialsError:
raise KeepassError
else:
return [
entry
for entry in kp.entries
if Password(password=entry.password).is_leaked()
]
8 changes: 8 additions & 0 deletions tests/test_cli_for_check_keepass.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,11 @@ def test_keepass_subcommand_error_handling(mock_password):
)
expected_output = "Error\n"
assert result.output == expected_output


def test_keepass_wrong_password():
runner = CliRunner()
result = runner.invoke(
main, ["check-keepass", "tests/test.kdbx", "--password", "wrong-password"]
)
assert result.output == "The entered password is not correct. Please try again.\n"

0 comments on commit 2a1fe45

Please sign in to comment.