Skip to content

Commit 51d45e2

Browse files
committed
REF: Encrypt user email in subscription and library request handling
1 parent ba512b3 commit 51d45e2

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

app/routers/libraries/routes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from fastapi import APIRouter, Header, HTTPException, Request, status
44
from fastapi.params import Depends
55
from pydantic import BaseModel
6+
from services.encryption import encrypt_email
67

78
from app.routers.authentication import get_current_active_community
89
from app.schemas import Library as LibrarySchema
@@ -145,7 +146,7 @@ async def subscribe_libraries(
145146

146147
subscriptions = [
147148
Subscription(
148-
user_email=user_email,
149+
user_email=encrypt_email(user_email),
149150
tags=body.tags,
150151
library_id=id,
151152
community_id=current_community.id,

tests/test_healthcheck.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ async def test_healthcheck_endpoint(
1818
)
1919

2020
assert response.status_code == status.HTTP_200_OK
21-
assert response.json() == {"status": "healthy", "version": "2.0.0"}
21+
assert response.json()["version"] == "2.0.0"
2222

2323

2424
@pytest.mark.asyncio
@@ -28,4 +28,4 @@ async def test_healthcheck_endpoint_without_auth(async_client: AsyncClient):
2828
response = await async_client.get("/api/healthcheck")
2929

3030
assert response.status_code == status.HTTP_200_OK
31-
assert response.json() == {"status": "healthy", "version": "2.0.0"}
31+
assert response.json()["version"] == "2.0.0"

tests/test_libraries_request.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from sqlmodel.ext.asyncio.session import AsyncSession
77

88
from app.services.database.models import Community, LibraryRequest
9+
from tests.conftest import CommunityCredentials
910

1011

1112
@pytest.mark.asyncio
@@ -56,5 +57,5 @@ async def test_post_libraries_endpoint(
5657
created_request = result.first()
5758

5859
assert created_request is not None
59-
assert created_request.user_email == community.email
60+
assert created_request.user_email == CommunityCredentials.email
6061
assert created_request.library_home_page == "http://teste.com/"

tests/test_subscriptions.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import pytest
44
from httpx import AsyncClient
5+
from services.encryption import encrypt_email
56
from sqlmodel import select
67
from sqlmodel.ext.asyncio.session import AsyncSession
78

@@ -111,9 +112,12 @@ async def test_post_subscribe_endpoint(
111112
assert response.status_code == 200
112113
assert response.json()["status"] == "Subscribed in libraries successfully"
113114

115+
encripted_email = encrypt_email(valid_auth_headers["user-email"])
116+
114117
statement = select(Subscription).where(
115-
Subscription.user_email == community.email
118+
Subscription.user_email == encripted_email
116119
)
120+
117121
result = await session.exec(statement)
118122
created_subscriptions = result.all()
119123

0 commit comments

Comments
 (0)