feat: move project from poetry to pdm, rewrite from scratch and add

basic `notebooks`, `edit` and `show` commands
This commit is contained in:
cătălin 2023-04-01 12:37:10 +02:00
commit d3ad87211e
Signed by: catalin
GPG key ID: 686088EF78EE4083
35 changed files with 1309 additions and 1434 deletions

54
tests/test_encryption.py Normal file
View file

@ -0,0 +1,54 @@
from pyrage import decrypt, encrypt, x25519
from halig.encryption import Encryptor
from halig.settings import Settings
def test_instance_encryptor_from_age_keys(halig_path, notebooks_path):
identity = x25519.Identity.generate()
identity_path = halig_path / "identity.key"
identity_path.touch()
recipient_path = halig_path / "recipient.key"
recipient_path.touch()
with identity_path.open("w") as f:
f.write(str(identity))
with recipient_path.open("w") as f:
f.write(str(identity.to_public()))
settings = Settings(
notebooks_root_path=notebooks_path,
identity_path=identity_path,
recipient_path=recipient_path,
)
assert Encryptor(settings)
def test_encrypt(encryptor: Encryptor, ssh_identity):
unencrypted_data = "foo"
encrypted_data = encryptor.encrypt(unencrypted_data)
assert isinstance(encrypted_data, bytes)
assert unencrypted_data == decrypt(encrypted_data, [ssh_identity]).decode()
def test_encrypt_bytes(encryptor: Encryptor, ssh_identity):
unencrypted_data = b"foo"
encrypted_data = encryptor.encrypt(unencrypted_data)
assert isinstance(encrypted_data, bytes)
assert unencrypted_data == decrypt(encrypted_data, [ssh_identity])
def test_decrypt(encryptor: Encryptor, ssh_recipient):
unencrypted_data = "foo"
encrypted_data = encrypt(unencrypted_data.encode(), [ssh_recipient])
decrypted_data = encryptor.decrypt(encrypted_data)
assert decrypted_data.decode() == unencrypted_data
def test_decrypt_bytes(encryptor: Encryptor, ssh_recipient):
unencrypted_data = b"foo"
encrypted_data = encrypt(unencrypted_data, [ssh_recipient])
decrypted_data = encryptor.decrypt(encrypted_data)
assert decrypted_data == unencrypted_data