diff options
| author | Frederick Muriuki Muriithi <fredmanglis@gmail.com> | 2026-10-07 11:46:10 -0500 |
|---|---|---|
| committer | Frederick Muriuki Muriithi <fredmanglis@gmail.com> | 2026-10-07 11:46:10 -0500 |
| commit | 0f75d18e38d06a8ed7bd2ab2dea3dbf3bcbc74da (patch) | |
| tree | 3f6deaf9754b66a03e492db22fabd6c0eaa4855a | |
| parent | af3fdc556297392e9a61065abb25682deef5b738 (diff) | |
| download | gn-auth-0f75d18e38d06a8ed7bd2ab2dea3dbf3bcbc74da.tar.gz | |
Reactivate tests and add warnings
Reactivate tests to ensure they are not skipped any longer. Add warnings for the parts of the tests that have not been handled to completion.
| -rw-r--r-- | tests/unit/auth/test_token.py | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/tests/unit/auth/test_token.py b/tests/unit/auth/test_token.py index 60d19ad..865638f 100644 --- a/tests/unit/auth/test_token.py +++ b/tests/unit/auth/test_token.py @@ -1,4 +1,5 @@ """Test the OAuth2 authorisation""" +import warnings import pytest @@ -7,8 +8,8 @@ from gn_auth.auth.db import sqlite3 as db SUCCESS_RESULT = { "status_code": 200, "result": { - "access_token": "123456ABCDE", - "expires_in": 864000, + # "access_token": "123456ABCDE", # T0DO: Generate valid JWT for these: + # "expires_in": 864000, # T0DO: Check this in the JWT access_token itself "scope": "profile", "token_type": "Bearer"}} @@ -23,10 +24,6 @@ def gen_token(client, grant_type, user, scope): # pylint: disable=[unused-argume return "123456ABCDE" -@pytest.mark.skip( - "Use of JWTs means the password grant is broken. We should probably drop " - "support for the password grant in the code, since it is actually a " - "deprecated type of grant anyway.") @pytest.mark.unit_test @pytest.mark.parametrize( "test_data,expected", @@ -39,7 +36,7 @@ def gen_token(client, grant_type, user, scope): # pylint: disable=[unused-argume (("papa", "yada", 2), USERNAME_PASSWORD_FAIL_RESULT), # (("unaff@iliated.user", "password_for_user_004", 1), USERNAME_PASSWORD_FAIL_RESULT) )) -def test_token(fxtr_app, fxtr_oauth2_clients, test_data, expected): +def test_token(client, fxtr_oauth2_clients, test_data, expected): """ GIVEN: a registered oauth2 client, a user WHEN: a token is requested via the 'password' grant @@ -52,16 +49,23 @@ def test_token(fxtr_app, fxtr_oauth2_clients, test_data, expected): conn, oa2clients = fxtr_oauth2_clients email, password, client_idx = test_data data = { - "grant_type": "password", "scope": "profile nonexistent-scope", + "grant_type": "password", "scope": "profile", "client_id": oa2clients[client_idx].client_id, "client_secret": oa2clients[client_idx].client_secret, "username": email, "password": password} - with fxtr_app.test_client() as client, db.cursor(conn) as cursor: + with db.cursor(conn) as cursor: res = client.post("/auth/token", data=data) # cleanup db cursor.execute("DELETE FROM oauth2_tokens WHERE access_token=?", (gen_token(None, None, None, None),)) + + warnings.warn( + "The `test_token.py` tests are incomplete:\nTODO:\n" + "\t- [ ] mock the token generation function(s).\n" + "\t- [ ] Check 'access_token' value.\n" + "\t- [ ] Check 'expires_in' value inside the 'access_token' value.", + RuntimeWarning) assert res.status_code == expected["status_code"] for key in expected["result"]: assert res.json[key] == expected["result"][key] |
