fix: harden v2 custom widgets and Workshop (#6480)

This commit is contained in:
Thomas authored and GitHub committed 2026-07-31 13:28:53 +02:00
1 parent e8a2c87c2d
commit 557ebe0a2f
138 files changed
+5151 -1976

No files matched your search

+30 -2
View File
@@ -2,7 +2,35 @@ import { describe, expect, test } from "vitest";
import { CUSTOM_WIDGET_STARTER } from "@homarr/custom-widgets/core";
import { validateWorkshopWidget, workshopSubmissionInputSchema, workshopSubmissionSummarySchema } from "./schema";
import {
normalizeHttpUrl,
resolveHomarrUrlConfig,
validateWorkshopWidget,
workshopSubmissionInputSchema,
workshopSubmissionSummarySchema,
} from "./schema";
describe("Workshop URL configuration", () => {
test("normalizes the URL contract and derives Workshop defaults", () => {
expect(
resolveHomarrUrlConfig({
homarrWebsiteUrl: "https://docs.example.com/",
workshopApiUrl: "https://api.example.com///",
}),
).toEqual({
homarrWebsiteUrl: "https://docs.example.com",
workshopApiUrl: "https://api.example.com",
workshopWebUrl: "https://docs.example.com/workshop",
});
});
test("rejects unsafe or ambiguous public URLs", () => {
expect(() => normalizeHttpUrl("file:///tmp/workshop", "WORKSHOP_API_URL")).toThrow("HTTP or HTTPS");
expect(() => normalizeHttpUrl("https://user:secret@example.com", "WORKSHOP_API_URL")).toThrow("credentials");
expect(() => normalizeHttpUrl("https://example.com/?token=secret", "WORKSHOP_API_URL")).toThrow("query string");
expect(() => normalizeHttpUrl("\nhttps://example.com", "WORKSHOP_API_URL")).toThrow("control characters");
});
});
describe("Workshop widget validation", () => {
test("accepts a canonical credential-free widget", () => {
@@ -28,7 +56,7 @@ describe("Workshop widget validation", () => {
).toBe(true);
});
test("uses canonical direct-binding validation before publication", () => {
test("validates direct bindings in the official client before publication", () => {
const widget = {
...CUSTOM_WIDGET_STARTER,
requests: {