Skip to content

Commit

Permalink
fix: improve https CLI output (#3673)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored Aug 18, 2021
1 parent 0277c5e commit f2d87fb
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 19 deletions.
14 changes: 8 additions & 6 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ class Server {
const del = require("del");

this.logger.info(
"SSL Certificate is more than 30 days old. Removing."
"SSL Certificate is more than 30 days old. Removing..."
);

del.sync([certificatePath], { force: true });
Expand All @@ -339,7 +339,7 @@ class Server {
}

if (!certificateExists) {
this.logger.info("Generating SSL Certificate");
this.logger.info("Generating SSL Certificate...");

const selfsigned = require("selfsigned");
const attributes = [{ name: "commonName", value: "localhost" }];
Expand All @@ -348,10 +348,10 @@ class Server {
days: 30,
keySize: 2048,
extensions: [
// {
// name: 'basicConstraints',
// cA: true,
// },
{
name: "basicConstraints",
cA: true,
},
{
name: "keyUsage",
keyCertSign: true,
Expand Down Expand Up @@ -412,6 +412,8 @@ class Server {
}

fakeCert = fs.readFileSync(certificatePath);

this.logger.info(`SSL certificate: ${certificatePath}`);
}

options.https.key = options.https.key || fakeCert;
Expand Down
4 changes: 3 additions & 1 deletion test/cli/__snapshots__/bonjour-option.test.js.snap.webpack4
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`"bonjour" CLI option should work using "--bonjour and --https" 1`] = `
"<i> [webpack-dev-server] Project is running at:
"<i> [webpack-dev-server] Generating SSL Certificate...
<i> [webpack-dev-server] SSL certificate: <cwd>/node_modules/.cache/webpack-dev-server/server.pem
<i> [webpack-dev-server] Project is running at:
<i> [webpack-dev-server] Loopback: https://localhost:<port>/
<i> [webpack-dev-server] On Your Network (IPv4): https://<ip-v4>:<port>/
<i> [webpack-dev-server] On Your Network (IPv6): https://[<ip-v6>]:<port>/
Expand Down
4 changes: 3 additions & 1 deletion test/cli/__snapshots__/bonjour-option.test.js.snap.webpack5
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`"bonjour" CLI option should work using "--bonjour and --https" 1`] = `
"<i> [webpack-dev-server] Project is running at:
"<i> [webpack-dev-server] Generating SSL Certificate...
<i> [webpack-dev-server] SSL certificate: <cwd>/node_modules/.cache/webpack-dev-server/server.pem
<i> [webpack-dev-server] Project is running at:
<i> [webpack-dev-server] Loopback: https://localhost:<port>/
<i> [webpack-dev-server] On Your Network (IPv4): https://<ip-v4>:<port>/
<i> [webpack-dev-server] On Your Network (IPv6): https://[<ip-v6>]:<port>/
Expand Down
4 changes: 3 additions & 1 deletion test/cli/__snapshots__/http2-option.test.js.snap.webpack4
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`"http2" CLI option should work using "--http2" 1`] = `
"<i> [webpack-dev-server] Project is running at:
"<i> [webpack-dev-server] Generating SSL Certificate...
<i> [webpack-dev-server] SSL certificate: <cwd>/node_modules/.cache/webpack-dev-server/server.pem
<i> [webpack-dev-server] Project is running at:
<i> [webpack-dev-server] Loopback: https://localhost:<port>/
<i> [webpack-dev-server] On Your Network (IPv4): https://<ip-v4>:<port>/
<i> [webpack-dev-server] On Your Network (IPv6): https://[<ip-v6>]:<port>/
Expand Down
4 changes: 3 additions & 1 deletion test/cli/__snapshots__/http2-option.test.js.snap.webpack5
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`"http2" CLI option should work using "--http2" 1`] = `
"<i> [webpack-dev-server] Project is running at:
"<i> [webpack-dev-server] Generating SSL Certificate...
<i> [webpack-dev-server] SSL certificate: <cwd>/node_modules/.cache/webpack-dev-server/server.pem
<i> [webpack-dev-server] Project is running at:
<i> [webpack-dev-server] Loopback: https://localhost:<port>/
<i> [webpack-dev-server] On Your Network (IPv4): https://<ip-v4>:<port>/
<i> [webpack-dev-server] On Your Network (IPv6): https://[<ip-v6>]:<port>/
Expand Down
12 changes: 9 additions & 3 deletions test/cli/__snapshots__/https-option.test.js.snap.webpack4
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`"https" CLI option should work using "--https" 1`] = `
"<i> [webpack-dev-server] Project is running at:
"<i> [webpack-dev-server] Generating SSL Certificate...
<i> [webpack-dev-server] SSL certificate: <cwd>/node_modules/.cache/webpack-dev-server/server.pem
<i> [webpack-dev-server] Project is running at:
<i> [webpack-dev-server] Loopback: https://localhost:<port>/
<i> [webpack-dev-server] On Your Network (IPv4): https://<ip-v4>:<port>/
<i> [webpack-dev-server] On Your Network (IPv6): https://[<ip-v6>]:<port>/
Expand All @@ -25,7 +27,9 @@ exports[`"https" CLI option should work using "--https-key <path> --https-pfx <p
`;

exports[`"https" CLI option should work using "--https-request-cert" 1`] = `
"<i> [webpack-dev-server] Project is running at:
"<i> [webpack-dev-server] Generating SSL Certificate...
<i> [webpack-dev-server] SSL certificate: <cwd>/node_modules/.cache/webpack-dev-server/server.pem
<i> [webpack-dev-server] Project is running at:
<i> [webpack-dev-server] Loopback: https://localhost:<port>/
<i> [webpack-dev-server] On Your Network (IPv4): https://<ip-v4>:<port>/
<i> [webpack-dev-server] On Your Network (IPv6): https://[<ip-v6>]:<port>/
Expand All @@ -41,7 +45,9 @@ exports[`"https" CLI option should work using "--no-https" 1`] = `
`;

exports[`"https" CLI option should work using "--no-https-request-cert" 1`] = `
"<i> [webpack-dev-server] Project is running at:
"<i> [webpack-dev-server] Generating SSL Certificate...
<i> [webpack-dev-server] SSL certificate: <cwd>/node_modules/.cache/webpack-dev-server/server.pem
<i> [webpack-dev-server] Project is running at:
<i> [webpack-dev-server] Loopback: https://localhost:<port>/
<i> [webpack-dev-server] On Your Network (IPv4): https://<ip-v4>:<port>/
<i> [webpack-dev-server] On Your Network (IPv6): https://[<ip-v6>]:<port>/
Expand Down
12 changes: 9 additions & 3 deletions test/cli/__snapshots__/https-option.test.js.snap.webpack5
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`"https" CLI option should work using "--https" 1`] = `
"<i> [webpack-dev-server] Project is running at:
"<i> [webpack-dev-server] Generating SSL Certificate...
<i> [webpack-dev-server] SSL certificate: <cwd>/node_modules/.cache/webpack-dev-server/server.pem
<i> [webpack-dev-server] Project is running at:
<i> [webpack-dev-server] Loopback: https://localhost:<port>/
<i> [webpack-dev-server] On Your Network (IPv4): https://<ip-v4>:<port>/
<i> [webpack-dev-server] On Your Network (IPv6): https://[<ip-v6>]:<port>/
Expand All @@ -25,7 +27,9 @@ exports[`"https" CLI option should work using "--https-key <path> --https-pfx <p
`;

exports[`"https" CLI option should work using "--https-request-cert" 1`] = `
"<i> [webpack-dev-server] Project is running at:
"<i> [webpack-dev-server] Generating SSL Certificate...
<i> [webpack-dev-server] SSL certificate: <cwd>/node_modules/.cache/webpack-dev-server/server.pem
<i> [webpack-dev-server] Project is running at:
<i> [webpack-dev-server] Loopback: https://localhost:<port>/
<i> [webpack-dev-server] On Your Network (IPv4): https://<ip-v4>:<port>/
<i> [webpack-dev-server] On Your Network (IPv6): https://[<ip-v6>]:<port>/
Expand All @@ -41,7 +45,9 @@ exports[`"https" CLI option should work using "--no-https" 1`] = `
`;

exports[`"https" CLI option should work using "--no-https-request-cert" 1`] = `
"<i> [webpack-dev-server] Project is running at:
"<i> [webpack-dev-server] Generating SSL Certificate...
<i> [webpack-dev-server] SSL certificate: <cwd>/node_modules/.cache/webpack-dev-server/server.pem
<i> [webpack-dev-server] Project is running at:
<i> [webpack-dev-server] Loopback: https://localhost:<port>/
<i> [webpack-dev-server] On Your Network (IPv4): https://<ip-v4>:<port>/
<i> [webpack-dev-server] On Your Network (IPv6): https://[<ip-v6>]:<port>/
Expand Down
8 changes: 8 additions & 0 deletions test/cli/bonjour-option.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
"use strict";

const del = require("del");
const Server = require("../../lib/Server");
const { testBin, normalizeStderr } = require("../helpers/test-bin");
const port = require("../ports-map")["cli-bonjour"];

const defaultCertificateDir = Server.findCacheDir();

describe('"bonjour" CLI option', () => {
beforeEach(async () => {
await del([defaultCertificateDir]);
});

it('should work using "--bonjour"', async () => {
const { exitCode, stderr } = await testBin(["--port", port, "--bonjour"]);

Expand Down
8 changes: 8 additions & 0 deletions test/cli/http2-option.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
"use strict";

const del = require("del");
const Server = require("../../lib/Server");
const { testBin, normalizeStderr } = require("../helpers/test-bin");
const port = require("../ports-map")["cli-http2"];

const defaultCertificateDir = Server.findCacheDir();

describe('"http2" CLI option', () => {
beforeEach(async () => {
await del([defaultCertificateDir]);
});

it('should work using "--http2"', async () => {
const { exitCode, stderr } = await testBin(["--port", port, "--http2"]);

Expand Down
8 changes: 8 additions & 0 deletions test/cli/https-option.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"use strict";

const path = require("path");
const del = require("del");
const Server = require("../../lib/Server");
const { testBin, normalizeStderr } = require("../helpers/test-bin");
const port = require("../ports-map")["cli-https"];

Expand All @@ -9,7 +11,13 @@ const httpsCertificateDirectory = path.resolve(
"../fixtures/https-certificate"
);

const defaultCertificateDir = Server.findCacheDir();

describe('"https" CLI option', () => {
beforeEach(async () => {
await del([defaultCertificateDir]);
});

it('should work using "--https"', async () => {
const { exitCode, stderr } = await testBin(["--port", port, "--https"]);

Expand Down
3 changes: 0 additions & 3 deletions test/helpers/test-bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ const normalizeStderr = (stderr, options = {}) => {
if (options.https) {
// We have deprecation warning on windows in some cases
normalizedStderr = normalizedStderr.split("\n");
normalizedStderr = normalizedStderr.filter(
(item) => !/Generating SSL Certificate/g.test(item)
);
normalizedStderr = normalizedStderr.filter(
(item) =>
!/DeprecationWarning: The legacy HTTP parser is deprecated/g.test(item)
Expand Down

0 comments on commit f2d87fb

Please sign in to comment.