From 74c431ca4f6e015fd53f2e270e3cc89546caca56 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 8 Nov 2022 09:48:03 +0300 Subject: Tests: Tests the credentials check system * gn3/auth/authentication.py: Fix issues caught by tests * tests/unit/auth/test_credentials.py: Add fixtures and tests for credentials checking --- gn3/auth/authentication.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'gn3/auth') diff --git a/gn3/auth/authentication.py b/gn3/auth/authentication.py index 781380e..42ceacb 100644 --- a/gn3/auth/authentication.py +++ b/gn3/auth/authentication.py @@ -11,11 +11,14 @@ def credentials_in_database(cursor, email: str, password: str) -> bool: ("SELECT " "users.email, user_credentials.password " "FROM users LEFT JOIN user_credentials " - "ON users.email = :email"), + "ON users.user_id = user_credentials.user_id " + "WHERE users.email = :email"), {"email": email}) results = cursor.fetchall() if len(results) == 0: return False - assert len(results) > 1, "Expected one row." - return (email == row[0] and bcrypt.checkpw(value.encode("utf-8"), row[1])) + assert len(results) == 1, "Expected one row." + row = results[0] + return (email == row[0] and + bcrypt.checkpw(password.encode("utf-8"), row[1])) -- cgit v1.2.3