Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions apps/smart-ssh-community/frontend/src/licenseCompatCheck.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"] },
Expand Down
12 changes: 11 additions & 1 deletion scripts/generate-third-party-notices.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [..]`),
Expand Down
Loading