Skip to content

Commit 48bdd06

Browse files
committed
[FIX] serve: Create SSL certificate in user homedir
The default certificate key/cert paths were using the $HOME variable which was not replaced with the actual homedir of the user. This caused creating a "$HOME" folder within the project which was not intended. Furthermore this can be dangerous in case someone wants to remove that folder with `rm -rf`, as this might cause the homedir to be removed in case no single quotes are used.
1 parent b3d0d16 commit 48bdd06

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

lib/cli/commands/serve.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
const path = require("path");
2+
const os = require("os");
3+
14
// Serve
25
const serve = {
36
command: "serve",
@@ -29,12 +32,12 @@ serve.builder = function(cli) {
2932
})
3033
.option("key", {
3134
describe: "Path to the private key",
32-
default: "$HOME/.ui5/server/server.key",
35+
default: path.join(os.homedir(), ".ui5", "server", "server.key"),
3336
type: "string"
3437
})
3538
.option("cert", {
3639
describe: "Path to the certificate",
37-
default: "$HOME/.ui5/server/server.crt",
40+
default: path.join(os.homedir(), ".ui5", "server", "server.crt"),
3841
type: "string"
3942
})
4043
.option("sap-csp-policies", {

test/lib/cli/commands/serve.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
const test = require("ava");
22
const sinon = require("sinon");
3+
const path = require("path");
4+
const os = require("os");
35
const normalizer = require("@ui5/project").normalizer;
46
const serve = require("../../../../lib/cli/commands/serve");
57
const ui5Server = require("@ui5/server");
68
const server = ui5Server.server;
79
const mockRequire = require("mock-require");
810
const defaultInitialHandlerArgs = Object.freeze({
911
accessRemoteConnections: false,
10-
cert: "$HOME/.ui5/server/server.crt",
12+
cert: path.join(os.homedir(), ".ui5", "server", "server.crt"),
1113
h2: false,
12-
key: "$HOME/.ui5/server/server.key",
14+
key: path.join(os.homedir(), ".ui5", "server", "server.key"),
1315
loglevel: "info",
1416
t8r: "npm",
1517
translator: "npm"
@@ -81,8 +83,8 @@ test.serial("ui5 serve --h2", async (t) => {
8183
const injectedProjectTree = serverStub.getCall(0).args[0];
8284
const injectedServerConfig = serverStub.getCall(0).args[1];
8385

84-
t.is(sslUtilStub.getCall(0).args[0], "$HOME/.ui5/server/server.key", "Load ssl key from default path");
85-
t.is(sslUtilStub.getCall(0).args[1], "$HOME/.ui5/server/server.crt", "Load ssl cert from default path");
86+
t.is(sslUtilStub.getCall(0).args[0], path.join(os.homedir(), ".ui5", "server", "server.key"), "Load ssl key from default path");
87+
t.is(sslUtilStub.getCall(0).args[1], path.join(os.homedir(), ".ui5", "server", "server.crt"), "Load ssl cert from default path");
8688
t.deepEqual(injectedProjectTree, projectTree, "Starting server with given project tree");
8789
t.is(injectedServerConfig.port === 8443, true, "http2 default port was auto set");
8890

0 commit comments

Comments
 (0)