Skip to content

Fix(invoice): reject trailing spaces and invalid status values in update_invoice_status#257

Open
Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Jean-Regis-M:patch-19
Open

Fix(invoice): reject trailing spaces and invalid status values in update_invoice_status#257
Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Jean-Regis-M:patch-19

Conversation

@Jean-Regis-M
Copy link

Summary

Fixes #179update_invoice_status now rejects status strings with trailing spaces (or any value not in the allowed set).

Problem

The function update_invoice_status accepts any string as the status argument and stores it directly in the database. This allows inputs like "approved " (with a trailing space) to be persisted, which then break all exact‑match comparisons (e.g., status == "approved"). The issue was discovered by test test_inv_upd_011.

Root Cause

No validation of the status argument against the domain‑allowed statuses. The code directly passed the user‑supplied string to the repository update call.

Solution

  1. Added a module‑level constant VALID_INVOICE_STATUSES containing the exact allowed status strings.
  2. Inserted a membership check before the repository update; if the status is not in the set, a ValueError is raised with a descriptive message.

Code Changes

File: finbot/tools/data/invoice.py

1. Define valid statuses (inserted after logger definition):

# Valid invoice statuses – must exactly match one of these values
VALID_INVOICE_STATUSES = {"submitted", "processing", "approved", "rejected", "paid"}

…es in update_invoice_status status

Root cause:
No validation was performed on the status argument, allowing strings
like "approved " to be stored in the database. This bypasses exact-match
checks downstream (e.g., status == "approved").

Solution:
- Define VALID_INVOICE_STATUSES set with the allowed values.
- Before updating, check if status is in that set and raise ValueError
  if not, with a clear error message.

Impact:
- Only invalid status values are rejected; valid calls unchanged.
- Prevents silent data corruption and ensures downstream logic works.
- Minimal, isolated change – easy to review and merge.

Signed-off-by: JEAN REGIS <240509606@firat.edu.tr>
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.

Bug_068_EVALUATE: Test Case INV-UPD-011 — update_invoice_status accepts trailing-space status strings

1 participant