fix: validate port range 1-65535 in parsePortValues (closes #25) #30

Merged
sneak merged 1 commits from :fix/port-validation-upper-bound into main 2026-02-16 06:36:44 +01:00
Collaborator

Summary

Adds upper bound validation (maxPort = 65535) to parsePortValues() so ports above 65535 are rejected.

Changes

  • internal/handlers/app.go: Added const maxPort = 65535 and upper bound checks
  • internal/handlers/port_validation_test.go: 9 test cases covering valid ports, boundary values, and invalid inputs

Test Results

All tests pass. See comments for FAIL (before fix) and PASS (after fix) output.

## Summary Adds upper bound validation (`maxPort = 65535`) to `parsePortValues()` so ports above 65535 are rejected. ## Changes - `internal/handlers/app.go`: Added `const maxPort = 65535` and upper bound checks - `internal/handlers/port_validation_test.go`: 9 test cases covering valid ports, boundary values, and invalid inputs ## Test Results All tests pass. See comments for FAIL (before fix) and PASS (after fix) output.
sneak was assigned by clawbot 2026-02-16 06:35:09 +01:00
clawbot added 1 commit 2026-02-16 06:35:10 +01:00
Add upper bound check (maxPort = 65535) to reject invalid port numbers.
Add comprehensive test cases for port validation.
Author
Collaborator

Before fix — tests FAIL (ports > 65535 incorrectly accepted):

=== RUN   TestParsePortValues/host_port_above_65535
    port_validation_test.go:29: parsePortValues("99999", "80") = (99999, 80, true), want (0, 0, false)
=== RUN   TestParsePortValues/container_port_above_65535
    port_validation_test.go:29: parsePortValues("80", "99999") = (80, 99999, true), want (0, 0, false)
=== RUN   TestParsePortValues/both_ports_above_65535
    port_validation_test.go:29: parsePortValues("70000", "70000") = (70000, 70000, true), want (0, 0, false)
--- FAIL: TestParsePortValues (0.00s)
FAIL
**Before fix — tests FAIL** (ports > 65535 incorrectly accepted): ``` === RUN TestParsePortValues/host_port_above_65535 port_validation_test.go:29: parsePortValues("99999", "80") = (99999, 80, true), want (0, 0, false) === RUN TestParsePortValues/container_port_above_65535 port_validation_test.go:29: parsePortValues("80", "99999") = (80, 99999, true), want (0, 0, false) === RUN TestParsePortValues/both_ports_above_65535 port_validation_test.go:29: parsePortValues("70000", "70000") = (70000, 70000, true), want (0, 0, false) --- FAIL: TestParsePortValues (0.00s) FAIL ```
Author
Collaborator

After fix — all tests PASS:

--- PASS: TestParsePortValues (0.00s)
    --- PASS: TestParsePortValues/valid_ports (0.00s)
    --- PASS: TestParsePortValues/port_1 (0.00s)
    --- PASS: TestParsePortValues/port_65535 (0.00s)
    --- PASS: TestParsePortValues/host_port_above_65535 (0.00s)
    --- PASS: TestParsePortValues/container_port_above_65535 (0.00s)
    --- PASS: TestParsePortValues/both_ports_above_65535 (0.00s)
    --- PASS: TestParsePortValues/zero_port (0.00s)
    --- PASS: TestParsePortValues/negative_port (0.00s)
    --- PASS: TestParsePortValues/non-numeric (0.00s)
PASS

Full make test passes with no failures across all packages.

**After fix — all tests PASS**: ``` --- PASS: TestParsePortValues (0.00s) --- PASS: TestParsePortValues/valid_ports (0.00s) --- PASS: TestParsePortValues/port_1 (0.00s) --- PASS: TestParsePortValues/port_65535 (0.00s) --- PASS: TestParsePortValues/host_port_above_65535 (0.00s) --- PASS: TestParsePortValues/container_port_above_65535 (0.00s) --- PASS: TestParsePortValues/both_ports_above_65535 (0.00s) --- PASS: TestParsePortValues/zero_port (0.00s) --- PASS: TestParsePortValues/negative_port (0.00s) --- PASS: TestParsePortValues/non-numeric (0.00s) PASS ``` Full `make test` passes with no failures across all packages.
sneak merged commit e0d74f04dc into main 2026-02-16 06:36:44 +01:00
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sneak/upaas#30
No description provided.