Skip to content
Open
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
6 changes: 4 additions & 2 deletions deep_agent/aegra/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ def __init__(self, message: str, status_code: int = 401):
def validate_api_key(provided_key: str) -> bool:
"""Constant-time comparison of API keys to prevent timing attacks."""
if not API_KEY:
logger.warning("LANGGRAPH_API_KEY not set — all keys accepted")
return True
raise AuthError(
"LANGGRAPH_API_KEY is not configured; API key authentication is unavailable",
status_code=500,
)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
return hmac.compare_digest(provided_key.encode(), API_KEY.encode())


Expand Down
6 changes: 4 additions & 2 deletions tests/unit/aegra/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ def test_custom_status(self):


class TestValidateApiKey:
def test_accepts_when_no_key_configured(self):
def test_raises_when_no_key_configured(self):
with patch("deep_agent.aegra.middleware.API_KEY", ""):
assert validate_api_key("anything") is True
with pytest.raises(AuthError, match="not configured") as exc_info:
validate_api_key("anything")
assert exc_info.value.status_code == 500

def test_accepts_correct_key(self):
with patch("deep_agent.aegra.middleware.API_KEY", "secret123"):
Expand Down
Loading