[Bug]: An invalid vhost on a platform-api deployment returns 500 instead of a validation error

Aperta Adatta ai principianti
#4,166 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go

Direzione di ricerca

Inizia in platform-api/internal/service/deployment.go intorno alle righe 331–357, dove vengono rifiutati i valori non validi di vhostMain e vhostSandbox. Confronta l’errore di validazione esistente per base intorno alle righe 188–191 e controlla come platform-api/internal/handler/service_error.go associa gli errori del servizio. Il lavoro è completato quando i vhost non validi restituiscono un errore di validazione 400 che indica il campo e il motivo, mentre _gateway_default_ continua a essere accettato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Area/Platform-API Aspect/API Severity/Minor Type/Bug
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.vhostMain with 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
  1. Create a REST API in platform-api and attach a connected gateway to it (POST /api/v0.9/rest-apis/{id}/gateways).
  2. Send POST /api/v0.9/rest-apis/{id}/deployments with {"name": "d1", "base": "current", "gatewayId": "<gateway id>", "metadata": {"vhostMain": "bad_host"}}.
  3. 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.

Lingua principale
Go
Stelle
85
Fork
137
Merge medio
1g 12h
PR unite (30g)
247

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di wso2/api-platform

Tutte le issue di wso2/api-platform

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.