Skip to content

Commit

Permalink
fix: don't allow empty array for allowedHosts option
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Jun 17, 2021
1 parent 809631c commit 894a680
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
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

0 comments on commit 894a680

Please sign in to comment.