fix: automated fixes for PR #24#35
Open
vikram-blaxel wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Automated fixes for PR #24.
23/23 tests pass. All changes are staged. Here is the structured summary:
Security Fixes
ISBN field propagation (Critical – Security/Code Quality/Test reports): Added
isbn: strtoBookInPydantic model with a@field_validatorenforcing ISBN-10/ISBN-13 format (^(?:\d{9}[\dX]|\d{13})$); addedisbn: strtoBookOut. This means invalid ISBNs are rejected at the API boundary with HTTP 422 rather than causing a databaseIntegrityError.Exception detail leakage (Critical – Security): Replaced
detail=str(e)in allexceptblocks inrouters.pywithdetail="An error occurred processing your request"and addedlogger.error(...)for server-side logging. Usedraise ... from eto preserve exception chaining for debugging. This prevents internal SQLAlchemy query text and schema details from leaking to clients.Unbounded
limitquery parameter (Warning – Security): Changedlimit: int = 10tolimit: int = Query(default=10, ge=1, le=100)andskip: int = 0toskip: int = Query(default=0, ge=0)inGET /books/. Requests withlimit > 100now return HTTP 422, preventing denial-of-service via huge result sets..envnot in.gitignore(Warning – Security): Added.envto.gitignoreto prevent accidental credential commits.Dockerfile: container runs as root (Warning – Security): Added
RUN adduser --disabled-password --gecos "" appuserandUSER appuserbeforeCMD.Dockerfile:
--log-level tracein production (Warning – Security): Changed--log-level traceto--log-level warningto prevent sensitive request/response data from leaking into logs.Docker Compose: PostgreSQL port exposed to host (Warning – Security): Removed the
ports: - "5432:5432"mapping from thedbservice; the database is now only reachable inside the Docker network.ISBN column size (Informational – Security/Code Quality): Changed
String(255)toString(13)for theisbncolumn — the tightest correct size for ISBN-13 (13 chars), enforcing length at the database layer.Code Quality Fixes
repositories.create_bookmissingisbn(Critical – Code Quality): Addedisbn=book.isbnto theBook(...)constructor call increate_book.repositories.update_bookmissingisbn(Critical – Code Quality): Addeddb_book.isbn = book.isbnin theupdate_bookfunction.Redundant
nullable=Falseremoved (Warning – Code Quality): Removed thenullable=Falsekwarg from theisbnmapped_column;Mapped[str]already implies NOT NULL in SQLAlchemy 2.x.raise ... from e(Warning – Code Quality): Bothexceptblocks inrouters.pynow useraise HTTPException(...) from e.from typing import Listreplaced (Informational – Code Quality): ReplacedList[models.BookOut]with the built-inlist[models.BookOut]and removed thetypingimport fromrouters.py.Unused imports removed (Informational – Code Quality): Removed
textfromconftest.py; removedcreate_engineandinspect-unused-in-old-sense fromtest_main.py(keptinspectwhich is used bytest_database_initialization).models.pyblank line (Informational – Code Quality): Added a blank line before the# Pydantic modelssection separator to comply with PEP 8.models.pyunnecessarypassinBase: Left as-is (pre-existing, not part of the PR diff, and removing it is style-only with no risk reduction).Test Additions
test_main.py–isbnadded to all fixtures: UpdatedTEST_BOOKSconstants with valid ISBN-13 values; updated allBookIn(...)calls in repository tests and inline usages.test_main.py–TestBookRepositorysplit and extended:test_get_nonexistent_book,test_update_nonexistent_book,test_delete_nonexistent_book— replaced the single combinedtest_nonexistent_operationswith three separate, named tests.test_get_books_pagination— new test verifyingskip/limitpagination at the repository layer.assert len(books) >= 2intest_get_books.isbnfield assertions intest_create_book,test_get_book,test_update_book.test_main.py–TestAPIRoutes(new class, 12 tests): Full HTTP-level coverage via theclientfixture for all 5 endpoints: create (happy path, missing isbn → 422, invalid isbn → 422), list (happy path, pagination limit, limit > max → 422), get (happy path, not found → 404), update (happy path, not found → 404), delete (happy path, not found → 404).conftest.py–test_appfixture improved: Changed to use a single shared connection with savepoint-based rollback (same pattern astest_db), fixing data-leakage between requests within the same test and ensuring data written through the HTTP client is visible within the same test.test_main.py::TestMainApp::test_create_appstrengthened: Added assertion thattest_app.routesis non-empty.Skipped Items
Authentication/Authorization (Critical – Security): Adding OAuth2/JWT or API-key authentication was not implemented. This requires introducing new application logic (token issuance, user management or key store) and non-trivial infrastructure changes that go well beyond the scope of propagating the
isbnfield fix. This should be addressed as a dedicated follow-up PR.Pinning dependency versions (Informational – Security): All
requirements.txtentries still use>=lower bounds. Generating a locked requirements file requires runningpip-compileorpoetry lockand validating against the full test suite; this is a separate operational task and no new dependencies were introduced.models.pyunnecessarypassinBase(Code Quality pylint W0107): Pre-existing style issue; removing it has zero functional impact and was not part of the PR diff.