mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
fix(guardrails): reject non-canonical date formats in usage windows
This commit is contained in:
parent
c9bfb7f0ab
commit
eb3ed6cf39
2 changed files with 16 additions and 0 deletions
|
|
@ -65,6 +65,11 @@ def _resolve_usage_window(start_date: str | None, end_date: str | None) -> tuple
|
|||
detail="start_date and end_date must be in YYYY-MM-DD format",
|
||||
)
|
||||
start_obj, end_obj = parsed
|
||||
if (start_obj.isoformat(), end_obj.isoformat()) != (start, end):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail="start_date and end_date must be in YYYY-MM-DD format",
|
||||
)
|
||||
if end_obj < start_obj:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
|
|
|
|||
|
|
@ -393,6 +393,17 @@ async def test_overview_rejects_malformed_dates():
|
|||
assert exc.value.status_code == 400
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_overview_rejects_non_canonical_date_format():
|
||||
prisma = _prisma()
|
||||
handler = _config_handler()
|
||||
p1, p2 = _patches(prisma, handler)
|
||||
with p1, p2, pytest.raises(HTTPException) as exc:
|
||||
await guardrails_usage_overview(start_date="20260420", end_date=END, user_api_key_dict=ADMIN)
|
||||
assert exc.value.status_code == 400
|
||||
assert "YYYY-MM-DD" in str(exc.value.detail)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_detail_rejects_reversed_dates():
|
||||
prisma = _prisma(find_unique=_db_row())
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue