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(regression): handle key, cert, cacert and pfx in CLI #1688

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/utils/createConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
89 changes: 89 additions & 0 deletions test/CreateConfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
128 changes: 128 additions & 0 deletions test/__snapshots__/CreateConfig.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down