pithos/hosted/test/public-page.test.js

29 lines
1.5 KiB
JavaScript
Raw Normal View History

// Public folder pages are served at /p/<who>/<drive>/<path>/ and also as
// navigate.st/s3/…, so every link in them must be relative to the folder.
import test from 'node:test';
import assert from 'node:assert/strict';
import { folderPage } from '../server.js';
test('folder page links are relative, names escaped, media playable', () => {
const html = folderPage({
owner: 'alice.x', bucket: 'music-house', key: 'Deep/Night/',
listing: { folders: ['Remixes/'], files: [{ name: 'A <i>song & co.mp3', size: 9_437_184 }, { name: 'cover.jpg', size: 2048 }, { name: 'notes.txt', size: 12 }], next: null },
});
assert.match(html, /<a href="Remixes\/">/);
assert.match(html, /href="A%20%3Ci%3Esong%20%26%20co\.mp3"/);
assert.match(html, /A &lt;i&gt;song &amp; co\.mp3/);
assert.doesNotMatch(html, /<i>song/);
assert.match(html, /data-kind="audio"/);
assert.match(html, /<img loading="lazy" src="cover\.jpg"/);
// Breadcrumbs climb with ../ only: drive root is two levels up.
assert.match(html, /<a href="\.\.\/\.\.\/">music-house<\/a> \/ <a href="\.\.\/">Deep<\/a> \/ <span>Night<\/span>/);
assert.doesNotMatch(html, /href="\/p\//);
});
test('drive root page has no stray parents', () => {
const html = folderPage({ owner: '0123', bucket: 'd', key: '', listing: { folders: [], files: [], next: 'tok/en' } });
assert.match(html, /This folder is empty/);
assert.match(html, /href="\?token=tok%2Fen"/);
assert.match(html, /<a href="\.\/">d<\/a>/);
});