fix(backend): validate non-negative prices, bounds, and typing in storefront models ($25 bounty proposal)
Closed
AI
8h ago+103+103+012345678901234567890123456789-22-22-01234567890123456789
Description
Validates non-negative prices, bounds, and typing in storefront models.
Currently:
StorefrontPricedefinesamount_minor: intwithout lower-bound constraints, allowing negative price amounts to be deserialized.months_freeinStorefrontPriceandcatalog_revisioninStorefrontResponselack non-negative bounds (ge=0).percentinStorefrontUsagelacks range bounds (ge=0, le=100).- Uses standard
Optional[...]across storefront models for typing consistency.
This change:
- Adds
ge=0bounds toamount_minor,months_free, andcatalog_revision. - Constrains
percentinStorefrontUsageto[0, 100]. - Enforces non-empty
currencystrings (min_length=1, max_length=10). - Adds hermetic unit test coverage in
backend/tests/unit/test_storefront_validation.py.
Test Plan
- Run unit tests:
Result: 9/9 tests passed in 0.005s.PYTHONPATH=backend python3 backend/tests/unit/test_storefront_validation.py