f97999c3c0
- coalesce.js: generisches Serialisieren+Koaleszieren je Key; buildSite() in hugo.js nutzt es → Publish/Preview/Profil starten nie überlappende Hugo- Prozesse, schnelle Folge-Aufrufe lösen nur einen Trailing-Build aus - dialog-store: syncLibrary() gedrosselt (60s-TTL) statt bei jedem Forum-Read Filesystem-Walk + Upsert; Publish forciert Sync (force:true) - test/: node:test-Suite (19 Tests) für safeRel/normAuthors/urlFor/hasAccess, roleOf + lokale JWT-Verifikation, Rate-Limiter, Coalescing; npm test Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
42 lines
1.5 KiB
JavaScript
42 lines
1.5 KiB
JavaScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
|
|
const { safeRel, normAuthors, hasAccess, urlFor } = await import('../src/files.js');
|
|
|
|
test('safeRel: gültiger relativer .md-Pfad bleibt erhalten', () => {
|
|
assert.equal(safeRel('library/software/stack.md'), 'library/software/stack.md');
|
|
assert.equal(safeRel('a/./b.md'), 'a/b.md');
|
|
});
|
|
|
|
test('safeRel: Path-Traversal wird abgelehnt', () => {
|
|
assert.throws(() => safeRel('../etc/passwd.md'));
|
|
assert.throws(() => safeRel('a/../../b.md'));
|
|
assert.throws(() => safeRel('/absolut.md'));
|
|
});
|
|
|
|
test('safeRel: nur .md erlaubt, leer/falsch wirft', () => {
|
|
assert.throws(() => safeRel('note.txt'));
|
|
assert.throws(() => safeRel(''));
|
|
assert.throws(() => safeRel(null));
|
|
});
|
|
|
|
test('normAuthors: String/Array/Leer normalisieren', () => {
|
|
assert.deepEqual(normAuthors('a@x.ch'), ['a@x.ch']);
|
|
assert.deepEqual(normAuthors(['a@x.ch', 'b@y.ch']), ['a@x.ch', 'b@y.ch']);
|
|
assert.deepEqual(normAuthors(null), []);
|
|
assert.deepEqual(normAuthors([]), []);
|
|
});
|
|
|
|
test('hasAccess: case-insensitive Mitgliedschaft', () => {
|
|
assert.equal(hasAccess(['Karim@x.ch'], 'karim@x.ch'), true);
|
|
assert.equal(hasAccess(['a@x.ch'], 'b@y.ch'), false);
|
|
assert.equal(hasAccess([], 'a@x.ch'), false);
|
|
});
|
|
|
|
test('urlFor: Hugo-URLs aus relativem Pfad', () => {
|
|
assert.equal(urlFor('_index.md'), '/');
|
|
assert.equal(urlFor('manifest.md'), '/manifest/');
|
|
assert.equal(urlFor('library/software/stack.md'), '/library/software/stack/');
|
|
assert.equal(urlFor('software/_index.md'), '/software/');
|
|
});
|