mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-06 12:12:16 +00:00
Remove .toLowerCase() transform from registryUsernameSchema. AWS ECR requires the username to be exactly 'AWS' (uppercase) for authentication. Docker Hub usernames are case-insensitive for login, so preserving case is safe for all providers. Closes #4632
This commit is contained in:
@@ -0,0 +1,75 @@
|
|||||||
|
import { apiCreateRegistry, apiTestRegistry } from "@dokploy/server/db/schema";
|
||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
|
describe("Registry Schema - Username case preservation (#4632)", () => {
|
||||||
|
const validBase = {
|
||||||
|
registryName: "AWS ECR",
|
||||||
|
password: "dXNlcm5hbWU6cGFzc3dvcmQ=", // dummy base64 token
|
||||||
|
registryUrl: "123456789.dkr.ecr.us-east-1.amazonaws.com",
|
||||||
|
registryType: "cloud" as const,
|
||||||
|
imagePrefix: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
it("should preserve uppercase username (AWS ECR requires 'AWS')", () => {
|
||||||
|
const result = apiCreateRegistry.safeParse({
|
||||||
|
...validBase,
|
||||||
|
username: "AWS",
|
||||||
|
});
|
||||||
|
expect(result.success).toBe(true);
|
||||||
|
if (result.success) {
|
||||||
|
expect(result.data.username).toBe("AWS");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not lowercase mixed-case usernames", () => {
|
||||||
|
const result = apiCreateRegistry.safeParse({
|
||||||
|
...validBase,
|
||||||
|
username: "MyUser",
|
||||||
|
});
|
||||||
|
expect(result.success).toBe(true);
|
||||||
|
if (result.success) {
|
||||||
|
expect(result.data.username).toBe("MyUser");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should still trim whitespace from username", () => {
|
||||||
|
const result = apiCreateRegistry.safeParse({
|
||||||
|
...validBase,
|
||||||
|
username: " AWS ",
|
||||||
|
});
|
||||||
|
expect(result.success).toBe(true);
|
||||||
|
if (result.success) {
|
||||||
|
expect(result.data.username).toBe("AWS");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should reject empty username", () => {
|
||||||
|
const result = apiCreateRegistry.safeParse({
|
||||||
|
...validBase,
|
||||||
|
username: "",
|
||||||
|
});
|
||||||
|
expect(result.success).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should also preserve case in apiTestRegistry", () => {
|
||||||
|
const result = apiTestRegistry.safeParse({
|
||||||
|
...validBase,
|
||||||
|
username: "AWS",
|
||||||
|
});
|
||||||
|
expect(result.success).toBe(true);
|
||||||
|
if (result.success) {
|
||||||
|
expect(result.data.username).toBe("AWS");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should accept lowercase usernames too (backward compat)", () => {
|
||||||
|
const result = apiCreateRegistry.safeParse({
|
||||||
|
...validBase,
|
||||||
|
username: "myuser",
|
||||||
|
});
|
||||||
|
expect(result.success).toBe(true);
|
||||||
|
if (result.success) {
|
||||||
|
expect(result.data.username).toBe("myuser");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -44,12 +44,11 @@ export const registryRelations = relations(registry, ({ many }) => ({
|
|||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Image references require a lowercase namespace (e.g. Docker Hub username).
|
// Registry usernames should NOT be lowercased.
|
||||||
const registryUsernameSchema = z
|
// Some registries (e.g. AWS ECR) require a specific case: the username must be
|
||||||
.string()
|
// exactly "AWS" (uppercase) for ECR authentication. Docker Hub usernames are
|
||||||
.trim()
|
// case-insensitive for login, so preserving case is safe for all providers.
|
||||||
.min(1)
|
const registryUsernameSchema = z.string().trim().min(1);
|
||||||
.transform((s) => s.toLowerCase());
|
|
||||||
|
|
||||||
// Registry URLs must be hostname[:port] only — no shell metacharacters
|
// Registry URLs must be hostname[:port] only — no shell metacharacters
|
||||||
// Empty string is allowed (means default/Docker Hub registry)
|
// Empty string is allowed (means default/Docker Hub registry)
|
||||||
|
|||||||
Reference in New Issue
Block a user