mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-12 15:04:52 +09:00
The automatic creation of a self-signed certificate while nice presents several problems. To make connections not reject the self-signed certificate the validation of TLS certificates are wholesale disabled, decreasing the security even when properly set up and trusted certificates are used. To make the created self-signed certificate pass validation it is necessary for it to list the host names it's valid for and to copy it to each machine that intends to connect to the server. These two steps complicate automating the process in a reliable way and will likely lead to confused users seeking to disable TLS certificate validation as the easy way out to problems. For these reasons, remove the automating creation of a broke self-signed certificate, fix validation of certificates and document how to set up TLS properly. This makes HTTPS recommended when accessing over the internet, but still something which must be explicitly configured.
57 lines
1.8 KiB
JavaScript
57 lines
1.8 KiB
JavaScript
"use strict";
|
|
const assert = require("assert").strict;
|
|
const events = require("events");
|
|
const fs = require("fs-extra");
|
|
const jwt = require("jsonwebtoken");
|
|
|
|
const { TestControlConnector, TestControl, get, exec, url } = require("./index");
|
|
|
|
let token = jwt.sign({ aud: "user", user: "test" }, "TestSecretDoNotUse");
|
|
|
|
describe("Integration of lib/link", function() {
|
|
let tlsCa;
|
|
let control;
|
|
let controlConnector;
|
|
before(async function() {
|
|
tlsCa = await fs.readFile("test/file/tls/cert.pem");
|
|
});
|
|
it("should emitt an error if authentication failed", async function() {
|
|
controlConnector = new TestControlConnector(url, 0.2, tlsCa);
|
|
controlConnector.token = "gibberish";
|
|
control = new TestControl(controlConnector);
|
|
await assert.rejects(
|
|
controlConnector.connect(),
|
|
new Error("Authentication failed: jwt malformed")
|
|
);
|
|
});
|
|
|
|
it("should connect with proper credentials", async function() {
|
|
controlConnector = new TestControlConnector(url, 0.2, tlsCa);
|
|
controlConnector.token = token;
|
|
control = new TestControl(controlConnector);
|
|
await controlConnector.connect();
|
|
});
|
|
|
|
it("should reconnect on connection lost", async function() {
|
|
controlConnector._socket.close(1008, "Test");
|
|
await events.once(controlConnector, "connect");
|
|
});
|
|
|
|
it("should reconnect on connection terminated", async function() {
|
|
controlConnector._socket.terminate();
|
|
await events.once(controlConnector, "connect");
|
|
});
|
|
|
|
it("should reconnect on connection heartbeat timeout", async function() {
|
|
controlConnector.stopHeartbeat();
|
|
await events.once(controlConnector, "connect");
|
|
});
|
|
|
|
it("should invalidate on reconnection with bad session token", async function() {
|
|
controlConnector._sessionToken = "blah";
|
|
controlConnector.stopHeartbeat();
|
|
await events.once(controlConnector, "invalidate");
|
|
await events.once(controlConnector, "connect");
|
|
});
|
|
});
|