Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't allow empty array for allowedHosts option #3451

Merged
merged 1 commit into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"anyOf": [
{
"type": "array",
"minItems": 1,
"items": {
"$ref": "#/definitions/AllowedHostsItem"
}
Expand Down
22 changes: 16 additions & 6 deletions test/__snapshots__/validate-options.test.js.snap.webpack4
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`options validate should throw an error on the "allowedHosts" option with '[""]' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.allowedHosts[0] should be an non-empty string."
`;

exports[`options validate should throw an error on the "allowedHosts" option with '[]' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.allowedHosts should be an non-empty array."
`;

exports[`options validate should throw an error on the "allowedHosts" option with '123' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.allowedHosts should be one of these:
[non-empty string, ...] | \\"auto\\" | \\"all\\" | non-empty string
[non-empty string, ...] (should not have fewer than 1 item) | \\"auto\\" | \\"all\\" | non-empty string
-> Allows to enumerate the hosts from which access to the dev server are allowed (useful when you are proxying dev server, by default is 'auto'). https://webpack.js.org/configuration/dev-server/#devserverallowedhosts
Details:
* options.allowedHosts should be an array:
[non-empty string, ...]
[non-empty string, ...] (should not have fewer than 1 item)
* options.allowedHosts should be one of these:
\\"auto\\" | \\"all\\"
* options.allowedHosts should be a non-empty string."
Expand All @@ -16,11 +26,11 @@ exports[`options validate should throw an error on the "allowedHosts" option wit
exports[`options validate should throw an error on the "allowedHosts" option with 'false' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.allowedHosts should be one of these:
[non-empty string, ...] | \\"auto\\" | \\"all\\" | non-empty string
[non-empty string, ...] (should not have fewer than 1 item) | \\"auto\\" | \\"all\\" | non-empty string
-> Allows to enumerate the hosts from which access to the dev server are allowed (useful when you are proxying dev server, by default is 'auto'). https://webpack.js.org/configuration/dev-server/#devserverallowedhosts
Details:
* options.allowedHosts should be an array:
[non-empty string, ...]
[non-empty string, ...] (should not have fewer than 1 item)
* options.allowedHosts should be one of these:
\\"auto\\" | \\"all\\"
* options.allowedHosts should be a non-empty string."
Expand All @@ -29,11 +39,11 @@ exports[`options validate should throw an error on the "allowedHosts" option wit
exports[`options validate should throw an error on the "allowedHosts" option with 'true' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.allowedHosts should be one of these:
[non-empty string, ...] | \\"auto\\" | \\"all\\" | non-empty string
[non-empty string, ...] (should not have fewer than 1 item) | \\"auto\\" | \\"all\\" | non-empty string
-> Allows to enumerate the hosts from which access to the dev server are allowed (useful when you are proxying dev server, by default is 'auto'). https://webpack.js.org/configuration/dev-server/#devserverallowedhosts
Details:
* options.allowedHosts should be an array:
[non-empty string, ...]
[non-empty string, ...] (should not have fewer than 1 item)
* options.allowedHosts should be one of these:
\\"auto\\" | \\"all\\"
* options.allowedHosts should be a non-empty string."
Expand Down
22 changes: 16 additions & 6 deletions test/__snapshots__/validate-options.test.js.snap.webpack5
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`options validate should throw an error on the "allowedHosts" option with '[""]' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.allowedHosts[0] should be an non-empty string."
`;

exports[`options validate should throw an error on the "allowedHosts" option with '[]' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.allowedHosts should be an non-empty array."
`;

exports[`options validate should throw an error on the "allowedHosts" option with '123' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.allowedHosts should be one of these:
[non-empty string, ...] | \\"auto\\" | \\"all\\" | non-empty string
[non-empty string, ...] (should not have fewer than 1 item) | \\"auto\\" | \\"all\\" | non-empty string
-> Allows to enumerate the hosts from which access to the dev server are allowed (useful when you are proxying dev server, by default is 'auto'). https://webpack.js.org/configuration/dev-server/#devserverallowedhosts
Details:
* options.allowedHosts should be an array:
[non-empty string, ...]
[non-empty string, ...] (should not have fewer than 1 item)
* options.allowedHosts should be one of these:
\\"auto\\" | \\"all\\"
* options.allowedHosts should be a non-empty string."
Expand All @@ -16,11 +26,11 @@ exports[`options validate should throw an error on the "allowedHosts" option wit
exports[`options validate should throw an error on the "allowedHosts" option with 'false' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.allowedHosts should be one of these:
[non-empty string, ...] | \\"auto\\" | \\"all\\" | non-empty string
[non-empty string, ...] (should not have fewer than 1 item) | \\"auto\\" | \\"all\\" | non-empty string
-> Allows to enumerate the hosts from which access to the dev server are allowed (useful when you are proxying dev server, by default is 'auto'). https://webpack.js.org/configuration/dev-server/#devserverallowedhosts
Details:
* options.allowedHosts should be an array:
[non-empty string, ...]
[non-empty string, ...] (should not have fewer than 1 item)
* options.allowedHosts should be one of these:
\\"auto\\" | \\"all\\"
* options.allowedHosts should be a non-empty string."
Expand All @@ -29,11 +39,11 @@ exports[`options validate should throw an error on the "allowedHosts" option wit
exports[`options validate should throw an error on the "allowedHosts" option with 'true' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.allowedHosts should be one of these:
[non-empty string, ...] | \\"auto\\" | \\"all\\" | non-empty string
[non-empty string, ...] (should not have fewer than 1 item) | \\"auto\\" | \\"all\\" | non-empty string
-> Allows to enumerate the hosts from which access to the dev server are allowed (useful when you are proxying dev server, by default is 'auto'). https://webpack.js.org/configuration/dev-server/#devserverallowedhosts
Details:
* options.allowedHosts should be an array:
[non-empty string, ...]
[non-empty string, ...] (should not have fewer than 1 item)
* options.allowedHosts should be one of these:
\\"auto\\" | \\"all\\"
* options.allowedHosts should be a non-empty string."
Expand Down
2 changes: 1 addition & 1 deletion test/validate-options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ const tests = {
},
allowedHosts: {
success: ['auto', 'all', ['foo'], 'bar'],
failure: [true, false, 123],
failure: [true, false, 123, [], ['']],
},
headers: {
success: [{}, { foo: 'bar' }, () => {}],
Expand Down