Standardize UUID validation across all REST API controllers#4591
Standardize UUID validation across all REST API controllers#4591m4cd4r4 wants to merge 1 commit into
Conversation
Extract a shared validate_uuid/1 function into LightningWeb.API.Helpers using the existing Ecto.UUID.dump/1 pattern. Replace private duplicate implementations in WorkflowsController and CredentialController. Apply validation to all controllers that accept UUID path or query params, so malformed UUIDs return 400 instead of raising Ecto.Query.CastError (500). Closes OpenFn#4588
e6abefc to
516e7a6
Compare
|
Rebased onto current Conflicts resolved:
Test failure root cause: The second failure in the prior CI ( CI is re-running now. |
Summary
Closes #4588.
Malformed UUID path/query params currently reach
Repo.getand raiseEcto.Query.CastError, which Phoenix turns into a 500 response. This extracts a sharedvalidate_uuid/1helper and applies it consistently across all REST API controllers.Changes:
validate_uuid/1toLightningWeb.API.Helpers- returns:okor{:error, :bad_request}WorkflowsController- privatevalidate_uuid/1now delegates to the shared helper (preserves existing 422 message behaviour viamaybe_handle_error)CredentialController- replaces privatevalidate_uuid/1with shared helper; malformed credentialidnow returns 400 instead of 404JobController,ProjectController,RunController,WorkOrdersController,ProvisioningController,AiAssistantController- addvalidate_uuid/1calls before any DB lookup that would otherwise raiseEcto.Query.CastErrorTests: UUID validation test cases added to all affected controller test files.
AI disclosure
Test plan
not-a-uuidinputsmix test test/lightning_web/controllers/api/passes