mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-14 07:24:52 +09:00
Add users, roles and permissions and rework the authentication to use separate user and slave tokens for control and slave connections respectively. Add commands for listing permissions, roles and users, and creating, editing and deleting roles and users.
51 lines
1.7 KiB
JavaScript
51 lines
1.7 KiB
JavaScript
const assert = require("assert").strict;
|
|
const events = require("events");
|
|
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 control;
|
|
let controlConnector;
|
|
it("should emitt an error if authentication failed", async function() {
|
|
controlConnector = new TestControlConnector(url, 0.2);
|
|
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);
|
|
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");
|
|
});
|
|
});
|