Skip to content

Conversation

@LingyuCoder
Copy link
Contributor

This pull request updates and expands the snapshot tests for allowed hosts and host header handling in the webpack-dev-server test suite. The changes include new test cases for different host and origin scenarios, improved output for error responses, and more detailed console and error message tracking for various websocket connection types.

The most important changes are:

Expanded test coverage for allowed hosts:

  • Added snapshot tests for allowing hosts when options.allowedHosts is set to auto, covering cases where the host is specified directly or via client.webSocketURL, and for various host values such as [::1], 0.0.0.0, 127.0.0.1, and localhost, across both "sockjs" and "ws" websocket transports. [1] [2]

New origin header handling tests:

  • Introduced tests for connecting and disconnecting web socket clients using an origin header containing an IP address, verifying behavior with both custom hostnames and the "auto" allowed hosts setting, for both "sockjs" and "ws" transports.

Improved error response and console output validation:

  • Enhanced the HTML error responses for invalid host headers to include a <meta name="color-scheme" content="light dark"> tag and improved formatting, and updated the expected console messages for forbidden (403) responses.

Default host handling tests:

  • Added tests to confirm that connections using default hosts such as "localhost" are allowed by default for both "sockjs" and "ws" transports, with corresponding console and error message expectations.

Detailed reconnection and error flow tests:

  • Added checks for specific console log sequences when the server disconnects clients due to invalid host/origin headers, ensuring that reconnection attempts and error messages are properly reported.

Copilot AI review requested due to automatic review settings January 14, 2026 07:36
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request enables the previously disabled allowed-hosts.test.js test file and expands test coverage for host and origin header validation in webpack-dev-server. The changes reorganize existing tests and add new test cases covering various scenarios including IPv4, IPv6, and localhost connections, as well as origin header handling with IP addresses.

Changes:

  • Enabled allowed-hosts.test.js by removing it from test ignore patterns in jest.config.js
  • Reorganized and renamed existing test cases to improve clarity
  • Added new test cases for origin headers containing IP addresses and default host handling
  • Updated API method calls from checkHeader to isValidHost

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 4 comments.

File Description
jest.config.js Removed test ignore pattern to enable allowed-hosts.test.js
tests/e2e/allowed-hosts.test.js Reorganized test structure, added new test cases for various host/origin scenarios, updated API method calls
tests/e2e/snapshots/allowed-hosts.test.js.snap.webpack5 Added snapshot expectations for new test cases and updated existing snapshots with improved error formatting

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@LingyuCoder LingyuCoder merged commit 3c6140a into main Jan 14, 2026
10 checks passed
@LingyuCoder LingyuCoder deleted the test/enable-allowed-hosts-test branch January 14, 2026 07:49
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.

2 participants