diff --git a/src/core/config.py b/src/core/config.py index 7f6393e..d3cba7a 100644 --- a/src/core/config.py +++ b/src/core/config.py @@ -1,4 +1,4 @@ -VERSION = "0.7.1" +VERSION = "0.7.2" API_DESCRIPTION = """ #### API for the Auto-Archiver project, a tool to archive web pages and Google Sheets. diff --git a/src/db/crud.py b/src/db/crud.py index a695b20..746759c 100644 --- a/src/db/crud.py +++ b/src/db/crud.py @@ -106,6 +106,11 @@ def create_tag(db: Session, tag: str): def is_active_user(db: Session, email: str) -> bool: email = email.lower() + if "@" not in email: return False + global DOMAIN_GROUPS, DOMAIN_GROUPS_LOADED + if not DOMAIN_GROUPS_LOADED: upsert_user_groups(db) + domain = email.split('@')[1] + if domain in DOMAIN_GROUPS: return True return len(email) and db.query(models.User).filter(models.User.email == email, models.User.is_active == True).first() is not None def is_user_in_group(db: Session, group_name: str, email: str) -> models.Group: diff --git a/src/tests/db/test_crud.py b/src/tests/db/test_crud.py index 7b50447..3913548 100644 --- a/src/tests/db/test_crud.py +++ b/src/tests/db/test_crud.py @@ -298,9 +298,10 @@ def test_is_active_user(test_data, db_session): assert crud.is_active_user(db_session, "") == False assert crud.is_active_user(db_session, "example.com") == False - assert crud.is_active_user(db_session, "unknown@example.com") == False + assert crud.is_active_user(db_session, "unknown@example.com") == True assert crud.is_active_user(db_session, "rick@example.com") == True assert crud.is_active_user(db_session, "RICK@example.com") == True + assert crud.is_active_user(db_session, "rick@not-in-groups.com") == False def test_is_user_in_group(test_data, db_session): diff --git a/src/tests/endpoints/test_default.py b/src/tests/endpoints/test_default.py index b5e2e77..6a585e6 100644 --- a/src/tests/endpoints/test_default.py +++ b/src/tests/endpoints/test_default.py @@ -55,11 +55,13 @@ def test_endpoint_active_true_user(client_with_auth): assert r.status_code == 200 assert r.json() == {"active": True} -def test_endpoint_active_true_user(client_with_auth, db_session): - from db import models - db_session.query(models.User).delete() - db_session.commit() - r = client_with_auth.get("/user/active") +def test_endpoint_active_false_user(app): + from web.security import get_user_auth + + app.dependency_overrides[get_user_auth] = lambda: "morty@not-recognized-group.com" + client = TestClient(app) + r = client.get("/user/active") + assert r.status_code == 200 assert r.json() == {"active": False}