generated from CubeCraft-Creations/Tracehound
fix: harden camera API endpoints (CUB-234) #12
Reference in New Issue
Block a user
Delete Branch "agent/dex/CUB-234-harden-camera-endpoints"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Overview
Hardens all camera API endpoints with input validation, structured error responses, and proper SQL handling.
Changes
Input Validation (new
harden.go)camera_id≤ 64,friendly_name≤ 128,mode≤ 32,resolution≤ 32Structured Error Responses
map[string]stringerrors with typedAPIError {error, code, details}Bug Fixes
MacAddressmodel field:string→*string(fixes NULL scan errors)isUniqueConstraintErr: now matches bothcamera_idandmac_addressconstraint violationssplitSQL: strips--line comments before splitting on semicolons (fixes migration failures withmodernc.org/sqlite)Tests
Files Changed
internal/api/harden.go— new validation and response helpersinternal/api/cameras.go— hardened GET/POST camera handlersinternal/api/recording.go— hardened start/stop handlersinternal/api/status.go— hardened PushStatus handlerinternal/api/camera_test.go— 30 integration testsinternal/db/db.go— fixed SQL line comment strippingpkg/models/camera.go— MacAddress → *stringCloses CUB-234
- Add request validation: Content-Type check, body size limit (64KB) - Add field length validation (camera_id: 64, friendly_name: 128, mode: 32, resolution: 32) - Add FPS range validation (0-240) - Add battery_pct range validation (0-100) - Replace ad-hoc map[string]string errors with structured APIError {error, code, details} - Fix isUniqueConstraintErr to catch both camera_id and mac_address constraint violations - Fix MacAddress model field from string to *string for NULL handling - Fix splitSQL to strip -- line comments before splitting (was causing migration failures with modernc.org/sqlite) - Add 30 integration tests covering all endpoints - All tests pass: ok github.com/cubecraft/remoterig/internal/api