diff options
author | Frederick Muriuki Muriithi | 2022-12-19 16:02:19 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2022-12-22 09:05:53 +0300 |
commit | b0641272491eb51d321b1b8a7d062e395e70800f (patch) | |
tree | c9b2065ea60399579c4c4d84c648b61ed67402ba /tests/unit/auth/fixtures/user_fixtures.py | |
parent | e9031e28594fcd21371adb2b9b26e17a1df95599 (diff) | |
download | genenetwork3-b0641272491eb51d321b1b8a7d062e395e70800f.tar.gz |
auth: implement OAuth2 flow.oauth2_auth_flow
Add code to implement the OAuth2 flow.
* Add test fixtures for setting up users and OAuth2 clients
* Add tests for token generation with the "Password Grant" flow
* Fix some issues with test due to changes in the database connection's
row_factory
Diffstat (limited to 'tests/unit/auth/fixtures/user_fixtures.py')
-rw-r--r-- | tests/unit/auth/fixtures/user_fixtures.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/unit/auth/fixtures/user_fixtures.py b/tests/unit/auth/fixtures/user_fixtures.py index cc43a74..843d575 100644 --- a/tests/unit/auth/fixtures/user_fixtures.py +++ b/tests/unit/auth/fixtures/user_fixtures.py @@ -2,6 +2,7 @@ import uuid import pytest +import bcrypt from gn3.auth import db from gn3.auth.authentication.users import User @@ -41,3 +42,25 @@ def test_users(conn_after_auth_migrations):# pylint: disable=[redefined-outer-na ("21351b66-8aad-475b-84ac-53ce528451e3",), ("ae9c6245-0966-41a5-9a5e-20885a96bea7",), ("9a0c7ce5-2f40-4e78-979e-bf3527a59579",))) + +@pytest.fixture(scope="function") +def fixture_users_with_passwords(test_users): # pylint: disable=[redefined-outer-name] + """Fixture: add passwords to the users""" + conn, users = test_users + user_passwords_params = tuple( + (str(user.user_id), bcrypt.hashpw( + f"password_for_user_{idx:03}".encode("utf8"), + bcrypt.gensalt())) + for idx, user in enumerate(users, start=1)) + + with db.cursor(conn) as cursor: + cursor.executemany( + "INSERT INTO user_credentials VALUES (?, ?)", + user_passwords_params) + + yield conn, users + + with db.cursor(conn) as cursor: + cursor.executemany( + "DELETE FROM user_credentials WHERE user_id=?", + ((item[0],) for item in user_passwords_params)) |