Skip to content

Reject out-of-range port and apiPort from config file - #2157

Merged
waldekmastykarz merged 11 commits into
dotnet:mainfrom
waldekmastykarz:psychic-fiesta
Dec 4, 2026
Merged

waldekmastykarz merged 11 commits into
dotnet:mainfrom
waldekmastykarz:psychic-fiesta

Conversation

@waldekmastykarz

Copy link
Copy Markdown
Collaborator

Closes #2140

An out-of-range port or apiPort in the config file (e.g. -1 or 70000) crashed Dev Proxy with an unhandled ArgumentOutOfRangeException from Kestrel. CLI values are already validated (#2135); config values weren't.

Changes

  • Program.cs: skip Listen for an out-of-range API port so building the app doesn't throw.
  • DevProxyCommand: validate the effective port and apiPort before the port-conflict check and log a clear error, e.g.:
    '70000' is not a valid value for 'apiPort' in the configuration file. Specify a number between 0 and 65535.
  • Port 0 stays valid (OS-assigned).
  • Tests for the validation helper.

Exit code

The issue left this open. This returns 1, treating it as a configuration error consistent with other config errors (no plugins, no URLs to watch, invalid apiIpAddress), rather than 2, which is reserved for CLI parse/validation errors. Happy to switch to 2 if preferred.

Verification

Ran each repro from the issue: all four now exit 1 with the message above and no stack trace. port: 0 / apiPort: 0 still start normally. DevProxy.Tests passes (186).

…2140

An out-of-range port or apiPort in the config file crashed Dev Proxy
with an unhandled ArgumentOutOfRangeException from Kestrel. Validate
both values at startup and report a clear error naming the setting and
the valid range (0-65535) with exit code 1, like other config errors.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@waldekmastykarz
waldekmastykarz requested a review from a team as a code owner November 22, 2026 09:49
Copilot AI balanced review requested due to automatic review settings November 22, 2026 09:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the configuration-port validation change.

No open issues 🎉

What changed in this PR

Addresses #2140 by rejecting out-of-range configuration ports with a clear error and exit code 1, rather than allowing an unhandled Kestrel exception.

Changes:

  • Guard API listener configuration against invalid port values.
  • Validate effective port and apiPort values before checking port conflicts, while preserving support for port 0.
  • Add validation-helper tests for invalid values and valid boundaries.
File Description
DevProxy/​Program.cs Skip API listener configuration when the port is out of range.
DevProxy/​Commands/​DevProxyCommand.cs Validate configured ports and report actionable errors.
DevProxy.Tests/​DevProxyCommandTests.cs Test error messages and valid port boundaries.

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 25, 2026 14:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

There are no active review issues for the change that rejects out-of-range configuration-file ports with clear errors.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 26, 2026 06:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues block the configuration-port validation change.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 26, 2026 13:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the configuration-port validation change.

No open issues 🎉

Review effort: Balanced

@garrytrinder garrytrinder left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Functional test results

  • PR: #2157
  • Tested commit: 2cfa8c346320962f8e1d02a09c5cd6d51b2ce5db
  • Environment: macOS, .NET SDK 10.0.103, source Debug build, loopback listeners, detached processes, isolated .devproxy/test-pr-2157-d6a52de8 fixtures, deterministic HTTP mock, system proxy disabled.

Every runtime launch used:

dotnet run --no-build --project DevProxy -- \
  --detach --as-system-proxy false --port 0 --api-port 0 \
  --config-file <fixture.json> --output json

Fixtures used MockResponsePlugin, watched http://pr2157.example/*, and mocked GET http://pr2157.example/test with status 200 and body {"source":"pr2157","ok":true}. Schemas were disabled for isolated testing. Each successful start was checked with PID-scoped status, an authenticated GET /proxy, and curl --noproxy "" --proxy <assigned-proxy-url> http://pr2157.example/test.

Scenario or test command Expected Actual Result
dotnet restore DevProxy.sln --locked-mode --verbosity quiet Dependencies restored without changing lock files Succeeded; source checkout remained clean PASS
dotnet build DevProxy.sln --no-restore --verbosity quiet Source and plugin assemblies build Succeeded with 0 warnings and 0 errors PASS
Current-head automated checks, inspected on GitHub rather than rerun locally Build, tests and smoke checks succeed for tested SHA Build, smoke, and macOS/Linux/Windows test checks all succeeded on the tested SHA PASS
Config port: 0, apiPort: 0, mandatory launch flags above OS assigns usable ports; API and explicitly proxied mock request work PID 33776; proxy 63997, API 63934; both HTTP 200; exact mock body matched PASS
Config port: -1, apiPort: 0, overridden by mandatory CLI zero ports Effective CLI ports win and remain usable PID 35758; proxy 64184, API 64185; API and mock HTTP 200; exact body matched PASS
Config port: 70000, apiPort: 0, overridden by mandatory CLI zero ports Effective CLI ports win and remain usable PID 37078; proxy 50013, API 50014; API and mock HTTP 200; exact body matched PASS
Config port: 0, apiPort: -1, overridden by mandatory CLI zero ports Effective CLI ports win and remain usable PID 37558; proxy 50167, API 50168; API and mock HTTP 200; exact body matched PASS
Config port: 0, apiPort: 70000, overridden by mandatory CLI zero ports Effective CLI ports win and remain usable PID 37997; proxy 50298, API 50299; API and mock HTTP 200; exact body matched PASS
Issue #2140: effective config port: -1 / 70000 without overriding that setting Exit 1; error names port and range 0–65535; no stack trace Not exercised: this testing workflow requires --port 0 on every launch, which overrides the invalid config value BLOCKED
Issue #2140: effective config apiPort: -1 / 70000 without overriding that setting Exit 1; error names apiPort and range 0–65535; no stack trace Not exercised: this testing workflow requires --api-port 0 on every launch, which overrides the invalid config value BLOCKED
Config upper valid boundary 65535 and first invalid upper boundary 65536, without CLI overrides Accept 65535 when available; reject 65536 cleanly Not exercised: mandatory CLI zero ports mask the configured boundaries BLOCKED
PID-scoped shutdown and fixture cleanup Stop only owned instances; preserve other concurrent tests and source All five owned PIDs exited after stop --pid; fixtures and captured successful-instance logs removed; source checkout clean PASS

Initial preparation needed a locked restore because assets were absent, and a solution build because building only the executable did not produce the dynamically loaded plugin assembly. The runtime matrix above was rerun successfully after that setup correction; the missing-plugin startup errors are not attributed to this PR.

Requested changes

None. No reproducible functional defect attributable to this PR was established.

Outcome

Comment only. Zero-port operation and CLI precedence passed, but these do not verify the central invalid-config rejection behavior: mandatory random-port CLI flags mask that behavior. This is a testing-workflow limitation, not a finding against the implementation. No approval or change request is justified by this incomplete functional evidence. Current-head CI is green. All owned running instances were stopped; no code was changed. Functional testing does not replace code review.

Copilot AI balanced review requested due to automatic review settings November 26, 2026 15:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the configuration-port validation changes.

No open issues 🎉

Review effort: Balanced

Killed child processes (e.g. cmd.exe /c more in the stdio test) release
handles on their working directory asynchronously on Windows, so the
immediate recursive delete intermittently failed with IOException.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 26, 2026 15:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

There are no active review issues blocking the port-validation change.

No open issues 🎉

Review effort: Balanced

@garrytrinder garrytrinder left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Functional test results

  • PR: #2157
  • Tested commit: 858433de40cd5c184591a4226973427856de0bc9
  • Environment: macOS, .NET SDK 10.0.103, source Debug build. Rerun supersedes the earlier revision's report.

Runtime fixtures used MockResponsePlugin and a deterministic GET http://pr2157.example/test returning HTTP 200 with {"source":"pr2157","ok":true}. Every launch used:

dotnet run --no-build --no-launch-profile --project DevProxy -- \
  --detach --as-system-proxy false --port 0 --api-port 0 \
  --config-file <fixture.json> --output json

HOME and CFFIXED_USER_HOME both pointed to a private fixture home with Library/Application Support pre-created. DEV_PROXY_CERT_PATH pointed to a private root certificate; installCert: false and noFirstRun: true prevented trust-store changes. State/log paths were asserted to be under the owned fixture directory. Schema validation was disabled and both listeners bound to loopback. Authentication tokens were kept out of this report.

For each runtime row below, startup had to report a live owned PID and two distinct assigned ports within 1–65535; authenticated GET /proxy had to return 200; status --pid <owned-pid> --output json had to identify that PID; and curl --noproxy "" --proxy <assigned-proxy-url> http://pr2157.example/test had to return HTTP 200 with the exact mock body.

Scenario or test command Expected Actual Result
dotnet build DevProxy.sln --no-restore --verbosity quiet Build source and plugin assemblies Succeeded, 0 warnings, 0 errors PASS
Current-head CI, inspected rather than rerun locally Required automated validation succeeds on tested SHA Build, client smoke, CodeQL, and macOS/Linux/Windows test checks all succeeded PASS
Updated process-smoke cleanup on Windows Windows integration suite completes successfully Windows job succeeded, including Test DevProxy.Integration.Tests; native Windows handle-release behavior was not reproduced locally on macOS PASS (CI)
Config port: 0, apiPort: 0 Assigned ports, API and mock work PID 8404; proxy/API 58412/58414; all runtime assertions passed PASS
Config port: -1, apiPort: 0, CLI overrides above Effective CLI zero ports win PID 9103; proxy/API 58599/58600; all runtime assertions passed PASS
Config port: 70000, apiPort: 0, CLI overrides above Effective CLI zero ports win PID 9497; proxy/API 58760/58761; all runtime assertions passed PASS
Config port: 0, apiPort: -1, CLI overrides above Effective CLI zero ports win PID 9834; proxy/API 58907/58908; all runtime assertions passed PASS
Config port: 0, apiPort: 70000, CLI overrides above Effective CLI zero ports win PID 10279; proxy/API 59262/59263; all runtime assertions passed PASS
Config port: 65536, apiPort: 0, CLI overrides above Effective CLI zero ports win PID 11004; proxy/API 50933/50926; all runtime assertions passed PASS
Config port: 0, apiPort: 65536, CLI overrides above Effective CLI zero ports win PID 11385; proxy/API 55055/55057; all runtime assertions passed PASS
Config port: 65535, apiPort: 0, CLI overrides above Effective CLI zero ports win PID 11830; proxy/API 55397/55398; all runtime assertions passed PASS
Config port: 0, apiPort: 65535, CLI overrides above Effective CLI zero ports win PID 12361; proxy/API 55675/55676; all runtime assertions passed PASS
Config port: -1, apiPort: 70000, CLI overrides above Both CLI zero ports win PID 12570; proxy/API 55848/55849; all runtime assertions passed PASS
Issue #2140: effective config port / apiPort of -1 or 70000, and first invalid upper boundary 65536 Exit 1; actionable message names setting and range 0–65535; no stack trace Not exercised: mandatory --port 0 --api-port 0 overrides these config values. Override cases above do not establish rejection behavior BLOCKED
Effective config port upper valid boundary 65535 without CLI override Accept and bind when available Not exercised: mandatory CLI zero ports mask the configured boundary BLOCKED
Owned process, fixture and certificate cleanup Stop only owned PIDs and remove private files All ten PIDs exited after matching-build stop --pid; private home, certificates, state/logs and fixtures removed; no tracked source changes PASS

Requested changes

None. No reproducible functional defect attributable to this PR was established.

Outcome

Comment only. Ten runtime startup/CLI-precedence scenarios passed on the current upstream head, and exact-head automated checks are green, including the updated Windows integration suite. The central invalid-config rejection reproduction remains unverified locally because mandatory safe startup flags mask it. This testing limitation does not justify a change request, and the incomplete functional evidence does not justify an approval. No fixes, commits or merges were made. All owned processes and private runtime artifacts were cleaned up. Functional testing does not replace code review.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 27, 2026 08:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the configuration-port validation change.

No open issues 🎉

Review effort: Balanced

@garrytrinder garrytrinder left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Functional test results

  • PR: #2157
  • Tested commit: 00c86c13c0cd6a2faf5878eb72ab9f807290002f
  • Environment: macOS, .NET SDK 10.0.103, source Debug build; November 27 retest supersedes previous-head reports.

Every runtime launch used dotnet run --no-build --no-launch-profile --project DevProxy -- --detach --as-system-proxy false --port 0 --api-port 0 --config-file <fixture.json> --output json. Fixtures configured loopback addresses, MockResponsePlugin, urlsToWatch: ["http://pr2157.example/*"], and a mock GET http://pr2157.example/test returning HTTP 200 with {"source":"pr2157","ok":true}. Schema validation and certificate trust installation were disabled.

Private HOME and CFFIXED_USER_HOME (with Library/Application Support pre-created) and a unique DEV_PROXY_CERT_PATH isolated certificates, state, and logs. Each returned log path was asserted to be within the owned fixture directory.

Every runtime row required a live PID, two distinct OS-assigned ports within 1–65535, authenticated GET /proxy returning 200, PID-scoped JSON status identifying that instance, and an explicitly proxied client request returning HTTP 200 with the exact mock body. All rows retain CLI zero-port overrides; they do not prove rejection of effective invalid configuration ports.

Scenario or test command Expected Actual Result
dotnet build DevProxy.sln --no-restore --verbosity quiet Source and plugins build 0 warnings, 0 errors PASS
Current-head GitHub CI, not rerun locally Required automated checks succeed for tested SHA Build, client smoke, macOS/Linux/Windows tests, CodeQL and CLA succeeded PASS
Config port: 0, apiPort: 0 Assigned ports; API and exact mock response work PID 40638; proxy/API 57407/57408; all assertions passed PASS
Config port: -1, apiPort: 0, CLI zero overrides CLI precedence preserved PID 40795; proxy/API 57502/57501; all assertions passed PASS
Config port: 70000, apiPort: 0, CLI zero overrides CLI precedence preserved PID 41060; proxy/API 57600/57601; all assertions passed PASS
Config port: 0, apiPort: -1, CLI zero overrides CLI precedence preserved PID 41267; proxy/API 57721/57722; all assertions passed PASS
Config port: 0, apiPort: 70000, CLI zero overrides CLI precedence preserved PID 41516; proxy/API 57843/57842; all assertions passed PASS
Config port: 65536, apiPort: 0, CLI zero overrides CLI precedence preserved PID 41698; proxy/API 62271/62254; all assertions passed PASS
Config port: 0, apiPort: 65536, CLI zero overrides CLI precedence preserved PID 41874; proxy/API 52918/52919; all assertions passed PASS
Config port: 65535, apiPort: 0, CLI zero overrides CLI precedence preserved PID 41974; proxy/API 53021/53022; all assertions passed PASS
Config port: 0, apiPort: 65535, CLI zero overrides CLI precedence preserved PID 42042; proxy/API 53102/53103; all assertions passed PASS
Config port: -1, apiPort: 70000, CLI zero overrides Both CLI values win PID 42117; proxy/API 53192/53193; all assertions passed PASS
Issue #2140: effective config -1/70000 and first invalid upper boundary 65536 Exit 1, name setting and range 0–65535, no stack trace Mandatory safe CLI flags override config ports, masking direct rejection behavior BLOCKED
Effective config upper valid boundary 65535 without override Bind when available Mandatory safe CLI flags mask the configured boundary BLOCKED
Windows-specific temp-directory handle-release retry Process-smoke cleanup succeeds on Windows Current-head Windows test check passed; Windows-specific behavior not reproduced locally on macOS PASS (CI)
Cleanup Stop only owned instances and remove private runtime files All ten PIDs exited after matching-build stop --pid; private home/certificates/state/logs/fixtures removed PASS

Requested changes

None established. No reproduced functional defect attributable to the PR.

Outcome

Comment only. Ten runtime scenarios and current-head CI passed. Direct config-port rejection remains blocked by the mandatory zero-port launch flags; passing override tests are not a substitute for that reproduction. No approval or change request is justified by this incomplete functional evidence. No code changes, pushes or merges; original checkout restored clean. Functional testing does not replace code review.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings December 2, 2026 12:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the configuration-port validation change.

No open issues 🎉

Review effort: Balanced

# Conflicts:
#	DevProxy/Commands/DevProxyCommand.cs
Copilot AI balanced review requested due to automatic review settings December 2, 2026 14:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues block the configuration-port validation changes.

No open issues 🎉

Review effort: Balanced

@garrytrinder garrytrinder left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Functional test results

  • PR: #2157
  • Tested commit: 6ec478abc9276fece5983989c7d5876df55e2d89
  • Environment: macOS arm64; private .NET SDK 11.0.100; source Debug build.

This report replaces the results for previous commits.

The test fixtures used MockResponsePlugin and watched http://pr2157.example/*.
The mock returned HTTP 200 and {"source":"pr2157","ok":true} for GET http://pr2157.example/test.
The tests disabled schema validation.

Each runtime case used this command:

<private-sdk>/dotnet run --no-build --no-launch-profile --project DevProxy -- \
  --detach --as-system-proxy false --install-cert false \
  --port 0 --api-port 0 --config-file <fixture.json> --output json

The tests used private HOME and CFFIXED_USER_HOME directories.
The tests created Library/Application Support before startup.
An absolute DEV_PROXY_CERT_PATH selected a private root certificate.
The configuration also set installCert: false and noFirstRun: true.
These settings prevented native certificate installation and system-proxy changes.

The source resolves state and leaf certificates below the application's data directory.
Each runtime case confirmed its private state file, log path, and root certificate.
Each case recorded the process identifier (PID) and process start time.

Each passing runtime case confirmed:

  • The process remained active after startup.
  • The proxy and application programming interface (API) used different assigned ports between 1 and 65535.
  • Authenticated GET /proxy returned HTTP 200.
  • status --pid <PID> --output json identified the correct process.
  • An explicit proxy request returned HTTP 200 and the exact mock body.

The client command was:

curl --silent --show-error --max-time 10 --noproxy "" \
  --proxy <assigned-proxy-url> --write-out "\n%{http_code}" \
  http://pr2157.example/test
Scenario or test command Expected Actual Result
Locked restore with private SDK 11.0.100 Restore without lock-file changes Restore completed; lock files remained unchanged PASS
dotnet build DevProxy.sln --no-restore --verbosity quiet with private SDK Build source and plugins Build completed with 0 warnings and 0 errors PASS
Continuous integration (CI) checks for the tested commit All required checks pass Build, smoke, macOS/Linux/Windows tests, CodeQL, and CLA checks passed PASS
Configured port: 0, apiPort: 0 Assigned ports; API and mock work PID 88846; proxy/API ports 56178/56179; all runtime checks passed PASS
Configured port: -1, apiPort: 0, with command-line port values Command-line values take priority PID 89632; ports 56245/56246; all runtime checks passed PASS
Configured port: 70000, apiPort: 0, with command-line port values Command-line values take priority PID 90267; ports 56285/56286; all runtime checks passed PASS
Configured port: 0, apiPort: -1, with command-line port values Command-line values take priority PID 90878; ports 56322/56323; all runtime checks passed PASS
Configured port: 0, apiPort: 70000, with command-line port values Command-line values take priority PID 91101; ports 56390/56391; all runtime checks passed PASS
Configured port: 65536, apiPort: 0, with command-line port values Command-line values take priority PID 91185; ports 56460/56461; all runtime checks passed PASS
Configured port: 0, apiPort: 65536, with command-line port values Command-line values take priority PID 91246; ports 56515/56516; all runtime checks passed PASS
Configured port: 65535, apiPort: 0, with command-line port values Command-line values take priority PID 91357; ports 56573/56574; all runtime checks passed PASS
Configured port: 0, apiPort: 65535, with command-line port values Command-line values take priority PID 91425; ports 56644/56645; all runtime checks passed PASS
Configured port: -1, apiPort: 70000, with command-line port values Both command-line values take priority PID 91505; ports 56703/56704; all runtime checks passed PASS
Issue #2140: effective configured values -1/70000; additional value 65536 Exit 1; identify the setting and valid range; no unhandled stack trace Required command-line values replace the configured values; direct rejection remains untested BLOCKED
Effective configured value 65535, without a command-line replacement Accept the valid upper limit when available Required command-line values prevent this test BLOCKED
Process and file removal Stop only owned processes; close listeners; remove private files All ten proxy processes exited; all twenty listeners closed; private files and SDK were removed PASS

The system SDK 10.0.103 could not build the net11.0 projects.
A private preview SDK produced NU1004 during locked restore.
The private release SDK 11.0.100 completed locked restore and build without source changes.
The tests did not repeat automated test suites locally; the report uses CI results for this commit.

Startup exceptions and cleanup

Scenario Changed default Why the default prevents reproduction Execution environment Safety controls Cleanup verification
Ten runtime cases None Not applicable macOS; private home, state, logs, root and leaf certificates Detached startup; finite command deadlines; loopback; system proxy and certificate installation disabled Matching-build stop --pid; process identity recorded; all owned processes exited; listeners closed; private files removed
Direct configured-port rejection and effective upper limit No exception applied Both zero-port flags replace configured values Not executed Governing session custom instructions require both flags for every test launch No additional processes or listeners

The current repository workflow permits omission of the relevant command-line port value.
However, this session retains a governing copy of the custom instructions under Testing Code Changes.
That copy requires both zero-port flags for every launch.
The current workflow explicitly states that repository edits cannot replace a governing copy already loaded into a session.
Therefore, the direct rejection tests remain blocked.
The passing replacement-value tests do not establish rejection behavior.

Requested changes

None established. The tests found no reproducible defect attributable to this PR.

Outcome

Comment only. Ten runtime cases passed on the tested commit.
The build and CI checks also passed.
Essential rejection tests remain blocked by the instruction conflict.
These results do not justify approval or a request for changes.

The tests stopped only owned processes.
The tests removed the private runtime files, private SDK, and its compiler process.
The original checkout was restored without source changes.
No fixes, pushes, or merges were made.
Functional testing does not replace code review.

The ASD-STE100 check is incomplete.
The official site requires a request for the full standard and dictionary.
This report does not claim verified conformance.

…r-2157

# Conflicts:
#	DevProxy/Commands/DevProxyCommand.cs
Copilot AI balanced review requested due to automatic review settings December 3, 2026 13:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the configuration-port validation changes.

No open issues 🎉

Review effort: Balanced

@garrytrinder garrytrinder left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Functional test results

  • PR: dotnet/dev-proxy#2157
  • Tested commit: 22eb23e3496aeaf0aa7963b92af2e96cf8214dab
  • Environment: macOS arm64; private .NET SDK 11.0.100; source Debug build; loopback addresses.

All 19 functional cases passed.
This report replaces earlier reports that did not test direct rejection of configured ports.
The PR changed during testing.
The tests rebuilt the source and repeated all 19 cases on the commit above.

The test fixtures used MockResponsePlugin and watched http://pr2157.example/*.
The mock returned HTTP 200 and {"source":"pr2157","ok":true} for GET http://pr2157.example/test.
Schema validation and version notifications were disabled.

Each case used the executable from the PR source build:

<PR-build>/devproxy --detach \
  --as-system-proxy false --install-cert false \
  --config-file <fixture.json> --output json <port-options>

For direct configuration tests, the matching command-line port option was absent.
The other port option remained zero unless the case tested both configured values.
Command-line priority cases used --port 0 --api-port 0.
Command-line validation cases replaced only the option under test.

Each configuration rejection matched this exact diagnostic, with the tested value and setting:

'<value>' is not a valid value for '<setting>' in the configuration file. Specify a number between 0 and 65535.

Each rejection also returned exit status 1 without an unhandled exception or stack trace.
Detached startup preserved the diagnostic and exit status.
No foreground exception was necessary.

The application programming interface (API) requires authentication.
Each successful startup passed an authenticated GET /proxy request with HTTP 200.
Each instance passed status --pid <PID> --output json.
An explicit proxy request returned HTTP 200 and the exact mock body.
The tests confirmed the assigned ports and private state, log, and certificate paths.

CLI means command-line interface.
PID means process identifier.

Scenario or test command Expected Actual Result
Configured port: -1; no --port Configuration diagnostic; exit 1; no stack trace Exact diagnostic identified port and -1; exit 1; no stack trace PASS
Configured port: 70000; no --port Configuration diagnostic; exit 1; no stack trace Exact diagnostic identified port and 70000; exit 1; no stack trace PASS
Configured port: 65536; no --port Reject the first value above the valid limit Exact diagnostic identified port and 65536; exit 1; no stack trace PASS
Configured apiPort: -1; no --api-port Configuration diagnostic; exit 1; no stack trace Exact diagnostic identified apiPort and -1; exit 1; no stack trace PASS
Configured apiPort: 70000; no --api-port Configuration diagnostic; exit 1; no stack trace Exact diagnostic identified apiPort and 70000; exit 1; no stack trace PASS
Configured apiPort: 65536; no --api-port Reject the first value above the valid limit Exact diagnostic identified apiPort and 65536; exit 1; no stack trace PASS
Configured port: -1, apiPort: 70000; neither override Identify invalid port first Exact diagnostic identified port and -1; exit 1; no stack trace PASS
Configured port: 0, apiPort: 0; neither override Assign usable ports; API and proxy work PID 78177; proxy/API 57351/57352; all runtime checks passed PASS
Configured port: 65535; no --port Use the valid upper limit PID 78240; proxy/API 65535/57372; all runtime checks passed PASS
Configured apiPort: 65535; no --api-port Use the valid upper limit PID 78312; proxy/API 57392/65535; all runtime checks passed PASS
Configured port: -1; both CLI zero options Command-line values take priority PID 78379; proxy/API 57419/57420; all runtime checks passed PASS
Configured port: 70000; both CLI zero options Command-line values take priority PID 78426; proxy/API 57442/57443; all runtime checks passed PASS
Configured apiPort: -1; both CLI zero options Command-line values take priority PID 78488; proxy/API 57464/57465; all runtime checks passed PASS
Configured apiPort: 70000; both CLI zero options Command-line values take priority PID 78547; proxy/API 57487/57488; all runtime checks passed PASS
Configured port: -1, apiPort: 70000; both CLI zero options Both command-line values take priority PID 78617; proxy/API 57509/57510; all runtime checks passed PASS
CLI --port -1 Port diagnostic; exit 2 Diagnostic gave valid range 0–65535; exit 2; no stack trace PASS
CLI --port 70000 Port diagnostic; exit 2 Diagnostic gave valid range 0–65535; exit 2; no stack trace PASS
CLI --api-port -1 Port diagnostic; exit 2 Diagnostic gave valid range 0–65535; exit 2; no stack trace PASS
CLI --api-port 70000 Port diagnostic; exit 2 Diagnostic gave valid range 0–65535; exit 2; no stack trace PASS
Source executable and plugin builds with --no-restore --disable-build-servers -p:UseSharedCompilation=false Both projects build Both builds completed with zero warnings and zero errors PASS
Continuous integration checks for the tested commit Automated validation passes Build, smoke, macOS/Linux/Windows tests, CodeQL, analysis, and CLA checks passed PASS
Owned process and file removal Stop owned processes; close listeners; remove private files All owned processes exited; all 16 runtime listeners closed; private files removed PASS

The system SDK was version 10.0.103, but the source requires .NET 11.
The tests used a private release SDK without changing the system installation.
An initial build failed because package assets were absent.
Network restore then failed because the NuGet connection could not complete.
The tests copied required packages into a private cache.
Locked restore then succeeded for the executable and plugins.
The tests used the existing cache only as a source.
No dependency lock files changed.
The tests did not repeat automated test suites locally.

Startup exceptions and cleanup

The tests used private HOME and CFFIXED_USER_HOME paths below .devproxy/test-pr-2157-c362d474.
The tests created Library/Application Support before running .NET.
An absolute DEV_PROXY_CERT_PATH selected a private root certificate.
The configuration also set installCert: false and noFirstRun: true.
All Dev Proxy launches disabled system proxy registration and certificate trust installation.

Scenario Changed default Why the default prevents reproduction Execution environment Safety controls Cleanup verification
Three direct port rejections Omitted --port 0 The CLI option replaces the invalid configured value Private macOS environment Detached; 25-second deadline; separate output capture; loopback; native changes disabled All owned launchers and daemons exited; no instance state remained
Three direct apiPort rejections Omitted --api-port 0 The CLI option replaces the invalid configured value Same environment Same controls Same checks passed
Two invalid configured values Omitted both zero-port options Both configured values must remain effective Same environment Same controls Same checks passed
Configured zero Omitted both zero-port options CLI values would hide whether configured zero works Same environment Same controls; authenticated API and explicit proxy request Owned process exited after stop --pid; both listeners closed
Each configured upper limit Omitted only the matching zero-port option The CLI option replaces configured 65535 Same environment Checked port availability before each launch; same runtime controls Both owned instances exited; all four listeners closed
Five CLI priority cases None Not applicable Same environment Same runtime controls All five owned instances exited; all ten listeners closed
Four invalid CLI values Replaced only the CLI zero value under test Zero cannot test CLI rejection Same environment Same rejection controls All owned launchers and daemons exited; no instance state remained

The tests recorded process identifiers and start times.
Successful instances stopped through the matching build with stop --pid <PID>.
Final checks found no remaining owned processes or listeners.
The tests removed the private SDK, package cache, home, certificates, logs, state, and fixtures.
The tests restored the original branch and commit.
The source checkout is clean.

Requested changes

None.

Outcome

Approval for functional testing.
All necessary functional cases passed on the tested commit.
The tests verified direct configuration rejection without CLI options that replace those values.
No functional tests remain blocked.
Cleanup passed.
This approval does not replace code review.
The tests did not change, push, or merge code.

The ASD-STE100 check is incomplete.
The official site requires a separate request for the full standard and dictionary.
This report does not claim verified conformance.

@waldekmastykarz
waldekmastykarz merged commit 9fd319c into dotnet:main Dec 4, 2026
8 checks passed
@waldekmastykarz
waldekmastykarz deleted the psychic-fiesta branch December 4, 2026 07:34
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.

[BUG]: Out-of-range port or apiPort in config file crashes with an unhandled exception

3 participants