Repository navigation
Description
POST /auth-app/tokens is meant to answer 201 Created, but always answers 200 OK. HandleCreate writes the response body first and calls w.WriteHeader(http.StatusCreated) only afterwards: by then the status has already been sent as 200, and the WriteHeader call has no effect.
HandleList has the same pattern twice: w.WriteHeader(http.StatusOK) after the body (no effect, but harmless), and w.WriteHeader(http.StatusInternalServerError) after a failed w.Write (no effect either: the client already got 200).
Steps to reproduce
Reproduced on main (d43947a209), with the auth-app service running (OC_ADD_RUN_SERVICES=auth-app) and basic auth enabled.
curl -si -XPOST 'https://<host>/auth-app/tokens?expiry=72h' -u <user>:<password> | head -1
Expected
HTTP/2 201, as the code intends.
Actual
HTTP/2 200, with the new token in the body. The acceptance tests in tests/acceptance/features/apiAuthApp/token.feature expect, and get, 200 (lines 12, 41 and 111).
Where
services/auth-app/pkg/service/service.go: HandleCreate (the w.Write(b) followed by w.WriteHeader(http.StatusCreated)) and HandleList (the w.WriteHeader calls after w.Write).
Neither HandleCreate nor HandleList sets Content-Type: application/json, so their JSON bodies are sent as text/plain; charset=utf-8.
Fix
Two options, which differ in what clients see:
- Send
201for real: callw.WriteHeader(http.StatusCreated)beforew.Write(b), and change the three acceptance test expectations to201. This is the correct status for a create, but changes the API's behaviour: a client that checks for exactly200would break. Within opencloud-eu only the acceptance tests do; web and the release tests accept any2xx. Clients outside opencloud-eu can't be checked. - Keep
200: remove theWriteHeadercalls that have no effect, so that the code matches the behaviour. Nothing changes for clients.
In both cases, HandleList should drop its WriteHeader calls after w.Write, since a status can't be changed once the body has been written. Both handlers should also set Content-Type: application/json before writing the body.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsPrio <= 3
Activity