stable

Clone or download

Read-only

feat: Respond status code 403 instead of 401 when unauthorized

Part of story #26799 associate a Tuleap project and a GitLab group How to test: if you call either POST or PATCH gitlab_groups, - with a non-existing project ID, you will get a 404 error - with a user that is not git administrator, you will get a 403 error (insteand of 401) No other functional change expected. Notes: 401 error is named "Unauthorized" but would more accurately be named "Unauthenticated" [0]. It really means "Who are you ? I don't know you". Some clients (like our API explorer) will show a login prompt when they get a 401 error code. In our code, we would respond 401 when a user is not Git Administrator, but it is incorrect: they are already logged in, entering their credentials again isn't going to grant them more permissions. In Tuleap terms, code 401 should only be used when a user is anonymous and calls a route that requires logging in. Code 403 is more precise, it means "You don't have permission" [1]. I also took this opportunity to use Faults to represent these "problems". We should try to avoid binding too much our code to Restler's RestExceptions. I know it is not hexagonal architecture, but nonetheless I feel like we are too much coupled to REST in what should be "sort-of domain" code. [0]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/401 [1]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403 Change-Id: I6b10b2d9cbc5cb6017a47d9056f2c0645f987791

Modified Files

Name
A plugins/git/include/Git/Permissions/VerifyUserIsGitAdministrator.php +26 −0 Go to diff View file
M plugins/git/include/GitPermissionsManager.class.php +3 −2 Go to diff View file
A plugins/git/tests/unit/Stub/VerifyUserIsGitAdministratorStub.php +45 −0 Go to diff View file
A plugins/gitlab/include/Core/ProjectNotFoundFault.php +36 −0 Go to diff View file
A plugins/gitlab/include/Core/ProjectRetriever.php +49 −0 Go to diff View file
A plugins/gitlab/include/Permission/GitAdministratorChecker.php +47 −0 Go to diff View file
A plugins/gitlab/include/Permission/UserIsNotGitAdministratorFault.php +36 −0 Go to diff View file
A plugins/gitlab/include/REST/v1/FaultMapper.php +45 −0 Go to diff View file
M plugins/gitlab/include/REST/v1/GitlabGroupResource.php +96 −90 Go to diff View file
A plugins/gitlab/tests/unit/Core/ProjectRetrieverTest.php +64 −0 Go to diff View file
A plugins/gitlab/tests/unit/Permission/GitAdministratorCheckerTest.php +64 −0 Go to diff View file
A plugins/gitlab/tests/unit/REST/v1/FaultMapperTest.php +48 −0 Go to diff View file
M tests/lib/Stubs/ProjectByIDFactoryStub.php +8 −2 Go to diff View file