refactor: trim v2 release hardening
This commit is contained in:
1 parent
3cf1dc8341
commit
657704340c
79 files changed
+405
-3378
No files matched your search
@@ -3,7 +3,6 @@ import { describe, expect, test } from "vitest";
|
||||
import { CUSTOM_WIDGET_STARTER } from "@homarr/custom-widgets/core";
|
||||
|
||||
import {
|
||||
normalizeDocsBaseUrl,
|
||||
normalizeHttpUrl,
|
||||
resolveHomarrUrlConfig,
|
||||
validateWorkshopWidget,
|
||||
@@ -31,23 +30,6 @@ describe("Workshop URL configuration", () => {
|
||||
expect(() => normalizeHttpUrl("https://example.com/?token=secret", "WORKSHOP_API_URL")).toThrow("query string");
|
||||
expect(() => normalizeHttpUrl("\nhttps://example.com", "WORKSHOP_API_URL")).toThrow("control characters");
|
||||
});
|
||||
|
||||
test.each([
|
||||
[undefined, "/"],
|
||||
["/", "/"],
|
||||
["/docs", "/docs/"],
|
||||
["/docs/", "/docs/"],
|
||||
["/docs..preview", "/docs..preview/"],
|
||||
])("normalizes DOCS_BASE_URL %s", (input, expected) => {
|
||||
expect(normalizeDocsBaseUrl(input)).toBe(expected);
|
||||
});
|
||||
|
||||
test.each(["docs", "/docs?preview=1", "/../docs", "/%2e%2e/private", "/docs path", String.raw`/docs\private`])(
|
||||
"rejects invalid DOCS_BASE_URL %s",
|
||||
(input) => {
|
||||
expect(() => normalizeDocsBaseUrl(input)).toThrow("DOCS_BASE_URL");
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("Workshop widget validation", () => {
|
||||
|
||||
@@ -68,19 +68,6 @@ export function resolveHomarrUrlConfig(input: HomarrUrlConfigInput = {}): Homarr
|
||||
return { homarrWebsiteUrl, workshopApiUrl, workshopWebUrl };
|
||||
}
|
||||
|
||||
export function normalizeDocsBaseUrl(value = "/"): string {
|
||||
if (
|
||||
!value.startsWith("/") ||
|
||||
/[^A-Za-z0-9._~/-]/u.test(value) ||
|
||||
value.split("/").some((segment) => segment === "." || segment === "..")
|
||||
) {
|
||||
throw new Error("DOCS_BASE_URL must be a safe path that starts with '/'");
|
||||
}
|
||||
|
||||
const path = value.replace(/^\/+|\/+$/gu, "");
|
||||
return path ? `/${path}/` : "/";
|
||||
}
|
||||
|
||||
export const workshopReportCategorySchema = z.enum(["malicious", "spam", "copyright", "inappropriate", "other"]);
|
||||
export const workshopSubmissionTypeSchema = z.enum(["customWidget", "customCss"]);
|
||||
export type WorkshopSubmissionType = z.infer<typeof workshopSubmissionTypeSchema>;
|
||||
|
||||
Reference in new issue
Block a user