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

feat: add https.cacert #3240

Merged
merged 1 commit into from
May 5, 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
2 changes: 1 addition & 1 deletion lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ class Server {
}

if (this.options.https) {
for (const property of ['ca', 'pfx', 'key', 'cert']) {
for (const property of ['cacert', 'pfx', 'key', 'cert']) {
const value = this.options.https[property];
const isBuffer = value instanceof Buffer;

Expand Down
2 changes: 1 addition & 1 deletion lib/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@
"requestCert": {
"type": "boolean"
},
"ca": {
"cacert": {
"anyOf": [
{
"type": "string"
Expand Down
6 changes: 3 additions & 3 deletions test/__snapshots__/validate-options.test.js.snap.webpack4
Original file line number Diff line number Diff line change
Expand Up @@ -178,18 +178,18 @@ exports[`options validate should throw an error on the "http2" option with '' va
exports[`options validate should throw an error on the "https" option with '' value 1`] = `
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.https should be one of these:
boolean | object { passphrase?, requestCert?, ca?, key?, pfx?, cert? }
boolean | object { passphrase?, requestCert?, cacert?, key?, pfx?, cert? }
-> By default, dev-server will be served over HTTP. It can optionally be served over HTTP/2 with HTTPS. https://webpack.js.org/configuration/dev-server/#devserverhttps
Details:
* configuration.https should be a boolean.
* configuration.https should be an object:
object { passphrase?, requestCert?, ca?, key?, pfx?, cert? }"
object { passphrase?, requestCert?, cacert?, key?, pfx?, cert? }"
`;

exports[`options validate should throw an error on the "https" option with '{"foo":"bar"}' value 1`] = `
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.https has an unknown property 'foo'. These properties are valid:
object { passphrase?, requestCert?, ca?, key?, pfx?, cert? }"
object { passphrase?, requestCert?, cacert?, key?, pfx?, cert? }"
`;

exports[`options validate should throw an error on the "onAfterSetupMiddleware" option with 'false' value 1`] = `
Expand Down
6 changes: 3 additions & 3 deletions test/__snapshots__/validate-options.test.js.snap.webpack5
Original file line number Diff line number Diff line change
Expand Up @@ -178,18 +178,18 @@ exports[`options validate should throw an error on the "http2" option with '' va
exports[`options validate should throw an error on the "https" option with '' value 1`] = `
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.https should be one of these:
boolean | object { passphrase?, requestCert?, ca?, key?, pfx?, cert? }
boolean | object { passphrase?, requestCert?, cacert?, key?, pfx?, cert? }
-> By default, dev-server will be served over HTTP. It can optionally be served over HTTP/2 with HTTPS. https://webpack.js.org/configuration/dev-server/#devserverhttps
Details:
* configuration.https should be a boolean.
* configuration.https should be an object:
object { passphrase?, requestCert?, ca?, key?, pfx?, cert? }"
object { passphrase?, requestCert?, cacert?, key?, pfx?, cert? }"
`;

exports[`options validate should throw an error on the "https" option with '{"foo":"bar"}' value 1`] = `
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.https has an unknown property 'foo'. These properties are valid:
object { passphrase?, requestCert?, ca?, key?, pfx?, cert? }"
object { passphrase?, requestCert?, cacert?, key?, pfx?, cert? }"
`;

exports[`options validate should throw an error on the "onAfterSetupMiddleware" option with 'false' value 1`] = `
Expand Down
22 changes: 13 additions & 9 deletions test/server/https-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('https option', () => {
afterAll(testServer.close);
});

describe('as an object when ca, pfx, key and cert are buffer', () => {
describe('as an object when cacert, pfx, key and cert are buffer', () => {
beforeAll((done) => {
server = testServer.start(
config,
Expand All @@ -55,7 +55,9 @@ describe('https option', () => {
watch: false,
},
https: {
ca: fs.readFileSync(path.join(httpsCertificateDirectory, 'ca.pem')),
cacert: fs.readFileSync(
path.join(httpsCertificateDirectory, 'ca.pem')
),
pfx: fs.readFileSync(
path.join(httpsCertificateDirectory, 'server.pfx')
),
Expand All @@ -79,14 +81,14 @@ describe('https option', () => {
});
});

describe('as an object when ca, pfx, key and cert are paths', () => {
describe('as an object when cacert, pfx, key and cert are paths', () => {
beforeAll((done) => {
server = testServer.start(
config,
{
static: contentBasePublic,
https: {
ca: path.join(httpsCertificateDirectory, 'ca.pem'),
cacert: path.join(httpsCertificateDirectory, 'ca.pem'),
pfx: path.join(httpsCertificateDirectory, 'server.pfx'),
key: path.join(httpsCertificateDirectory, 'server.key'),
cert: path.join(httpsCertificateDirectory, 'server.crt'),
Expand All @@ -104,7 +106,7 @@ describe('https option', () => {
});
});

describe('as an object when ca, pfx, key and cert are symlinks', () => {
describe('as an object when cacert, pfx, key and cert are symlinks', () => {
if (skipTestOnWindows('Symlinks are not supported on Windows')) {
return;
}
Expand All @@ -118,7 +120,7 @@ describe('https option', () => {
watch: false,
},
https: {
ca: path.join(httpsCertificateDirectory, 'ca-symlink.pem'),
cacert: path.join(httpsCertificateDirectory, 'ca-symlink.pem'),
pfx: path.join(httpsCertificateDirectory, 'server-symlink.pfx'),
key: path.join(httpsCertificateDirectory, 'server-symlink.key'),
cert: path.join(httpsCertificateDirectory, 'server-symlink.crt'),
Expand All @@ -138,7 +140,7 @@ describe('https option', () => {
afterAll(testServer.close);
});

describe('as an object when ca, pfx, key and cert are raw strings', () => {
describe('as an object when cacert, pfx, key and cert are raw strings', () => {
beforeAll((done) => {
server = testServer.start(
config,
Expand All @@ -148,7 +150,7 @@ describe('https option', () => {
watch: false,
},
https: {
ca: fs
cacert: fs
.readFileSync(path.join(httpsCertificateDirectory, 'ca.pem'))
.toString(),
// pfx can't be string because it is binary format
Expand Down Expand Up @@ -186,7 +188,9 @@ describe('https option', () => {
},
https: {
requestCert: true,
ca: fs.readFileSync(path.join(httpsCertificateDirectory, 'ca.pem')),
cacert: fs.readFileSync(
path.join(httpsCertificateDirectory, 'ca.pem')
),
pfx: fs.readFileSync(
path.join(httpsCertificateDirectory, 'server.pfx')
),
Expand Down
4 changes: 2 additions & 2 deletions test/validate-options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,15 @@ const tests = {
false,
true,
{
ca: join(httpsCertificateDirectory, 'ca.pem'),
cacert: join(httpsCertificateDirectory, 'ca.pem'),
key: join(httpsCertificateDirectory, 'server.key'),
pfx: join(httpsCertificateDirectory, 'server.pfx'),
cert: join(httpsCertificateDirectory, 'server.crt'),
requestCert: true,
passphrase: 'webpack-dev-server',
},
{
ca: readFileSync(join(httpsCertificateDirectory, 'ca.pem')),
cacert: readFileSync(join(httpsCertificateDirectory, 'ca.pem')),
pfx: readFileSync(join(httpsCertificateDirectory, 'server.pfx')),
key: readFileSync(join(httpsCertificateDirectory, 'server.key')),
cert: readFileSync(join(httpsCertificateDirectory, 'server.crt')),
Expand Down