diff --git a/apps/smart-ssh-community/frontend/src/licenseCompatCheck.test.ts b/apps/smart-ssh-community/frontend/src/licenseCompatCheck.test.ts index 2ef152ae0..43c00364e 100644 --- a/apps/smart-ssh-community/frontend/src/licenseCompatCheck.test.ts +++ b/apps/smart-ssh-community/frontend/src/licenseCompatCheck.test.ts @@ -123,7 +123,8 @@ describe("check-license-compat", () => { expect(() => parseExceptions(raw(body))).toThrow(/array of tables/); const bad = spawnSync(process.execPath, [SCRIPT, raw(body)], { encoding: "utf8" }); expect(bad.status).not.toBe(0); - }); + expect(bad.stderr).toMatch(/array of tables/); + }, 30_000); it("rejects the dotted-key form", () => { const body = 'licenses.exceptions = [{ crate = "x", allow = ["GPL-2.0"] }]\n'; @@ -134,17 +135,41 @@ describe("check-license-compat", () => { 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"); + const FORMS: [string, string, RegExp][] = [ + ["array of tables", '[[licenses.exceptions]]\ncrate = "x"\nallow = ["GPL-2.0"]\n', /array of tables/], + ["dotted key", 'licenses.exceptions = [{ crate = "x", allow = ["GPL-2.0"] }]\n', /dotted key/], + ["quoted array of tables", '[[licenses."exceptions"]]\ncrate = "x"\n', /array of tables/], + ["quoted licenses", '"licenses".exceptions = [{ crate = "x", allow = ["GPL-2.0"] }]\n', /quoted key/], + ["quoted exceptions", "licenses.'exceptions' = [{ crate = \"x\", allow = [\"GPL-2.0\"] }]\n", /quoted key/], + ["spaced dots", 'licenses . "exceptions" = [{ crate = "x", allow = ["GPL-2.0"] }]\n', /quoted key/], + ["inline table", 'licenses = { exceptions = [{ crate = "x", allow = ["GPL-2.0"] }] }\n', /inline table/], + ]; + + it.each(FORMS)("rejects %s, also with comment and CRLF", (_n, body, re) => { + expect(() => parseExceptions(raw(body))).toThrow(re); + const withComment = body.replace(/\n/, " # note\n"); + expect(() => parseExceptions(raw(withComment))).toThrow(re); + expect(() => parseExceptions(raw(withComment.replace(/\n/g, "\r\n")))).toThrow(re); + }); + + it("does not throw for commented-out forms", () => { + for (const [, body] of FORMS) { + expect(parseExceptions(raw(body.replace(/^/gm, "# ")))).toEqual([]); } }); + it( + "check-license-compat exits non-zero naming the form", + () => { + for (const [, body, re] of FORMS) { + const bad = spawnSync(process.execPath, [SCRIPT, raw(body)], { encoding: "utf8" }); + expect(bad.status).not.toBe(0); + expect(bad.stderr).toMatch(re); + } + }, + 30_000, + ); + 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"] }, @@ -159,6 +184,6 @@ describe("check-license-compat", () => { expect(bad.stderr).toContain('crate = "x"'); const ok = spawnSync(process.execPath, [SCRIPT], { encoding: "utf8" }); expect(ok.status).toBe(0); - }); + }, 30_000); }); }); diff --git a/scripts/generate-third-party-notices.mjs b/scripts/generate-third-party-notices.mjs index dade203dc..d0c65d7bd 100644 --- a/scripts/generate-third-party-notices.mjs +++ b/scripts/generate-third-party-notices.mjs @@ -155,12 +155,23 @@ function parseExceptions(licensesFilePath) { .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) { + // General rule: any line using `exceptions` as a key (bare or quoted) other + // than the supported `exceptions = [` block is rejected, so future spellings + // fail closed too. + const keyRe = /(^|[\s.{,\[])(["']?)exceptions\2\s*(=|\]|\.|$)/; + for (const line of content.split("\n")) { + if (/^[ \t]*exceptions[ \t]*=[ \t]*\[/.test(line)) continue; + if (!keyRe.test(line)) continue; + const t = line.trim(); + const form = /^\[\[/.test(t) + ? "array of tables" + : /\{[^}]*exceptions/.test(t) + ? "inline table" + : /["']/.test(t.split("=")[0]) + ? "quoted key" + : "dotted key"; fail( - `Nicht unterstützte Schreibweise der Ausnahmen in ${licensesFilePath} (array of tables / dotted key): ${alt[0].trim()} — bitte den Block "exceptions = [ … ]" unter [licenses] verwenden.`, + `Nicht unterstützte Schreibweise der Ausnahmen in ${licensesFilePath} (${form}): ${t} — bitte den Block "exceptions = [ … ]" unter [licenses] verwenden.`, ); } const key = content.match(/^[ \t]*exceptions\s*=\s*\[/m);