diff --git a/apps/smart-ssh-community/frontend/src/licenseCompatCheck.test.ts b/apps/smart-ssh-community/frontend/src/licenseCompatCheck.test.ts index 35467ebab..2ef152ae0 100644 --- a/apps/smart-ssh-community/frontend/src/licenseCompatCheck.test.ts +++ b/apps/smart-ssh-community/frontend/src/licenseCompatCheck.test.ts @@ -107,6 +107,44 @@ describe("check-license-compat", () => { ).toEqual([]); }); + it("rejects the array-of-tables form, naming the form", () => { + const body = '[[licenses.exceptions]]\ncrate = "x"\nallow = ["GPL-2.0"]\n'; + expect(() => parseExceptions(raw(body))).toThrow(/array of tables/); + }); + + it("rejects headers with a trailing comment or whitespace", () => { + for (const h of ["[[licenses.exceptions]] # note", "[[licenses.exceptions]] "]) { + expect(() => parseExceptions(raw(`${h}\ncrate = "x"\n`))).toThrow(/array of tables/); + } + }); + + it("rejects a CRLF header with a trailing comment", () => { + const body = '[[licenses.exceptions]] # note\r\ncrate = "x"\r\nallow = ["GPL-2.0"]\r\n'; + expect(() => parseExceptions(raw(body))).toThrow(/array of tables/); + const bad = spawnSync(process.execPath, [SCRIPT, raw(body)], { encoding: "utf8" }); + expect(bad.status).not.toBe(0); + }); + + it("rejects the dotted-key form", () => { + const body = 'licenses.exceptions = [{ crate = "x", allow = ["GPL-2.0"] }]\n'; + expect(() => parseExceptions(raw(body))).toThrow(/dotted key/); + }); + + it("ignores a commented-out array-of-tables header", () => { + expect(parseExceptions(raw('# [[licenses.exceptions]]\n#licenses.exceptions = []\n'))).toEqual([]); + }); + + it("check-license-compat exits non-zero for both alternative forms", () => { + for (const body of [ + '[[licenses.exceptions]]\ncrate = "x"\nallow = ["GPL-2.0"]\n', + 'licenses.exceptions = [{ crate = "x", allow = ["GPL-2.0"] }]\n', + ]) { + const bad = spawnSync(process.execPath, [SCRIPT, raw(body)], { encoding: "utf8" }); + expect(bad.status).not.toBe(0); + expect(bad.stderr).toContain("exceptions"); + } + }); + it("returns the sqlcipher-src entry of the repo deny.toml", () => { expect(parseExceptions(path.resolve(__dirname, "../../../../deny.toml"))).toEqual([ { crate: "sqlcipher-src", allow: ["blessing", "WTFPL"] }, diff --git a/scripts/generate-third-party-notices.mjs b/scripts/generate-third-party-notices.mjs index 8b11b5fb6..dade203dc 100644 --- a/scripts/generate-third-party-notices.mjs +++ b/scripts/generate-third-party-notices.mjs @@ -150,9 +150,19 @@ function parseExceptions(licensesFilePath) { // Strip comments first, so commented-out entries are not counted as active. const content = fs .readFileSync(licensesFilePath, "utf8") - .split("\n") + .split(/\r?\n/) .map((l) => l.replace(/#.*$/, "")) .join("\n"); + // Other valid TOML spellings of the same data are rejected (fail closed): + // the repo uses the `exceptions = [ … ]` block only. + const alt = content.match( + /^[ \t]*(?:\[\[[^\]\n]*\bexceptions\s*\]\]|licenses\s*\.\s*exceptions\s*=.*)[ \t]*$/m, + ); + if (alt) { + fail( + `Nicht unterstützte Schreibweise der Ausnahmen in ${licensesFilePath} (array of tables / dotted key): ${alt[0].trim()} — bitte den Block "exceptions = [ … ]" unter [licenses] verwenden.`, + ); + } const key = content.match(/^[ \t]*exceptions\s*=\s*\[/m); if (!key) return []; // Find the matching closing bracket (entries contain nested `allow = [..]`),