Skip to content

Commit 9bd6bc8

Browse files
authored
test: add more cases for https cli options (#3826)
1 parent 8d5b906 commit 9bd6bc8

File tree

3 files changed

+140
-0
lines changed

3 files changed

+140
-0
lines changed

test/cli/__snapshots__/https-option.test.js.snap.webpack4

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`"https" CLI option should warn using "--https-cacert" and "--https-ca" together 1`] = `
4+
"<w> [webpack-dev-server] Do not specify 'https.ca' and 'https.cacert' options together, the 'https.ca' option will be used.
5+
<i> [webpack-dev-server] Project is running at:
6+
<i> [webpack-dev-server] Loopback: https://localhost:<port>/
7+
<i> [webpack-dev-server] On Your Network (IPv4): https://<ip-v4>:<port>/
8+
<i> [webpack-dev-server] On Your Network (IPv6): https://[<ip-v6>]:<port>/
9+
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
10+
`;
11+
312
exports[`"https" CLI option should work using "--https" 1`] = `
413
"<i> [webpack-dev-server] SSL certificate: <cwd>/node_modules/.cache/webpack-dev-server/server.pem
514
<i> [webpack-dev-server] Project is running at:
@@ -9,6 +18,14 @@ exports[`"https" CLI option should work using "--https" 1`] = `
918
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
1019
`;
1120

21+
exports[`"https" CLI option should work using "--https-key <path> --https-pfx <path> --https-passphrase webpack-dev-server --https-cert <path> --https-ca <path>" 1`] = `
22+
"<i> [webpack-dev-server] Project is running at:
23+
<i> [webpack-dev-server] Loopback: https://localhost:<port>/
24+
<i> [webpack-dev-server] On Your Network (IPv4): https://<ip-v4>:<port>/
25+
<i> [webpack-dev-server] On Your Network (IPv6): https://[<ip-v6>]:<port>/
26+
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
27+
`;
28+
1229
exports[`"https" CLI option should work using "--https-key <path> --https-pfx <path> --https-passphrase webpack-dev-server --https-cert <path> --https-cacert <path>" 1`] = `
1330
"<i> [webpack-dev-server] Project is running at:
1431
<i> [webpack-dev-server] Loopback: https://localhost:<port>/
@@ -25,6 +42,14 @@ exports[`"https" CLI option should work using "--https-key <path> --https-pfx <p
2542
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
2643
`;
2744

45+
exports[`"https" CLI option should work using "--https-key-reset --https-key <path> --https-pfx-reset --https-pfx <path> --https-passphrase webpack-dev-server --https-cert-reset --https-cert <path> --https-ca-reset --https-ca <path>" 1`] = `
46+
"<i> [webpack-dev-server] Project is running at:
47+
<i> [webpack-dev-server] Loopback: https://localhost:<port>/
48+
<i> [webpack-dev-server] On Your Network (IPv4): https://<ip-v4>:<port>/
49+
<i> [webpack-dev-server] On Your Network (IPv6): https://[<ip-v6>]:<port>/
50+
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
51+
`;
52+
2853
exports[`"https" CLI option should work using "--https-request-cert" 1`] = `
2954
"<i> [webpack-dev-server] SSL certificate: <cwd>/node_modules/.cache/webpack-dev-server/server.pem
3055
<i> [webpack-dev-server] Project is running at:

test/cli/__snapshots__/https-option.test.js.snap.webpack5

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`"https" CLI option should warn using "--https-cacert" and "--https-ca" together 1`] = `
4+
"<w> [webpack-dev-server] Do not specify 'https.ca' and 'https.cacert' options together, the 'https.ca' option will be used.
5+
<i> [webpack-dev-server] Project is running at:
6+
<i> [webpack-dev-server] Loopback: https://localhost:<port>/
7+
<i> [webpack-dev-server] On Your Network (IPv4): https://<ip-v4>:<port>/
8+
<i> [webpack-dev-server] On Your Network (IPv6): https://[<ip-v6>]:<port>/
9+
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
10+
`;
11+
312
exports[`"https" CLI option should work using "--https" 1`] = `
413
"<i> [webpack-dev-server] SSL certificate: <cwd>/node_modules/.cache/webpack-dev-server/server.pem
514
<i> [webpack-dev-server] Project is running at:
@@ -9,6 +18,14 @@ exports[`"https" CLI option should work using "--https" 1`] = `
918
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
1019
`;
1120

21+
exports[`"https" CLI option should work using "--https-key <path> --https-pfx <path> --https-passphrase webpack-dev-server --https-cert <path> --https-ca <path>" 1`] = `
22+
"<i> [webpack-dev-server] Project is running at:
23+
<i> [webpack-dev-server] Loopback: https://localhost:<port>/
24+
<i> [webpack-dev-server] On Your Network (IPv4): https://<ip-v4>:<port>/
25+
<i> [webpack-dev-server] On Your Network (IPv6): https://[<ip-v6>]:<port>/
26+
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
27+
`;
28+
1229
exports[`"https" CLI option should work using "--https-key <path> --https-pfx <path> --https-passphrase webpack-dev-server --https-cert <path> --https-cacert <path>" 1`] = `
1330
"<i> [webpack-dev-server] Project is running at:
1431
<i> [webpack-dev-server] Loopback: https://localhost:<port>/
@@ -25,6 +42,14 @@ exports[`"https" CLI option should work using "--https-key <path> --https-pfx <p
2542
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
2643
`;
2744

45+
exports[`"https" CLI option should work using "--https-key-reset --https-key <path> --https-pfx-reset --https-pfx <path> --https-passphrase webpack-dev-server --https-cert-reset --https-cert <path> --https-ca-reset --https-ca <path>" 1`] = `
46+
"<i> [webpack-dev-server] Project is running at:
47+
<i> [webpack-dev-server] Loopback: https://localhost:<port>/
48+
<i> [webpack-dev-server] On Your Network (IPv4): https://<ip-v4>:<port>/
49+
<i> [webpack-dev-server] On Your Network (IPv6): https://[<ip-v6>]:<port>/
50+
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
51+
`;
52+
2853
exports[`"https" CLI option should work using "--https-request-cert" 1`] = `
2954
"<i> [webpack-dev-server] SSL certificate: <cwd>/node_modules/.cache/webpack-dev-server/server.pem
3055
<i> [webpack-dev-server] Project is running at:

test/cli/https-option.test.js

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,96 @@ describe('"https" CLI option', () => {
5555
).toMatchSnapshot();
5656
});
5757

58+
it('should work using "--https-key <path> --https-pfx <path> --https-passphrase webpack-dev-server --https-cert <path> --https-ca <path>"', async () => {
59+
const pfxFile = path.join(httpsCertificateDirectory, "server.pfx");
60+
const key = path.join(httpsCertificateDirectory, "server.key");
61+
const cert = path.join(httpsCertificateDirectory, "server.crt");
62+
const ca = path.join(httpsCertificateDirectory, "ca.pem");
63+
const passphrase = "webpack-dev-server";
64+
65+
const { exitCode, stderr } = await testBin([
66+
"--port",
67+
port,
68+
"--https-key",
69+
key,
70+
"--https-pfx",
71+
pfxFile,
72+
"--https-passphrase",
73+
passphrase,
74+
"--https-cert",
75+
cert,
76+
"--https-ca",
77+
ca,
78+
]);
79+
80+
expect(exitCode).toEqual(0);
81+
expect(
82+
normalizeStderr(stderr, { ipv6: true, https: true })
83+
).toMatchSnapshot();
84+
});
85+
86+
it('should work using "--https-key-reset --https-key <path> --https-pfx-reset --https-pfx <path> --https-passphrase webpack-dev-server --https-cert-reset --https-cert <path> --https-ca-reset --https-ca <path>"', async () => {
87+
const pfxFile = path.join(httpsCertificateDirectory, "server.pfx");
88+
const key = path.join(httpsCertificateDirectory, "server.key");
89+
const cert = path.join(httpsCertificateDirectory, "server.crt");
90+
const ca = path.join(httpsCertificateDirectory, "ca.pem");
91+
const passphrase = "webpack-dev-server";
92+
93+
const { exitCode, stderr } = await testBin([
94+
"--port",
95+
port,
96+
"--https-key-reset",
97+
"--https-key",
98+
key,
99+
"--https-pfx-reset",
100+
"--https-pfx",
101+
pfxFile,
102+
"--https-passphrase",
103+
passphrase,
104+
"--https-cert-reset",
105+
"--https-cert",
106+
cert,
107+
"--https-ca-reset",
108+
"--https-ca",
109+
ca,
110+
]);
111+
112+
expect(exitCode).toEqual(0);
113+
expect(
114+
normalizeStderr(stderr, { ipv6: true, https: true })
115+
).toMatchSnapshot();
116+
});
117+
118+
it('should warn using "--https-cacert" and "--https-ca" together', async () => {
119+
const pfxFile = path.join(httpsCertificateDirectory, "server.pfx");
120+
const key = path.join(httpsCertificateDirectory, "server.key");
121+
const cert = path.join(httpsCertificateDirectory, "server.crt");
122+
const cacert = path.join(httpsCertificateDirectory, "ca.pem");
123+
const passphrase = "webpack-dev-server";
124+
125+
const { exitCode, stderr } = await testBin([
126+
"--port",
127+
port,
128+
"--https-key",
129+
key,
130+
"--https-pfx",
131+
pfxFile,
132+
"--https-passphrase",
133+
passphrase,
134+
"--https-cert",
135+
cert,
136+
"--https-cacert",
137+
cacert,
138+
"--https-ca",
139+
cacert,
140+
]);
141+
142+
expect(exitCode).toEqual(0);
143+
expect(
144+
normalizeStderr(stderr, { ipv6: true, https: true })
145+
).toMatchSnapshot();
146+
});
147+
58148
// For https://github.com/webpack/webpack-dev-server/issues/3306
59149
it('should work using "--https-key <path> --https-pfx <path> --https-passphrase webpack-dev-server --https-cert <path>"', async () => {
60150
const pfxFile = path.join(httpsCertificateDirectory, "server.pfx");

0 commit comments

Comments
 (0)