Skip to content

Commit

Permalink
feat: add https.cacert (#3240)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `https.ca` was removed in favor `https.cacert`
  • Loading branch information
snitin315 authored May 5, 2021
1 parent 6e0e653 commit b212a2c
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 19 deletions.
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 @@ -312,7 +312,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

0 comments on commit b212a2c

Please sign in to comment.