fix: address multiple code quality improvements across backend and frontend

Backend fixes:
- Fix JWT sub claim: encode as str(user.id), decode with int() cast (python-jose requirement)
- Replace all deprecated datetime.utcnow() with datetime.now(timezone.utc)
- Replace deprecated FastAPI @app.on_event() with modern lifespan context manager
- Replace deprecated Pydantic class Config with model_config = ConfigDict(...)
- Replace deprecated Pydantic .dict() with .model_dump()
- Fix overly broad except (GmailInjectionError, Exception) → except Exception
- Remove unused GmailInjectionError import
- Fix TokenPayload schema sub field type from int to str

Frontend:
- Create frontend/src/lib/api.ts — API client module with auth, user, mail accounts, processing runs APIs
- Add !frontend/src/lib/ to .gitignore negation

Tests:
- Add 3 new JWT tests (sub string encoding, access token type, refresh token type)
- Update test_token_payload_schema for string sub claim
- All 128 tests pass

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
Agent-Logs-Url: https://github.com/christianlouis/pop_puller_to_gmail/sessions/e0b13eb0-8de7-4f02-81e4-e202cbba4608
This commit is contained in:
copilot-swe-agent[bot]
2026-03-23 13:09:23 +00:00
parent a513ef3c20
commit f439f887d0
15 changed files with 360 additions and 76 deletions
+32
View File
@@ -51,6 +51,38 @@ class TestJWT:
assert len(token) > 50
assert token.count(".") == 2 # JWT has 3 parts
def test_access_token_sub_claim_is_string(self):
"""Test that sub claim must be passed as a string (python-jose requirement)"""
from app.core.security import decode_token
# sub should be a string (e.g. str(user.id)), not an integer
token = create_access_token(data={"sub": "42"})
payload = decode_token(token)
assert payload is not None
assert payload["sub"] == "42"
assert isinstance(payload["sub"], str)
def test_access_token_contains_type_claim(self):
"""Test that access token includes type=access claim"""
from app.core.security import decode_token
token = create_access_token(data={"sub": "1"})
payload = decode_token(token)
assert payload is not None
assert payload["type"] == "access"
def test_refresh_token_contains_type_claim(self):
"""Test that refresh token includes type=refresh claim"""
from app.core.security import create_refresh_token, decode_token
token = create_refresh_token(data={"sub": "1"})
payload = decode_token(token)
assert payload is not None
assert payload["type"] == "refresh"
class TestEncryption:
"""Test credential encryption/decryption"""