mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-11-01 08:05:23 +00:00
v26.10.3 (#1692)
* feat: shell controller, TabStage, layout and theme plugins with repair view * feat: move the classic layout into its own bundled plugin * feat: move color themes into a bundled themes plugin * fix: plugin tests and type checks work with a linked sdk * fix: home tab, layout switch and missing layout fallbacks for looks * chore: add classic layout and themes to the readme * chore: drop example plugin links from the plugin guide * feat: plugin filters by type, paged browse, hide plugins needing newer termix * feat: move desktop, status, import, audit and branding features into plugins * feat: host lock api so a plugin can load hosts from a config file (#1581) * chore: add hosts config to the plugin table * feat: login policy hook for plugins and optional https redirect (#1584) * chore: add login security to the plugin table * feat: api key socket tickets so a master can open remote sessions (#1654) * feat: sync moves to a plugin, desktop gets multiple accounts (#1580, #1654) * chore: add sync to the plugin table * feat: move the sync screens and wizard out of core into the plugin (#1580) * fix: add a neutral linked desktop hook for plugins (#1580) * fix: show the linked account's name and admin flag in the app (#1580) * feat: ssh transport providers, core ssh relay and plugin folders api * feat: support FIDO2 security keys through ssh agent * feat: add companion panels beside host tabs * feat: mTLS client certificates for desktop server links * feat: native web view for plugins in the desktop app * fix: detect the desktop link window by Electron's default user agent Fixes #1675 * fix: changelog for desktop link fix * fix: keep text primary keys in the plugin data export * fix: ship sharp binaries for Windows arm64 builds * feat: client cert on the sync link types (sdk 1.0.18) * chore: update translations * feat: themed title bar for the desktop app (#1690) * chore: changelog for the themed title bar * fix: draw the title bar in the sidebar color * feat: per host layout for the terminal panel bar * chore: sdk 1.0.19 for the panel bar layout * chore: bundle all 43 plugins for 26.10.3 * chore: update translations --------- Co-authored-by: SirHephaistos <60616553+SirHephaistos@users.noreply.github.com> Co-authored-by: Giovanny Aranda <garanda21@gmail.com>
This commit is contained in:
577 files changed
+76479
-101831
No files matched your search
@@ -1,5 +1,4 @@
|
||||
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import sharp from "sharp";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import express, {
|
||||
type NextFunction,
|
||||
type Request,
|
||||
@@ -19,15 +18,6 @@ vi.mock("../../../utils/logger.js", () => ({
|
||||
vi.mock("../../../database/repositories/factory.js", () => ({
|
||||
createCurrentSettingsRepository: () => ({
|
||||
get: async (key: string) => state.settings[key] ?? null,
|
||||
set: async (key: string, value: string) => {
|
||||
state.settings[key] = value;
|
||||
},
|
||||
setMany: async (writes: Array<{ key: string; value: string }>) => {
|
||||
for (const write of writes) state.settings[write.key] = write.value;
|
||||
},
|
||||
delete: async (key: string) => {
|
||||
delete state.settings[key];
|
||||
},
|
||||
}),
|
||||
}));
|
||||
|
||||
@@ -42,25 +32,17 @@ interface RouteLayer {
|
||||
};
|
||||
}
|
||||
|
||||
/** Runs a route's full middleware chain (e.g. requireAdmin, then the handler). */
|
||||
function handlersFor(
|
||||
router: express.Router,
|
||||
pathName: string,
|
||||
method: string,
|
||||
): RequestHandler[] {
|
||||
const layer = (router as unknown as { stack: RouteLayer[] }).stack.find(
|
||||
(candidate) =>
|
||||
candidate.route?.path === pathName && candidate.route.methods[method],
|
||||
);
|
||||
if (!layer) throw new Error(`Route not registered: ${method} ${pathName}`);
|
||||
return layer.route!.stack.map((entry) => entry.handle);
|
||||
function routesOf(router: express.Router) {
|
||||
return (router as unknown as { stack: RouteLayer[] }).stack
|
||||
.filter((layer) => layer.route)
|
||||
.map((layer) => ({
|
||||
path: layer.route!.path,
|
||||
methods: Object.keys(layer.route!.methods),
|
||||
handlers: layer.route!.stack.map((entry) => entry.handle),
|
||||
}));
|
||||
}
|
||||
|
||||
async function invokeChain(
|
||||
handlers: RequestHandler[],
|
||||
body: unknown = {},
|
||||
): Promise<{ statusCode: number; body: unknown }> {
|
||||
const req = { body, headers: {} } as unknown as Request;
|
||||
async function call(handler: RequestHandler) {
|
||||
const result = { statusCode: 200, body: null as unknown };
|
||||
const res = {
|
||||
status(code: number) {
|
||||
@@ -72,67 +54,34 @@ async function invokeChain(
|
||||
return this;
|
||||
},
|
||||
} as unknown as Response;
|
||||
|
||||
for (const handler of handlers) {
|
||||
let proceeded = false;
|
||||
await handler(req, res, ((err?: unknown) => {
|
||||
if (err) throw err;
|
||||
proceeded = true;
|
||||
}) as NextFunction);
|
||||
if (!proceeded) return result;
|
||||
}
|
||||
await handler(
|
||||
{ body: {}, headers: {} } as Request,
|
||||
res,
|
||||
(() => {}) as NextFunction,
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Mimics the real requireAdmin: 401 with no session, 403 for a non-admin. */
|
||||
function fakeRequireAdmin(
|
||||
outcome: "unauthenticated" | "not-admin" | "admin",
|
||||
): RequestHandler {
|
||||
return (_req, res, next) => {
|
||||
if (outcome === "unauthenticated") {
|
||||
res.status(401).json({ error: "Missing authentication token" });
|
||||
return;
|
||||
}
|
||||
if (outcome === "not-admin") {
|
||||
res.status(403).json({ error: "Not authorized" });
|
||||
return;
|
||||
}
|
||||
// Must return (not just call) next() so invokeChain's await actually
|
||||
// waits for the downstream async handler to finish before returning.
|
||||
return next();
|
||||
};
|
||||
}
|
||||
|
||||
function buildRouter(requireAdmin: RequestHandler) {
|
||||
const router = express.Router();
|
||||
registerBrandingRoutes(router, requireAdmin);
|
||||
return router;
|
||||
}
|
||||
|
||||
let pngDataUrl: string;
|
||||
|
||||
beforeAll(async () => {
|
||||
const buffer = await sharp({
|
||||
create: { width: 4, height: 4, channels: 3, background: "#112233" },
|
||||
})
|
||||
.png()
|
||||
.toBuffer();
|
||||
pngDataUrl = `data:image/png;base64,${buffer.toString("base64")}`;
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
state.settings = {};
|
||||
});
|
||||
|
||||
describe("GET /users/branding", () => {
|
||||
it("succeeds with no auth at all, since the route registers no auth handler", async () => {
|
||||
// requireAdmin is only ever wired onto PATCH below; GET's own handler chain
|
||||
// has exactly one entry, proving the public route never runs an admin gate.
|
||||
const router = buildRouter(fakeRequireAdmin("unauthenticated"));
|
||||
const handlers = handlersFor(router, "/branding", "get");
|
||||
expect(handlers).toHaveLength(1);
|
||||
it("is the only branding route and has no auth handler", () => {
|
||||
const router = express.Router();
|
||||
registerBrandingRoutes(router);
|
||||
const routes = routesOf(router);
|
||||
|
||||
const response = await invokeChain(handlers);
|
||||
expect(routes).toHaveLength(1);
|
||||
expect(routes[0].path).toBe("/branding");
|
||||
expect(routes[0].methods).toEqual(["get"]);
|
||||
expect(routes[0].handlers).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("answers defaults when nothing is set", async () => {
|
||||
const router = express.Router();
|
||||
registerBrandingRoutes(router);
|
||||
const response = await call(routesOf(router)[0].handlers[0]);
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.body).toEqual({
|
||||
@@ -142,126 +91,19 @@ describe("GET /users/branding", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("reflects persisted branding values", async () => {
|
||||
state.settings.branding_app_name = "Acme Ops";
|
||||
state.settings.branding_tagline = "Ship it";
|
||||
state.settings.branding_logo = pngDataUrl;
|
||||
const router = buildRouter(fakeRequireAdmin("admin"));
|
||||
it("keeps serving the stored branding of an older install", async () => {
|
||||
state.settings = {
|
||||
branding_app_name: "Acme",
|
||||
branding_tagline: "Ops",
|
||||
};
|
||||
const router = express.Router();
|
||||
registerBrandingRoutes(router);
|
||||
const response = await call(routesOf(router)[0].handlers[0]);
|
||||
|
||||
const response = await invokeChain(handlersFor(router, "/branding", "get"));
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.body).toEqual({
|
||||
appName: "Acme Ops",
|
||||
tagline: "Ship it",
|
||||
logo: pngDataUrl,
|
||||
appName: "Acme",
|
||||
tagline: "Ops",
|
||||
logo: null,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("PATCH /users/branding", () => {
|
||||
it("rejects an unauthenticated request and persists nothing", async () => {
|
||||
const router = buildRouter(fakeRequireAdmin("unauthenticated"));
|
||||
|
||||
const response = await invokeChain(
|
||||
handlersFor(router, "/branding", "patch"),
|
||||
{ appName: "Hijacked" },
|
||||
);
|
||||
|
||||
expect(response.statusCode).toBe(401);
|
||||
expect(state.settings).toEqual({});
|
||||
});
|
||||
|
||||
it("rejects a non-admin request and persists nothing", async () => {
|
||||
const router = buildRouter(fakeRequireAdmin("not-admin"));
|
||||
|
||||
const response = await invokeChain(
|
||||
handlersFor(router, "/branding", "patch"),
|
||||
{ appName: "Hijacked" },
|
||||
);
|
||||
|
||||
expect(response.statusCode).toBe(403);
|
||||
expect(state.settings).toEqual({});
|
||||
});
|
||||
|
||||
it("persists only the allowed fields for an admin request", async () => {
|
||||
const router = buildRouter(fakeRequireAdmin("admin"));
|
||||
|
||||
const response = await invokeChain(
|
||||
handlersFor(router, "/branding", "patch"),
|
||||
{ appName: "Acme Ops", tagline: "Ship it", logo: pngDataUrl },
|
||||
);
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(state.settings.branding_app_name).toBe("Acme Ops");
|
||||
expect(state.settings.branding_tagline).toBe("Ship it");
|
||||
expect(state.settings.branding_logo).toMatch(/^data:image\/png;base64,/);
|
||||
expect(response.body).toMatchObject({
|
||||
appName: "Acme Ops",
|
||||
tagline: "Ship it",
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects unknown fields without writing anything", async () => {
|
||||
const router = buildRouter(fakeRequireAdmin("admin"));
|
||||
|
||||
const response = await invokeChain(
|
||||
handlersFor(router, "/branding", "patch"),
|
||||
{ theme: "dark" },
|
||||
);
|
||||
|
||||
expect(response.statusCode).toBe(400);
|
||||
expect(response.body).toMatchObject({
|
||||
code: "BRANDING_SETTINGS_UNKNOWN_FIELD",
|
||||
});
|
||||
expect(state.settings).toEqual({});
|
||||
});
|
||||
|
||||
it("rejects an app name over the length limit", async () => {
|
||||
const router = buildRouter(fakeRequireAdmin("admin"));
|
||||
|
||||
const response = await invokeChain(
|
||||
handlersFor(router, "/branding", "patch"),
|
||||
{ appName: "x".repeat(61) },
|
||||
);
|
||||
|
||||
expect(response.statusCode).toBe(400);
|
||||
expect(response.body).toMatchObject({
|
||||
code: "BRANDING_SETTINGS_INVALID",
|
||||
field: "appName",
|
||||
});
|
||||
expect(state.settings).toEqual({});
|
||||
});
|
||||
|
||||
it("rejects malformed/non-raster logo data without persisting it", async () => {
|
||||
const router = buildRouter(fakeRequireAdmin("admin"));
|
||||
|
||||
const response = await invokeChain(
|
||||
handlersFor(router, "/branding", "patch"),
|
||||
{
|
||||
logo: `data:image/png;base64,${Buffer.from("not an image").toString("base64")}`,
|
||||
},
|
||||
);
|
||||
|
||||
expect(response.statusCode).toBe(400);
|
||||
expect(response.body).toMatchObject({
|
||||
code: "BRANDING_SETTINGS_INVALID",
|
||||
field: "logo",
|
||||
});
|
||||
expect(state.settings).toEqual({});
|
||||
});
|
||||
|
||||
it("clears the logo when patched with null", async () => {
|
||||
state.settings.branding_logo = pngDataUrl;
|
||||
const router = buildRouter(fakeRequireAdmin("admin"));
|
||||
|
||||
const response = await invokeChain(
|
||||
handlersFor(router, "/branding", "patch"),
|
||||
{ logo: null },
|
||||
);
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(state.settings.branding_logo).toBeUndefined();
|
||||
expect(response.body).toMatchObject({ logo: null });
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user