Skip to content

Commit 06b3bb2

Browse files
committed
fix(libsql): validate appName like the other database kinds
1 parent 48504fd commit 06b3bb2

2 files changed

Lines changed: 69 additions & 1 deletion

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { apiCreateLibsql } from "@dokploy/server/db/schema";
2+
import { APP_NAME_MESSAGE } from "@dokploy/server/db/schema/utils";
3+
import { describe, expect, it } from "vitest";
4+
5+
describe("apiCreateLibsql appName", () => {
6+
const validBase = {
7+
name: "My libSQL",
8+
dockerImage: "ghcr.io/tursodatabase/libsql-server:v0.24.32",
9+
environmentId: "env-1",
10+
description: null,
11+
databaseUser: "admin",
12+
databasePassword: "secretPassword1",
13+
sqldNode: "primary" as const,
14+
sqldPrimaryUrl: null,
15+
enableNamespaces: false,
16+
serverId: null,
17+
};
18+
19+
it.each([
20+
["a space", "my libsql"],
21+
["an at sign", "repro@lib"],
22+
["a slash", "team/libsql"],
23+
["a colon", "libsql:1"],
24+
])("refuses an appName with %s", (_, appName) => {
25+
const result = apiCreateLibsql.safeParse({ ...validBase, appName });
26+
expect(result.success).toBe(false);
27+
if (!result.success) {
28+
const appNameIssues = result.error.issues.filter(
29+
(issue) => issue.path[0] === "appName",
30+
);
31+
expect(appNameIssues.map((issue) => issue.message)).toEqual([
32+
APP_NAME_MESSAGE,
33+
]);
34+
}
35+
});
36+
37+
it("accepts an appName of letters, numbers, dots, underscores and hyphens", () => {
38+
const result = apiCreateLibsql.safeParse({
39+
...validBase,
40+
appName: "my-libsql.db_1",
41+
});
42+
expect(result.success).toBe(true);
43+
});
44+
45+
it("refuses an appName longer than 63 characters", () => {
46+
const result = apiCreateLibsql.safeParse({
47+
...validBase,
48+
appName: "a".repeat(64),
49+
});
50+
expect(result.success).toBe(false);
51+
if (!result.success) {
52+
const appNameIssues = result.error.issues.filter(
53+
(issue) => issue.path[0] === "appName",
54+
);
55+
expect(appNameIssues.map((issue) => issue.code)).toEqual(["too_big"]);
56+
}
57+
});
58+
59+
it("accepts an appName of 63 characters", () => {
60+
const result = apiCreateLibsql.safeParse({
61+
...validBase,
62+
appName: "a".repeat(63),
63+
});
64+
expect(result.success).toBe(true);
65+
});
66+
});

‎packages/server/src/db/schema/libsql.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ import {
3535
UpdateConfigSwarmSchema,
3636
} from "./shared";
3737
import {
38+
APP_NAME_MESSAGE,
39+
APP_NAME_REGEX,
3840
DATABASE_PASSWORD_MESSAGE,
3941
DATABASE_PASSWORD_REGEX,
4042
encryptedText,
@@ -115,7 +117,7 @@ export const libsqlRelations = relations(libsql, ({ one, many }) => ({
115117
const createSchema = createInsertSchema(libsql, {
116118
libsqlId: z.string(),
117119
name: z.string().min(1),
118-
appName: z.string().min(1),
120+
appName: z.string().min(1).max(63).regex(APP_NAME_REGEX, APP_NAME_MESSAGE),
119121
createdAt: z.string(),
120122
databaseUser: z.string().min(1),
121123
databasePassword: z.string().regex(DATABASE_PASSWORD_REGEX, {

0 commit comments

Comments
 (0)