Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add test for get_private_keys #17

Merged
merged 3 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions inputs/bob.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-----BEGIN CRYPT4GH PUBLIC KEY-----
gPghilyXu+cZy1Iyego3yzZYi5vILe4ZulWDdL4CbGM=
-----END CRYPT4GH PUBLIC KEY-----
3 changes: 3 additions & 0 deletions inputs/bob.sec
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-----BEGIN CRYPT4GH PRIVATE KEY-----
athith-g marked this conversation as resolved.
Show resolved Hide resolved
YzRnaC12MQAEbm9uZQAEbm9uZQAgroAjTA5BPeGfYZBwkk3dmiiIsYBTCvOgDsJVf2X9y3c=
athith-g marked this conversation as resolved.
Show resolved Hide resolved
-----END CRYPT4GH PRIVATE KEY-----
athith-g marked this conversation as resolved.
Show resolved Hide resolved
37 changes: 37 additions & 0 deletions tests/decryption/test_decrypt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""Tests for decrypt.py"""
from pathlib import Path
import pytest

from crypt4gh.keys import get_private_key as get_pk_bytes
from decrypt import get_private_keys

INPUT_DIR = Path(__file__).parents[2]/"inputs"


class TestGetPrivateKeys:
"""Test get_private_keys."""

def test_empty_list(self):
athith-g marked this conversation as resolved.
Show resolved Hide resolved
"""Test empty input."""
assert not get_private_keys([])

def test_invalid_path(self):
"""Test input with an invalid filename."""
with pytest.raises(FileNotFoundError):
get_private_keys([INPUT_DIR/'bad_file_path'])

@pytest.mark.parametrize("files,expected_keys_retrieved", [
athith-g marked this conversation as resolved.
Show resolved Hide resolved
(["alice.pub", "bob.pub", "hello.c4gh"], []),
(["alice.sec", "alice.pub", "bob.pub"], ["alice.sec"]),
(["alice.sec", "bob.sec", "alice.pub", "bob.pub"], ["alice.sec", "bob.sec"])
])
def test_get_keys(self, files, expected_keys_retrieved):
"""Test ability to retrieve keys from a list of files.

Ensure that `get_private_keys` gets only private keys from a list of files.
"""
def get_expected_bytes():
return [get_pk_bytes(INPUT_DIR/filename, callback=lambda x: '')
for filename in expected_keys_retrieved]

assert get_private_keys([INPUT_DIR/file for file in files]) == get_expected_bytes()
athith-g marked this conversation as resolved.
Show resolved Hide resolved