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

Refactor project structure and update script namespaces. #80

Merged
merged 1 commit into from
Dec 20, 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
5 changes: 4 additions & 1 deletion envex/dot_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,11 @@ def _process_env(
environ["PWD"] = str(env_path.parent)
try:
with open_env(env_path) as f:
data = f.read()
if isinstance(data, str):
data = data.encode(encoding)
load_stream(
BytesIO(f.read()),
BytesIO(data),
environ,
overwrite,
errors,
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions scripts/env2hvac.py → envex/scripts/env2hvac.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ def handler(
def main():
import argparse

from scripts.lib.decr_action import Decrement
from scripts.lib.log import config as log_config
from scripts.lib.log import log_get_level, log_set_level
from envex.scripts.lib.decr_action import Decrement
from envex.scripts.lib.log import config as log_config
from envex.scripts.lib.log import log_get_level, log_set_level

log_config()

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file added envex/scripts/lib/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ classifiers = [
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3 :: Only",
]
scripts = {envcrypt = "scripts.envcrypt:main", env2hvac = "scripts.env2hvac:main", envsecrets = "scripts.envsecrets:main", seal = "scripts.seal:main"}
scripts = {envcrypt = "envex.scripts.envcrypt:main", env2hvac = "envex.scripts.env2hvac:main", envsecrets = "envex.scripts.envsecrets:main", seal = "envex.scripts.seal:main"}

[project.urls]
homepage = "https://github.com/deeprave/envex"
Expand Down
9 changes: 0 additions & 9 deletions tests/test_env_crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@ def encrypted_stream_with_invalid_magic_bytes():
return BytesIO(b"DATA_WITH_INVALID_MAGIC_BYTES")


@pytest.mark.unit
def test_encrypt_data_success(password):
input_data = BytesIO(b"test data")
result = encrypt_data(input_data, password)
assert isinstance(result, BytesIO)
assert result.getvalue() != b"test data" # Ensure data is encrypted


@pytest.mark.unit
def test_encrypt_decrypt_unicode_(password):
test_string = "\u00a9 test data \u06a2"
input_data = StringIO(test_string)
Expand All @@ -44,23 +42,20 @@ def test_encrypt_decrypt_unicode_(password):
assert result.getvalue().decode("utf-8") == test_string


@pytest.mark.unit
def test_encrypt_data_no_password():
input_data = BytesIO(b"test data")
password = ""
with pytest.raises(EncryptError):
encrypt_data(input_data, password)


@pytest.mark.unit
def test_encrypt_data_already_encrypted(password):
input_data = BytesIO(b"Some Test data data")
input_enc = encrypt_data(input_data, password)
with pytest.raises(EncryptError):
encrypt_data(input_enc, password)


@pytest.mark.unit
def test_encrypt_empty_data():
input_data = BytesIO(b"")
password = "strongpassword123"
Expand All @@ -77,23 +72,20 @@ def test_encrypt_large_data(password):
assert input_data.getvalue() == decrypt_data(result, password).getvalue()


@pytest.mark.unit
def test_valid_decryption(password):
encrypted_stream = encrypt_data(BytesIO(b"VALID_ENCRYPTED_DATA"), password)
result = decrypt_data(encrypted_stream, password)
assert isinstance(result, BytesIO)
assert result.getvalue() == b"VALID_ENCRYPTED_DATA"


@pytest.mark.unit
def test_invalid_magic_bytes(encrypted_stream_with_invalid_magic_bytes, password):
# Ensure decryption fails on invalid magic bytes
with pytest.raises(DecryptError) as e:
decrypt_data(encrypted_stream_with_invalid_magic_bytes, password)
assert "does not look to be encrypted" in str(e.value)


@pytest.mark.unit
def test_invalid_password(incorrect_password, password):
data = b"VALID_ENCRYPTED_DATA"
encrypted_data = encrypt_data(BytesIO(data), password)
Expand All @@ -103,7 +95,6 @@ def test_invalid_password(incorrect_password, password):
assert "Incorrect password or invalid data" in str(e.value)


@pytest.mark.unit
def test_empty_stream(password):
# Test with an empty BytesIO stream
empty_stream = BytesIO()
Expand Down
36 changes: 33 additions & 3 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading