Skip to content

Commit

Permalink
Add test for decrypt_to_stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
elikoga committed Oct 15, 2024
1 parent 58414dd commit e28a377
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
21 changes: 20 additions & 1 deletion src/batou/secrets/tests/test_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@

from batou.environment import UnknownEnvironmentError

from ..manage import add_user, reencrypt, remove_user, summary
from ..encryption import GPGEncryptedFile
from ..manage import (
add_user,
decrypt_to_stdout,
reencrypt,
remove_user,
summary,
)
from .test_secrets import cleartext_file, encrypted_file


@pytest.mark.parametrize("func", (add_user, remove_user))
Expand Down Expand Up @@ -136,3 +144,14 @@ def test_manage__reencrypt__1(tmp_path, monkeypatch, capsys):
assert old[path] != new[path]

assert set(old) == set(new)


def test_manage__decrypt_to_stdout__1(encrypted_file, capsys):
"""It decrypts a file and writes the content to stdout."""
with GPGEncryptedFile(encrypted_file) as secret:
with open(cleartext_file) as cleartext:
# assert cleartext.read().strip() == secret.cleartext.strip()
assert decrypt_to_stdout(str(encrypted_file)) == 0
out, err = capsys.readouterr()
assert out == cleartext.read()
assert err == ""
2 changes: 1 addition & 1 deletion src/batou/secrets/tests/test_secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

FIXTURE = pathlib.Path(__file__).parent / "fixture"
cleartext_file = FIXTURE / "cleartext.cfg"
FIXTURE_ENCRYPTED_CONFIG = FIXTURE / "encrypted.cfg"
FIXTURE_ENCRYPTED_CONFIG = FIXTURE / "encrypted.cfg.gpg"


@pytest.fixture(scope="function")
Expand Down

0 comments on commit e28a377

Please sign in to comment.