Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
948b6ba2c6 | ||
|
|
54c317e452 | ||
|
|
969dbe08ce | ||
|
|
77ee80d3f1 |
No files matched your search
@@ -50,6 +50,9 @@ processed_emails.json
|
||||
storage/deploy-logs/*
|
||||
!storage/deploy-logs/.gitkeep
|
||||
|
||||
# Git credentials (deploy-hook container)
|
||||
.git-credentials
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
@@ -66,12 +66,13 @@ log "Building API + worker ($GIT_SHA)"
|
||||
$COMPOSE build --build-arg GIT_SHA="$GIT_SHA" web
|
||||
remove_stale_service_containers web
|
||||
$COMPOSE up -d --force-recreate web
|
||||
HEALTH_URL="${HEALTH_CHECK_URL:-http://127.0.0.1:8000/api/health}"
|
||||
for i in 1 2 3 4 5; do
|
||||
curl -sf --max-time 8 http://127.0.0.1:8000/api/health >/dev/null && break
|
||||
curl -sf --max-time 8 "$HEALTH_URL" >/dev/null && break
|
||||
log "API not ready yet (attempt $i/5), retrying in 5s..."
|
||||
sleep 5
|
||||
done
|
||||
curl -sf --max-time 8 http://127.0.0.1:8000/api/health >/dev/null
|
||||
curl -sf --max-time 8 "$HEALTH_URL" >/dev/null
|
||||
write_status "ok $GIT_SHA $(date -Iseconds)"
|
||||
log "Deploy OK ($GIT_SHA)"
|
||||
log "Refreshing deploy-hook (self-restart — runs detached)"
|
||||
|
||||
@@ -13,7 +13,12 @@ def get_fernet() -> Fernet:
|
||||
key = get_settings().encryption_key.strip()
|
||||
if not key:
|
||||
raise EncryptionError("ENCRYPTION_KEY is not configured")
|
||||
return Fernet(key.encode() if isinstance(key, str) else key)
|
||||
try:
|
||||
return Fernet(key.encode() if isinstance(key, str) else key)
|
||||
except ValueError as exc:
|
||||
raise EncryptionError(
|
||||
"ENCRYPTION_KEY must be 32 url-safe base64-encoded bytes"
|
||||
) from exc
|
||||
|
||||
|
||||
def encrypt_password(plain: str) -> str:
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
"""Crypto / Fernet key tests."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from cryptography.fernet import Fernet
|
||||
|
||||
from forwarder.crypto import EncryptionError, decrypt_password, encrypt_password, get_fernet
|
||||
|
||||
|
||||
def _make_settings(key: str):
|
||||
fake = type("FakeSettings", (), {"encryption_key": key})()
|
||||
return fake
|
||||
|
||||
|
||||
def test_get_fernet_with_valid_key():
|
||||
key = Fernet.generate_key().decode()
|
||||
with patch("forwarder.crypto.get_settings", return_value=_make_settings(key)):
|
||||
f = get_fernet()
|
||||
assert isinstance(f, Fernet)
|
||||
|
||||
|
||||
def test_get_fernet_empty_key_raises_encryption_error():
|
||||
with patch("forwarder.crypto.get_settings", return_value=_make_settings("")):
|
||||
with pytest.raises(EncryptionError, match="not configured"):
|
||||
get_fernet()
|
||||
|
||||
|
||||
def test_get_fernet_invalid_key_raises_encryption_error():
|
||||
with patch("forwarder.crypto.get_settings", return_value=_make_settings("not-a-valid-fernet-key")):
|
||||
with pytest.raises(EncryptionError, match="32 url-safe base64"):
|
||||
get_fernet()
|
||||
|
||||
|
||||
def test_decrypt_password_with_invalid_key_raises_encryption_error():
|
||||
with patch("forwarder.crypto.get_settings", return_value=_make_settings("bad-key")):
|
||||
with pytest.raises(EncryptionError, match="32 url-safe base64"):
|
||||
decrypt_password("some-token")
|
||||
|
||||
|
||||
def test_encrypt_then_decrypt_roundtrip():
|
||||
key = Fernet.generate_key().decode()
|
||||
with patch("forwarder.crypto.get_settings", return_value=_make_settings(key)):
|
||||
token = encrypt_password("secret123")
|
||||
assert decrypt_password(token) == "secret123"
|
||||
Reference in new issue
Block a user