[Bug]: An invalid vhost on a platform-api deployment returns 500 instead of a validation error
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- go
- Domain
- api, backend-api-design
Research direction
Start in platform-api/internal/service/deployment.go around lines 331–357, where invalid vhostMain and vhostSandbox values are rejected. Compare the existing validation error for base around lines 188–191 and check how platform-api/internal/handler/service_error.go maps service errors. Done means invalid vhosts return a 400 validation error naming the field and reason, while _gateway_default_ remains accepted.
Written by the indexing model from the issue text.
Description
Please select the area the issue is related to
Platform API
Please select the aspect the issue is related to
Aspect/API (API backends, definitions, contracts, interfaces, OpenAPI)
Description
Deploying a REST API through platform-api with an invalid metadata.vhostMain or metadata.vhostSandbox returns 500 INTERNAL_ERROR ("An unexpected error occurred."). It should return a 400 that names the invalid vhost. The value is a caller mistake, but the caller is told the server failed and is given no hint about what to fix.
Observed (POST /api/v0.9/rest-apis/{id}/deployments with base: current and a gatewayId)
metadata.vhostMain: "bad_host":500 {"code":"INTERNAL_ERROR","message":"An unexpected error occurred."}metadata.vhostMain: "-api.example.com"(leading hyphen): the same 500.metadata.vhostMainwith a 64-character label: the same 500.metadata.vhostSandbox: "bad_host": the same 500.metadata.vhostMain: "_gateway_default_": 201, as expected.
Expected
A 400 with a validation error code and a message that says which vhost is invalid and why, as other deployment validation errors do (for example REST_API_DEPLOYMENT_VALIDATION_FAILED).
Cause
platform-api/internal/service/deployment.go:331-357 rejects the value with a plain fmt.Errorf("invalid vhostMain in metadata: %s", …) (and the same for vhostSandbox, and for a non-string value). That is not a catalog error, so serviceError (platform-api/internal/handler/service_error.go:41-46) maps it to apperror.Internal. Using apperror.RESTAPIDeploymentValidationFailed.New(...) there, as deployment.go:188-191 already does for base, would return a 400.
Steps to Reproduce
- Create a REST API in platform-api and attach a connected gateway to it (
POST /api/v0.9/rest-apis/{id}/gateways). - Send
POST /api/v0.9/rest-apis/{id}/deploymentswith{"name": "d1", "base": "current", "gatewayId": "<gateway id>", "metadata": {"vhostMain": "bad_host"}}. - The response is
500 INTERNAL_ERROR.
Severity Level of the Issue
Severity/Minor (Non-critical functionality. Can be fixed in future releases)
Environment Details (with versions)
Current main (e90cde473). Platform-api and gateway built from source and run by the IT suite (tests/framework), on macOS with Rancher Desktop.
- Dominant language
- Go
- Stars
- 85
- Forks
- 137
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 247
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from wso2/api-platform
-
Area/DeveloperPortal Aspect/UI Severity/Minor Type/Bug
Difficulty 1/5 Under an hour Newbie friendliness 88/100
wso2/api-platform#4369 ·
Maintainers usually reply within 1 day
-
[Bug]: host-rewrite policy documentation lists fewer allowed host characters than the policy acceptsOpenArea/Policies Aspect/Other Severity/Trivial Type/Bug
Difficulty 1/5 Under an hour Newbie friendliness 91/100
wso2/api-platform#4355 ·
Maintainers usually reply within 1 day
-
Area/Gateway Aspect/API Severity/Minor Type/Bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
wso2/api-platform#4348 ·
Maintainers usually reply within 1 day
-
Aspect/AI Aspect/API. Severity/Major
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
wso2/api-platform#4343 ·
Maintainers usually reply within 1 day
-
Area/Policies Aspect/Configuration Severity/Minor Type/Bug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
wso2/api-platform#4330 ·
Maintainers usually reply within 1 day
All issues in wso2/api-platform
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Inconsistency between golang and cue in specPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 1/5 Under an hour Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
security
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
Tencent/LoopForge#1087 · 1 comment ·
Maintainers usually reply within 1 day