fix(wss): resolve libsql services when binding the container terminal

This commit is contained in:
Narciso
2026-10-21 22:26:02 -04:00
parent 99e4f1c8dc
commit 73c795e157
2 changed files with 19 additions and 2 deletions
@@ -1,6 +1,7 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
const mockFindApp = vi.hoisted(() => vi.fn());
const mockFindLibsql = vi.hoisted(() => vi.fn());
const mockExec = vi.hoisted(() => vi.fn());
vi.mock("@dokploy/server/db", () => {
const none = { findFirst: async () => undefined };
@@ -14,6 +15,7 @@ vi.mock("@dokploy/server/db", () => {
mariadb: none,
mongo: none,
redis: none,
libsql: { findFirst: mockFindLibsql },
},
},
};
@@ -30,6 +32,7 @@ const labels = (l: Record<string, string>) => ({ stdout: JSON.stringify(l) });
beforeEach(() => {
vi.clearAllMocks();
mockFindApp.mockResolvedValue({ appName: "app-mine-abc123" });
mockFindLibsql.mockResolvedValue(undefined);
});
describe("containerBelongsToService", () => {
@@ -54,6 +57,15 @@ describe("containerBelongsToService", () => {
expect(await containerBelongsToService("svc", "c1")).toBe(false);
});
it("resolves libsql services", async () => {
mockFindApp.mockResolvedValue(undefined);
mockFindLibsql.mockResolvedValue({ appName: "libsql-abc" });
mockExec.mockResolvedValue(
labels({ "com.docker.swarm.service.name": "libsql-abc" }),
);
expect(await containerBelongsToService("svc", "c1")).toBe(true);
});
it("denies an unknown service", async () => {
mockFindApp.mockResolvedValue(undefined);
expect(await containerBelongsToService("nope", "c1")).toBe(false);
@@ -2,6 +2,7 @@ import { db } from "@dokploy/server/db";
import {
applications,
compose,
libsql,
mariadb,
mongo,
mysql,
@@ -22,7 +23,7 @@ const OWNERSHIP_LABELS = [
];
const findServiceAppName = async (serviceId: string) => {
const [app, comp, pg, my, maria, mon, red] = await Promise.all([
const [app, comp, pg, my, maria, mon, red, lib] = await Promise.all([
db.query.applications.findFirst({
where: eq(applications.applicationId, serviceId),
columns: { appName: true },
@@ -51,8 +52,12 @@ const findServiceAppName = async (serviceId: string) => {
where: eq(redis.redisId, serviceId),
columns: { appName: true },
}),
db.query.libsql.findFirst({
where: eq(libsql.libsqlId, serviceId),
columns: { appName: true },
}),
]);
return (app ?? comp ?? pg ?? my ?? maria ?? mon ?? red)?.appName;
return (app ?? comp ?? pg ?? my ?? maria ?? mon ?? red ?? lib)?.appName;
};
// Service access alone must not allow `docker exec` into other tenants' containers.