27 lines
898 B
Python
27 lines
898 B
Python
"""Tests various error types."""
|
|
|
|
from pathlib import Path
|
|
import pykeepass
|
|
import pykeepass.exceptions
|
|
import pytest
|
|
|
|
from sshecret_admin.services.keepass import PasswordContext, _password_context, PasswordCredentialsError
|
|
|
|
def test_open_invalid_database() -> None:
|
|
"""Test opening a non-existing database."""
|
|
bogus_path = Path("/tmp/non/existing/password/database.kdbx")
|
|
|
|
with pytest.raises(FileNotFoundError):
|
|
with _password_context(bogus_path, "foobar") as context:
|
|
assert context is not None
|
|
|
|
|
|
def test_incorrect_password(tmp_path: Path) -> None:
|
|
"""Test opening database with incorrect password."""
|
|
filename = tmp_path / "db.kdbx"
|
|
pykeepass.create_database(str(filename), password="correct")
|
|
|
|
with pytest.raises(PasswordCredentialsError):
|
|
with _password_context(filename, "incorrect") as context:
|
|
assert context is not None
|