Skip to content

feat: add file size validation for resume uploads (closes #135)#150

Open
singhanurag0317-bit wants to merge 2 commits into
Team-NoxVeil:mainfrom
singhanurag0317-bit:feat/resume-validation-135
Open

feat: add file size validation for resume uploads (closes #135)#150
singhanurag0317-bit wants to merge 2 commits into
Team-NoxVeil:mainfrom
singhanurag0317-bit:feat/resume-validation-135

Conversation

@singhanurag0317-bit
Copy link
Copy Markdown

Description

This pull request resolves Issue #135 ("Add file size validation for resume uploads") by implementing a configurable upload size limit setting, validating the upload's size prior to loading its contents into memory, and returning descriptive HTTP 400 validation error responses to the client on limit violation.

Key Improvements

  1. Configurable Size Limits (MAX_UPLOAD_SIZE):

    • Added a new setting MAX_UPLOAD_SIZE: int = 5 * 1024 * 1024 (5 MB default) inside the Settings class in backend/app/config.py.
    • Allows configuration through the environment variable MAX_UPLOAD_SIZE.
  2. In-Memory Buffer Allocation Prevention:

    • Updated apply_for_interview inside backend/app/routers/application.py to check the file size before executing the resume.read() buffer read operation.
    • Built a robust async fallback using seek/tell to safely determine the file size if resume.size is not directly populated by Starlette/FastAPI.
    • Raises a descriptive BadRequestError (returning an HTTP 400 response) if the file size limit is exceeded.
  3. SQLite Database & Test Environment Corrections:

    • Fixed SQLite compatibility compilation error with Postgres JSONB in backend/app/models/dsa_question.py by introducing a dialect-agnostic JSON().with_variant(JSONB, "postgresql") column mapping.
    • Added the missing dsa_question model import inside the pytest setup hook create_tables in backend/tests/conftest.py to prevent NoReferencedTableError database setup failures.
  4. Integration Test Suite:

    • Created a comprehensive test suite backend/tests/test_routers/test_application.py targeting /applications/{interview_id} endpoints.
    • Fully validates:
      • Successful application creation with standard size upload.
      • Rejection of oversized resumes with HTTP 400 Bad Request and correct error details.
      • Successful upload of a file exactly at the configured size limit.
      • Rejection of organization accounts attempting to apply for interviews.
      • Rejection of duplicate applications for the same interview.

Verification

  • Verified that all unit tests in the new test suite compile and run perfectly.
  • Executed pytest inside the virtual environment:
    .venv\Scripts\pytest.exe tests\test_routers\test_application.py
    Result: 6 passed with zero errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant