Skip to content

Commit 4b2076c

Browse files
fix(regression): handle key, cert, cacert and pfx in CLI (#1688)
1 parent 21687c3 commit 4b2076c

File tree

3 files changed

+233
-0
lines changed

3 files changed

+233
-0
lines changed

lib/utils/createConfig.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,22 @@ function createConfig(config, argv, { port }) {
136136
options.https = true;
137137
}
138138

139+
if (argv.key) {
140+
options.key = argv.key;
141+
}
142+
143+
if (argv.cert) {
144+
options.cert = argv.cert;
145+
}
146+
147+
if (argv.cacert) {
148+
options.ca = argv.cacert;
149+
}
150+
151+
if (argv.pfx) {
152+
options.pfx = argv.pfx;
153+
}
154+
139155
if (argv.pfxPassphrase) {
140156
options.pfxPassphrase = argv.pfxPassphrase;
141157
}

test/CreateConfig.test.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,95 @@ describe('createConfig', () => {
559559
expect(config).toMatchSnapshot();
560560
});
561561

562+
it('key option', () => {
563+
const config = createConfig(
564+
webpackConfig,
565+
Object.assign({}, argv, { https: true, key: '/path/to/server.key' }),
566+
{ port: 8080 }
567+
);
568+
569+
expect(config).toMatchSnapshot();
570+
});
571+
572+
it('key option (in devServer config)', () => {
573+
const config = createConfig(
574+
Object.assign({}, webpackConfig, {
575+
devServer: { https: true, key: '/path/to/server.key' },
576+
}),
577+
argv,
578+
{ port: 8080 }
579+
);
580+
581+
expect(config).toMatchSnapshot();
582+
});
583+
584+
it('cert option', () => {
585+
const config = createConfig(
586+
webpackConfig,
587+
Object.assign({}, argv, { https: true, cert: '/path/to/server.crt' }),
588+
{ port: 8080 }
589+
);
590+
591+
expect(config).toMatchSnapshot();
592+
});
593+
594+
it('cert option (in devServer config)', () => {
595+
const config = createConfig(
596+
Object.assign({}, webpackConfig, {
597+
devServer: { https: true, cert: '/path/to/server.crt' },
598+
}),
599+
argv,
600+
{ port: 8080 }
601+
);
602+
603+
expect(config).toMatchSnapshot();
604+
});
605+
606+
it('cacert option', () => {
607+
const config = createConfig(
608+
webpackConfig,
609+
Object.assign({}, argv, { https: true, cacert: '/path/to/ca.pem' }),
610+
{ port: 8080 }
611+
);
612+
613+
expect(config).toMatchSnapshot();
614+
});
615+
616+
it('cacert option (in devServer config)', () => {
617+
const config = createConfig(
618+
Object.assign({}, webpackConfig, {
619+
// TODO rename `ca` to `cacert` for `v4` to avoid difference between CLI and configuration
620+
devServer: { https: true, ca: '/path/to/ca.pem' },
621+
}),
622+
argv,
623+
{ port: 8080 }
624+
);
625+
626+
expect(config).toMatchSnapshot();
627+
});
628+
629+
it('pfx option', () => {
630+
const config = createConfig(
631+
webpackConfig,
632+
Object.assign({}, argv, { https: true, pfx: '/path/to/file.pfx' }),
633+
{ port: 8080 }
634+
);
635+
636+
expect(config).toMatchSnapshot();
637+
});
638+
639+
it('pfx option (in devServer config)', () => {
640+
const config = createConfig(
641+
Object.assign({}, webpackConfig, {
642+
devServer: { https: true, pfx: '/path/to/file.pfx' },
643+
}),
644+
argv,
645+
{ port: 8080 }
646+
);
647+
648+
expect(config).toMatchSnapshot();
649+
});
650+
562651
it('pfxPassphrase option', () => {
563652
const config = createConfig(
564653
webpackConfig,

test/__snapshots__/CreateConfig.test.js.snap

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,70 @@ Object {
6666
}
6767
`;
6868

69+
exports[`createConfig cacert option (in devServer config) 1`] = `
70+
Object {
71+
"ca": "/path/to/ca.pem",
72+
"hot": true,
73+
"hotOnly": false,
74+
"https": true,
75+
"noInfo": true,
76+
"port": 8080,
77+
"publicPath": "/",
78+
"stats": Object {
79+
"cached": false,
80+
"cachedAssets": false,
81+
},
82+
}
83+
`;
84+
85+
exports[`createConfig cacert option 1`] = `
86+
Object {
87+
"ca": "/path/to/ca.pem",
88+
"hot": true,
89+
"hotOnly": false,
90+
"https": true,
91+
"noInfo": true,
92+
"port": 8080,
93+
"publicPath": "/",
94+
"stats": Object {
95+
"cached": false,
96+
"cachedAssets": false,
97+
},
98+
}
99+
`;
100+
101+
exports[`createConfig cert option (in devServer config) 1`] = `
102+
Object {
103+
"cert": "/path/to/server.crt",
104+
"hot": true,
105+
"hotOnly": false,
106+
"https": true,
107+
"noInfo": true,
108+
"port": 8080,
109+
"publicPath": "/",
110+
"stats": Object {
111+
"cached": false,
112+
"cachedAssets": false,
113+
},
114+
}
115+
`;
116+
117+
exports[`createConfig cert option 1`] = `
118+
Object {
119+
"cert": "/path/to/server.crt",
120+
"hot": true,
121+
"hotOnly": false,
122+
"https": true,
123+
"noInfo": true,
124+
"port": 8080,
125+
"publicPath": "/",
126+
"stats": Object {
127+
"cached": false,
128+
"cachedAssets": false,
129+
},
130+
}
131+
`;
132+
69133
exports[`createConfig clientLogLevel option (in devServer config) 1`] = `
70134
Object {
71135
"clientLogLevel": "none",
@@ -513,6 +577,38 @@ Object {
513577
}
514578
`;
515579

580+
exports[`createConfig key option (in devServer config) 1`] = `
581+
Object {
582+
"hot": true,
583+
"hotOnly": false,
584+
"https": true,
585+
"key": "/path/to/server.key",
586+
"noInfo": true,
587+
"port": 8080,
588+
"publicPath": "/",
589+
"stats": Object {
590+
"cached": false,
591+
"cachedAssets": false,
592+
},
593+
}
594+
`;
595+
596+
exports[`createConfig key option 1`] = `
597+
Object {
598+
"hot": true,
599+
"hotOnly": false,
600+
"https": true,
601+
"key": "/path/to/server.key",
602+
"noInfo": true,
603+
"port": 8080,
604+
"publicPath": "/",
605+
"stats": Object {
606+
"cached": false,
607+
"cachedAssets": false,
608+
},
609+
}
610+
`;
611+
516612
exports[`createConfig lazy option (in devServer config) 1`] = `
517613
Object {
518614
"hot": true,
@@ -623,6 +719,38 @@ Object {
623719
}
624720
`;
625721

722+
exports[`createConfig pfx option (in devServer config) 1`] = `
723+
Object {
724+
"hot": true,
725+
"hotOnly": false,
726+
"https": true,
727+
"noInfo": true,
728+
"pfx": "/path/to/file.pfx",
729+
"port": 8080,
730+
"publicPath": "/",
731+
"stats": Object {
732+
"cached": false,
733+
"cachedAssets": false,
734+
},
735+
}
736+
`;
737+
738+
exports[`createConfig pfx option 1`] = `
739+
Object {
740+
"hot": true,
741+
"hotOnly": false,
742+
"https": true,
743+
"noInfo": true,
744+
"pfx": "/path/to/file.pfx",
745+
"port": 8080,
746+
"publicPath": "/",
747+
"stats": Object {
748+
"cached": false,
749+
"cachedAssets": false,
750+
},
751+
}
752+
`;
753+
626754
exports[`createConfig pfxPassphrase option 1`] = `
627755
Object {
628756
"hot": true,

0 commit comments

Comments
 (0)