mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-19 07:33:12 +09:00
Address review of host pairing
Revoking a host now unassigns its instances instead of being refused while it has any, and removes its system metrics. Approving and revoking no longer force a save. Hosts are saved by autosave and on exit like everything else, which also removes the approving state from pairing requests. The approval code and link are logged as warnings so they show up in the systemd service, which only prints warnings and above. The pairing limits are now the controller.host_pairing_timeout and controller.host_pairing_max_pending config values, 0 removes the limit. Subscribers take an optional permitted function, used for the pairing requests instead of overrides in a subclass.
This commit is contained in:
29 files changed
+356
-418
No files matched your search
+40
-1
@@ -162,6 +162,22 @@ describe("host/src/pairing", function() {
|
||||
stub = await startStub();
|
||||
});
|
||||
|
||||
it("keeps polling while the controller is busy", async function() {
|
||||
const handler = approveAfter(0);
|
||||
let busy = 2;
|
||||
stub.handler = entry => {
|
||||
if (entry.url === "/api/host-pairing/poll" && busy > 0) {
|
||||
busy -= 1;
|
||||
return [503, { error: "Recovery mode" }];
|
||||
}
|
||||
return handler(entry);
|
||||
};
|
||||
const retries = [];
|
||||
const result = await pair({ onRetry: err => { retries.push(err.message); } });
|
||||
assert.deepEqual(result, approved);
|
||||
assert.deepEqual(retries, ["Recovery mode", "Recovery mode"]);
|
||||
});
|
||||
|
||||
it("throws when the request is rejected", async function() {
|
||||
const handler = approveAfter(Infinity);
|
||||
stub.handler = entry => (entry.url === "/api/host-pairing/poll" && stub.requests.length > 2
|
||||
@@ -248,8 +264,17 @@ describe("host/src/pairing", function() {
|
||||
it("waits for approval and saves the host when not paired", async function() {
|
||||
this.timeout(5000); // Polls at the default interval of 2 seconds
|
||||
stub.handler = approveAfter(0);
|
||||
await ensurePaired(config, { version: "2.1.0" });
|
||||
const warnings = [];
|
||||
const originalWarn = lib.logger.warn;
|
||||
lib.logger.warn = message => { warnings.push(message); };
|
||||
try {
|
||||
await ensurePaired(config, { version: "2.1.0" });
|
||||
} finally {
|
||||
lib.logger.warn = originalWarn;
|
||||
}
|
||||
assert.deepEqual(stub.requests[0].body, { name: "My Host", version: "2.1.0" });
|
||||
// The systemd service created by the installer only prints warnings and above.
|
||||
assert(warnings.includes(`${stub.url}hosts?approve=ABC-DE1`), "approval link is not a warning");
|
||||
const saved = await savedConfig();
|
||||
assert.equal(saved["host.id"], 1234);
|
||||
assert.equal(saved["host.name"], "Approved");
|
||||
@@ -284,6 +309,20 @@ describe("host/src/pairing", function() {
|
||||
assert(!JSON.stringify(saved).includes("user-token"), "user token must not be saved");
|
||||
});
|
||||
|
||||
it("stops when aborted while checking the saved token", async function() {
|
||||
config.set("host.controller_token", "some-token");
|
||||
const abort = new AbortController();
|
||||
stub.handler = () => {
|
||||
abort.abort();
|
||||
return new Promise(() => {});
|
||||
};
|
||||
await assert.rejects(
|
||||
ensurePaired(config, { version: "2.1.0", signal: abort.signal }),
|
||||
{ name: "AbortError" },
|
||||
);
|
||||
assert.equal(config.get("host.controller_token"), "some-token");
|
||||
});
|
||||
|
||||
it("keeps the saved token when it can't be checked", async function() {
|
||||
config.set("host.controller_token", "some-token");
|
||||
stub.handler = () => [404, undefined];
|
||||
|
||||
Reference in new issue
Block a user