Fix API endpoint: Return 401 when the token is missing#133
Fix API endpoint: Return 401 when the token is missing#133josecelano wants to merge 1 commit intodevelopfrom
Conversation
|
The "test" check is failing because there are some clipply warnings/errors that have been fixed in other pending-to-merge PRs. I'm not going to fix them. I will probably merge those PRs tomorrow and rebase this PR before fixing the newly detected ones. I have also added one test, "should_return_an_internal_error_server_when_the_token_is_invalid" that has to be changed. In the current behaviour, the API returns a 500 when the token is invalid, and I think it should return a 401. |
|
Today @WarmBeer @da2ce7 and I agreed on the following tasks. Each task could be an independent PR: Add tests
Reimplement the current API using Axum
New API (same endpoints, different response codes)We start building a new API using the
NOTES:
Long-term APIIn the future, we want to:
|
|
This PR has been reorganized. The new issue is #141 |
The API returned a 500 code when the token was missing. I've changed it, and now it returns a 401 code. The change affects all endpoints.
I think we could make other changes:
struct Unauthorized.routes.rs.authenticatefunction should also return a 401 response instead oftoken not validwhen the token is present but not valid.GET /api/torrent/:info_hashendpoint should return a 404 when the torrent does not exist and the token is valid.GET /api/torrent/:info_hashshould return a 404 when the torrent does not exist and the token is invalid. See Insecure Direct Object References (IDOR)). We should not expose that the tracker has a given torrent because the tracker could be private.DELETE /api/whitelist/:info_hashendpoint should return: a "204 No Content" when it deletes the torrent and a "404 Not Found" when the torrent does not exist or the token is invalid.POST /api/whitelist/:info_hashendpoint should return a "201 Created" response with the location of the new resourceGET /api/whitelist/:info_hash. In this case we would need to create that new endpoint. It could be empty. It could be used only to know if a torrent is whitelisted. Alternatively, we could consider the whitelist a unique resource and use aPUT /api/whitelist/:info_hashto add a new torrent to the list.POST /api/key/:seconds_validendpoint should return a "201 Created".DELETE /api/key/:keyshould should return "204 No Content".GET /api/whitelist/reloadendpoint should be aPOST,PUTorPATCH. This endpoint is a little weird, it's like a remote command. I think I should have usePOST /api/commandswith the command you want to execute in the request body orPOST /api/reload-whitelist.GET /api/keys/reload@WarmBeer @da2ce7 do you think those changes make sense? If you do, should I make them now or postpone them?