From 4b2076c743d65f32f4ae68bd0c962feaee7a00ed Mon Sep 17 00:00:00 2001 From: Evilebot Tnawi Date: Mon, 25 Feb 2019 13:35:34 +0300 Subject: [PATCH] fix(regression): handle `key`, `cert`, `cacert` and `pfx` in CLI (#1688) --- lib/utils/createConfig.js | 16 +++ test/CreateConfig.test.js | 89 +++++++++++++ test/__snapshots__/CreateConfig.test.js.snap | 128 +++++++++++++++++++ 3 files changed, 233 insertions(+) diff --git a/lib/utils/createConfig.js b/lib/utils/createConfig.js index 792670428f..53e00cf2af 100644 --- a/lib/utils/createConfig.js +++ b/lib/utils/createConfig.js @@ -136,6 +136,22 @@ function createConfig(config, argv, { port }) { options.https = true; } + if (argv.key) { + options.key = argv.key; + } + + if (argv.cert) { + options.cert = argv.cert; + } + + if (argv.cacert) { + options.ca = argv.cacert; + } + + if (argv.pfx) { + options.pfx = argv.pfx; + } + if (argv.pfxPassphrase) { options.pfxPassphrase = argv.pfxPassphrase; } diff --git a/test/CreateConfig.test.js b/test/CreateConfig.test.js index e0209bd600..edeb0da422 100644 --- a/test/CreateConfig.test.js +++ b/test/CreateConfig.test.js @@ -559,6 +559,95 @@ describe('createConfig', () => { expect(config).toMatchSnapshot(); }); + it('key option', () => { + const config = createConfig( + webpackConfig, + Object.assign({}, argv, { https: true, key: '/path/to/server.key' }), + { port: 8080 } + ); + + expect(config).toMatchSnapshot(); + }); + + it('key option (in devServer config)', () => { + const config = createConfig( + Object.assign({}, webpackConfig, { + devServer: { https: true, key: '/path/to/server.key' }, + }), + argv, + { port: 8080 } + ); + + expect(config).toMatchSnapshot(); + }); + + it('cert option', () => { + const config = createConfig( + webpackConfig, + Object.assign({}, argv, { https: true, cert: '/path/to/server.crt' }), + { port: 8080 } + ); + + expect(config).toMatchSnapshot(); + }); + + it('cert option (in devServer config)', () => { + const config = createConfig( + Object.assign({}, webpackConfig, { + devServer: { https: true, cert: '/path/to/server.crt' }, + }), + argv, + { port: 8080 } + ); + + expect(config).toMatchSnapshot(); + }); + + it('cacert option', () => { + const config = createConfig( + webpackConfig, + Object.assign({}, argv, { https: true, cacert: '/path/to/ca.pem' }), + { port: 8080 } + ); + + expect(config).toMatchSnapshot(); + }); + + it('cacert option (in devServer config)', () => { + const config = createConfig( + Object.assign({}, webpackConfig, { + // TODO rename `ca` to `cacert` for `v4` to avoid difference between CLI and configuration + devServer: { https: true, ca: '/path/to/ca.pem' }, + }), + argv, + { port: 8080 } + ); + + expect(config).toMatchSnapshot(); + }); + + it('pfx option', () => { + const config = createConfig( + webpackConfig, + Object.assign({}, argv, { https: true, pfx: '/path/to/file.pfx' }), + { port: 8080 } + ); + + expect(config).toMatchSnapshot(); + }); + + it('pfx option (in devServer config)', () => { + const config = createConfig( + Object.assign({}, webpackConfig, { + devServer: { https: true, pfx: '/path/to/file.pfx' }, + }), + argv, + { port: 8080 } + ); + + expect(config).toMatchSnapshot(); + }); + it('pfxPassphrase option', () => { const config = createConfig( webpackConfig, diff --git a/test/__snapshots__/CreateConfig.test.js.snap b/test/__snapshots__/CreateConfig.test.js.snap index 99bce55b15..c66f9ab9de 100644 --- a/test/__snapshots__/CreateConfig.test.js.snap +++ b/test/__snapshots__/CreateConfig.test.js.snap @@ -66,6 +66,70 @@ Object { } `; +exports[`createConfig cacert option (in devServer config) 1`] = ` +Object { + "ca": "/path/to/ca.pem", + "hot": true, + "hotOnly": false, + "https": true, + "noInfo": true, + "port": 8080, + "publicPath": "/", + "stats": Object { + "cached": false, + "cachedAssets": false, + }, +} +`; + +exports[`createConfig cacert option 1`] = ` +Object { + "ca": "/path/to/ca.pem", + "hot": true, + "hotOnly": false, + "https": true, + "noInfo": true, + "port": 8080, + "publicPath": "/", + "stats": Object { + "cached": false, + "cachedAssets": false, + }, +} +`; + +exports[`createConfig cert option (in devServer config) 1`] = ` +Object { + "cert": "/path/to/server.crt", + "hot": true, + "hotOnly": false, + "https": true, + "noInfo": true, + "port": 8080, + "publicPath": "/", + "stats": Object { + "cached": false, + "cachedAssets": false, + }, +} +`; + +exports[`createConfig cert option 1`] = ` +Object { + "cert": "/path/to/server.crt", + "hot": true, + "hotOnly": false, + "https": true, + "noInfo": true, + "port": 8080, + "publicPath": "/", + "stats": Object { + "cached": false, + "cachedAssets": false, + }, +} +`; + exports[`createConfig clientLogLevel option (in devServer config) 1`] = ` Object { "clientLogLevel": "none", @@ -513,6 +577,38 @@ Object { } `; +exports[`createConfig key option (in devServer config) 1`] = ` +Object { + "hot": true, + "hotOnly": false, + "https": true, + "key": "/path/to/server.key", + "noInfo": true, + "port": 8080, + "publicPath": "/", + "stats": Object { + "cached": false, + "cachedAssets": false, + }, +} +`; + +exports[`createConfig key option 1`] = ` +Object { + "hot": true, + "hotOnly": false, + "https": true, + "key": "/path/to/server.key", + "noInfo": true, + "port": 8080, + "publicPath": "/", + "stats": Object { + "cached": false, + "cachedAssets": false, + }, +} +`; + exports[`createConfig lazy option (in devServer config) 1`] = ` Object { "hot": true, @@ -623,6 +719,38 @@ Object { } `; +exports[`createConfig pfx option (in devServer config) 1`] = ` +Object { + "hot": true, + "hotOnly": false, + "https": true, + "noInfo": true, + "pfx": "/path/to/file.pfx", + "port": 8080, + "publicPath": "/", + "stats": Object { + "cached": false, + "cachedAssets": false, + }, +} +`; + +exports[`createConfig pfx option 1`] = ` +Object { + "hot": true, + "hotOnly": false, + "https": true, + "noInfo": true, + "pfx": "/path/to/file.pfx", + "port": 8080, + "publicPath": "/", + "stats": Object { + "cached": false, + "cachedAssets": false, + }, +} +`; + exports[`createConfig pfxPassphrase option 1`] = ` Object { "hot": true,