Repository navigation
fix: validate lab ports in model and admin forms - #577
Open
Yeagerist0 wants to merge 2 commits into
Open
Yeagerist0 wants to merge 2 commits into
Yeagerist0 wants to merge 2 commits into
Conversation
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
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.
Summary
Add model-level TCP port bounds to
Lab.portso 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
IntegerFieldaccepts 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)andMaxValueValidator(65535)to the existing field and record them in migration0009. 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
challenge/models.pychallenge/migrations/0009_alter_lab_port.pychallenge/tests.pyType of Change
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:
python manage.py test --verbosity 1— 57 tests pass.python manage.py makemigrations --check --dry-run— no changes detected.git diff --checkpasses.AI assistance
OpenAI Codex assisted with implementation, regression tests and this description. Tests ran locally without live Docker containers.