Skip to content

test: add unit tests for _validate_lengths field length guard - #2437

Merged
utksh1 merged 2 commits into
utksh1:mainfrom
aaniya22:test/validate-lengths-2307
Aug 5, 2026
Merged

test: add unit tests for _validate_lengths field length guard#2437
utksh1 merged 2 commits into
utksh1:mainfrom
aaniya22:test/validate-lengths-2307

Conversation

@aaniya22

@aaniya22 aaniya22 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Description

Adds unit tests for the _validate_lengths helper in backend/secuscan/routes.py, which enforces maximum field lengths (255 chars for name, 2000 chars for description/notes) before data reaches the database. Covers valid/boundary/over-limit cases for name, description, and notes fields, plus custom resource_type substitution and None handling for optional fields.

Related Issues

Closes #2307

Type of Change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Ran python -m pytest testing/backend/unit/test_routes_validate_lengths.py -v locally — all 9 tests pass. Coverage includes:

  • Valid name/description/notes under their respective limits
  • Exact-boundary values (255 chars for name, 2000 for description/notes) — confirmed to pass
  • Over-limit values for name, description, and notes — confirmed to raise HTTPException with status 400 and the correct detail message
  • Custom resource_type correctly substituted into the error message
  • None values for all optional fields — confirmed to pass without raising

Checklist

  • My code follows the code style of this project.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.

@utksh1 utksh1 added area:backend Backend API, database, or service work level:beginner 20 pts difficulty label for small beginner-friendly PRs type:testing Testing work category bonus label labels Aug 4, 2026
Covers valid/boundary/over-limit cases for name, description, and
notes fields, plus custom resource_type substitution and None
handling for optional fields. Closes utksh1#2307.
@utksh1
utksh1 force-pushed the test/validate-lengths-2307 branch from 0f57159 to 9036a2b Compare August 4, 2026 10:03

@utksh1 utksh1 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code change is reviewed and the backend/lint checks are green. Merge remains blocked by the required frontend audit, which reports the pre-existing high-severity undici vulnerability; I am not bypassing that security gate.

@utksh1 utksh1 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the current head, including the undici lockfile security update. The focused validation tests pass, all required checks are green, and the branch is clean for squash merge.

@utksh1
utksh1 merged commit 5267f90 into utksh1:main Aug 5, 2026
33 checks passed
@utksh1 utksh1 added the gssoc:approved Admin validation: approved for GSSoC scoring label Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:backend Backend API, database, or service work gssoc:approved Admin validation: approved for GSSoC scoring level:beginner 20 pts difficulty label for small beginner-friendly PRs type:testing Testing work category bonus label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test : add unit tests for _validate_lengths field length guard

2 participants