#5422 Add verify_token API endpoint
Closed by mattia. Opened by mattia.
Unknown source master

Download 5422.patch

Add a simple endpoint which verify token validity for the specified project. Return 200 if token is valid or 401 if expired/invalid. See #5420

Signed-off-by: Mattia Verga mattia.verga@tiscali.it

It's missing an entry to show in the API docs :)

@mattia, if you need an example of how to do this, you can see how new API endpoints are added with this commit: https://pagure.io/pagure/c/1b7d305d06af42f0996ae54fea223ecc5a081b72

rebased onto aab6e4f6b17d28e1581d43bd94c9a264c2018013

rebased onto b6b1b72502c8df91d5b8ec035987b24fa9ab799f

There are some failed tests, can you take a look at them?

05:17:53  FAILED tests/test_pagure_flask_api_project.py::PagureFlaskApiProjectVerifyAPITokenTests::test_api_verifyapitoken_no_headers
05:17:53  FAILED tests/test_pagure_flask_api_project.py::PagureFlaskApiProjectVerifyAPITokenTests::test_api_verifyapitoken_not_valid
05:17:53  FAILED tests/test_pagure_flask_api_project.py::PagureFlaskApiProjectVerifyAPITokenTests::test_api_verifyapitoken_valid
05:17:53  FAILED tests/test_style.py::TestStyle::test_code_with_black - AssertionError:...

rebased onto 0028f651ec8d3e88bb991fff89db50db077c74cc

Still three failures:

03:49:19  FAILED tests/test_pagure_flask_api_project.py::PagureFlaskApiProjectVerifyAPITokenTests::test_api_verifyapitoken_no_headers
03:49:19  FAILED tests/test_pagure_flask_api_project.py::PagureFlaskApiProjectVerifyAPITokenTests::test_api_verifyapitoken_not_valid
03:49:19  FAILED tests/test_pagure_flask_api_project.py::PagureFlaskApiProjectVerifyAPITokenTests::test_api_verifyapitoken_valid

rebased onto 9d833f3ab05e4334fb85deecd6727b86f66529cf

rebased onto 5045627fc36251f2eab42e1346f6321180390df1

This currently can only verify tokens with modify_project ACL. Ideally, this should work with any ACL, but I have to figure out how to do so without listing all ACLs in the api_login_required decorator...

I've changed the logic in _check_token() and now there are several tests failing... is it really correct the current logic in _check_token? It only raises an error within the if api_authenticated() block, but if api_authenticated() is False there's no token that could be validated, so shouldn't it raise an error as well?

rebased onto ed5d68700f58d2cd5f0ae10b8cc2cbcde9261b43

I think you're probably right here. We want this to fail when the user isn't authenticated/authorized to access the API.

I think you're probably right here. We want this to fail when the user isn't authenticated/authorized to access the API.

So, I'll try to firstly look at changing _check_token() behavior and analyze tests failures and try to fix them. Then I'll rebase this PR on top of that.

That sounds like a good plan of action!

Well, after some digging in Pagure code, I think I'm going to retire this PR. I'm really confused on how this all work and can't figure it out.
Also, as I understand it, check_token() checks a token is valid for a project if the token is project specific, while the token is system wide only checks if the call of check_token() must be for a project specific or not (so it doesn't really check token validity).

Pull-Request has been closed by mattia

Metadata