Skip to content

fix: validate lab ports in model and admin forms - #577

Open
Yeagerist0 wants to merge 2 commits into
adeyosemanputra:masterfrom
Yeagerist0:fix/lab-model-port-bounds
Open

Yeagerist0 wants to merge 2 commits into
adeyosemanputra:masterfrom
Yeagerist0:fix/lab-model-port-bounds

Conversation

@Yeagerist0

Copy link
Copy Markdown
Contributor

Summary

Add model-level TCP port bounds to Lab.port so Django admin and generated model forms reject ports outside 1–65535.

Problem / Motivation

Follow-up to the review of #574. The custom endpoints have a pending input-validation fix, but the admin uses the model field directly. The plain IntegerField accepts negative ports, zero and values above 65535 through model/form validation, allowing lab definitions that cannot be started with a valid Docker port.

Solution / Approach

Add MinValueValidator(1) and MaxValueValidator(65535) to the existing field and record them in migration 0009. Cover the model and generated ModelForm, plus valid boundary values. This complements #574 without depending on it. Existing data is not rewritten; direct ORM writes must still request validation explicitly, as with other Django field validators.

Files Changed

File Change
challenge/models.py Bound the lab port field
challenge/migrations/0009_alter_lab_port.py Record the validators
challenge/tests.py Cover invalid ports, boundaries and ModelForm errors

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

Impact

Admin/model validation rejects unusable port values. Existing valid port values, the database column type and the lab start flow are unchanged.

Validation

Python 3.11.15 with repository-pinned dependencies:

  • Before the fix: three invalid-value subcases and the ModelForm test fail; valid boundaries pass.
  • After the fix: python manage.py test --verbosity 1 — 57 tests pass.
  • python manage.py makemigrations --check --dry-run — no changes detected.
  • git diff --check passes.

AI assistance

OpenAI Codex assisted with implementation, regression tests and this description. Tests ran locally without live Docker containers.

Signed-off-by: Yeagerist0 <180412661+Yeagerist0@users.noreply.github.com>
Signed-off-by: Yeagerist0 <180412661+Yeagerist0@users.noreply.github.com>

This branch has not been deployed

No deployments
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