[268] Electron: externe Links im System-Browser, keine fremden Fenster; Release-Skript: Anhang erst hochladen dann ersetzen, Abbruch bei veröffentlichtem Release und ohne Mac-Pakete

- Electron: setWindowOpenHandler (https/mailto -> shell.openExternal, sonst deny), will-navigate/will-redirect nur im App-Ursprung, CSP nur für den App-Ursprung; Entscheide in scripts/electron-links.cjs (im Paket)
- Release-Skript: Ersetzen über temporären Namen + Löschen + Umbenennen; Abbruch ohne --publish auf veröffentlichtes Release (--replace-published); Abbruch bei --publish ohne Mac-Pakete (--linux-only)
- Tests: electronLinks.test.ts, releaseGitea.test.ts, e2e linuxApp170 (Externe Links); README und TODO nachgeführt
This commit is contained in:
Claude committed 2026-11-16 15:29:20 +00:00
1 parent cddbab57c0
commit 0bf79c819b
10 files changed
+262 -11

No files matched your search

+44
View File
@@ -0,0 +1,44 @@
// [268] Electron: externe Links im System-Browser, keine Kindfenster, keine fremde Navigation (reine Entscheide).
import { describe, expect, it } from "vitest";
import { createRequire } from "node:module";
import { readFileSync } from "node:fs";
import { join } from "node:path";
const links = createRequire(import.meta.url)("../../scripts/electron-links.cjs");
const ORIGINS = ["dossier://app", "http://localhost:5187"];
describe("[268] Electron-Links", () => {
it("window.open: nie ein Kindfenster; https/mailto gehen in den System-Browser", () => {
expect(links.windowOpenDecision("https://git.openbureau.ch/karim/dossier/issues/new")).toEqual({
action: "deny",
external: "https://git.openbureau.ch/karim/dossier/issues/new",
});
expect(links.windowOpenDecision("mailto:a@b.ch").external).toBe("mailto:a@b.ch");
for (const bad of ["http://example.org", "file:///etc/passwd", "javascript:alert(1)", "dossier://app/x", "data:text/html,x", "", "kaputt"]) {
expect(links.windowOpenDecision(bad), bad).toEqual({ action: "deny", external: null });
}
});
it("Navigation: nur App-Ursprung und Dev-Server, fremde https gehen extern", () => {
expect(links.navigationDecision("dossier://app/index.html", ORIGINS).allow).toBe(true);
expect(links.navigationDecision("http://localhost:5187/?x=1", ORIGINS).allow).toBe(true);
expect(links.navigationDecision("https://example.org/", ORIGINS)).toEqual({ allow: false, external: "https://example.org/" });
expect(links.navigationDecision("http://localhost:5188/", ORIGINS)).toEqual({ allow: false, external: null });
expect(links.navigationDecision("file:///etc/passwd", ORIGINS)).toEqual({ allow: false, external: null });
expect(links.navigationDecision("dossier://evil/", ORIGINS).allow).toBe(false);
});
it("CSP nur für den App-Ursprung", () => {
expect(links.shouldSetCsp("dossier://app/assets/x.js", ORIGINS)).toBe(true);
expect(links.shouldSetCsp("https://example.org/", ORIGINS)).toBe(false);
expect(links.shouldSetCsp("devtools://devtools/x", ORIGINS)).toBe(false);
});
it("Hauptprozess verdrahtet Handler, Navigation und Weiterleitung", () => {
const main = readFileSync(join(__dirname, "..", "..", "scripts", "electron-main.cjs"), "utf8");
expect(main).toMatch(/setWindowOpenHandler/);
expect(main).toMatch(/"will-navigate"/);
expect(main).toMatch(/"will-redirect"/);
expect(main).toMatch(/shell\.openExternal/);
});
});
+27
View File
@@ -67,4 +67,31 @@ describe("release-gitea-lib", () => {
const h = "a".repeat(64);
expect(lib.parseSums(`${h} x.AppImage\n\nkaputt\n${"b".repeat(64)} y.dmg\n`)).toEqual({ "x.AppImage": h, "y.dmg": "b".repeat(64) });
});
// [268] Ersetzen eines Anhangs: erst hochladen (temporärer Name), dann löschen und umbenennen — nie ohne `latest.json`.
it("tempAssetName: anderer Name als das Original, Stempel enthalten", () => {
expect(lib.tempAssetName("latest.json", 7)).toBe("latest.json.upload-7");
});
it("preflight: ohne --publish nicht auf ein veröffentlichtes Release", () => {
const base = { localFiles: ["a.AppImage"], publish: false, replacePublished: false, linuxOnly: false };
expect(lib.preflight({ ...base, release: { tag_name: "v1", draft: false, assets: [] } })).toMatch(/--replace-published/);
expect(lib.preflight({ ...base, release: { tag_name: "v1", draft: false, assets: [] }, replacePublished: true })).toBeNull();
expect(lib.preflight({ ...base, release: { tag_name: "v1", draft: true, assets: [] } })).toBeNull();
expect(lib.preflight({ ...base, release: null })).toBeNull();
});
it("preflight: --publish nur mit Mac-Paketen (lokal oder am Release), sonst --linux-only", () => {
const base = { publish: true, replacePublished: false, linuxOnly: false };
const draft = (names: string[]) => ({ draft: true, assets: names.map((name) => ({ name })) });
expect(lib.preflight({ ...base, localFiles: ["a.AppImage"], release: draft([]) })).toMatch(/--linux-only/);
expect(lib.preflight({ ...base, localFiles: ["a.AppImage"], release: null })).toMatch(/--linux-only/);
expect(lib.preflight({ ...base, localFiles: ["a.AppImage"], release: draft([]), linuxOnly: true })).toBeNull();
expect(lib.preflight({ ...base, localFiles: ["a.AppImage", "b.dmg"], release: draft([]) })).toBeNull();
expect(lib.preflight({ ...base, localFiles: ["a.AppImage"], release: draft(["b.dmg"]) })).toBeNull();
// --publish auf ein veröffentlichtes Release bleibt erlaubt (Nachführen), wenn Mac-Pakete da sind
expect(lib.preflight({ ...base, localFiles: ["b.dmg"], release: { draft: false, assets: [] } })).toBeNull();
expect(lib.hasMacPackages(["x.AppImage", "SHA256SUMS.txt"])).toBe(false);
expect(lib.hasMacPackages(["x.app.tar.gz"])).toBe(true);
});
});