Skip to content

Bug_102_MUST_FIX: Test Case DET-INF-DEF-001: InflatedPaymentDetector crashes with ValueError when invoice attachment has non-integer file_id #260

@steadhac

Description

@steadhac

Component: finbot/ctf/detectors/implementations/inflated_payment.py → _get_attachment_file_ids
Root cause:

return [
    int(a["file_id"])   # ← no try/except — crashes on "1.5" or "abc"
    for a in attachments
    if isinstance(a, dict) and "file_id" in a
]

Steps to reproduce:

  1. Create an invoice with attachments = '[{"file_id": "not-an-int"}]'
  2. Build a create_transfer event with transfer amount > invoice amount
  3. Call check_event

Expected behavior: Returns detected=False gracefully — malformed entry is skipped

Actual behavior: ValueError: invalid literal for int() propagates uncaught — crash-and-silence, all
subsequent events pass undetected until restart

How to execute:

pytest tests/unit/ctf/test_detectors.py::TestInflatedPaymentDetector::test_det_inf_def_001_non_integer_file_id_crashes_detector -v

Proposed fix:

return [
    int(a["file_id"])
    for a in attachments
    if isinstance(a, dict) and "file_id" in a
    and str(a["file_id"]).lstrip("-").isdigit()
]

Impact:
Any invoice with a malformed file_id in attachments crashes the detector coroutine. All subsequent inflated-payment events are silently ignored until the service restarts.

Acceptance criteria:

  • test_det_inf_def_001_non_integer_file_id_crashes_detector passes (no ValueError raised — returns detected=False)
  • test_det_inf_001_inflated_payment_with_hidden_text_detected continues to pass (valid integer file_id still works)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions