mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-17 21:10:48 +00:00
24 lines
1.3 KiB
TypeScript
24 lines
1.3 KiB
TypeScript
import React from 'react';
|
|
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import { renderToStaticMarkup } from 'react-dom/server';
|
|
import { PluginReadme } from './PluginReadme';
|
|
|
|
test('README never creates active HTML, remote media or script links', () => {
|
|
const html = renderToStaticMarkup(<PluginReadme markdown={'# Example\n\n<script>alert(1)</script>\n\n<img src="https://tracker.example/pixel">\n\n\n\n[run](javascript:alert%281%29)\n\n[docs](https://example.com)\n\n```html\n<iframe src="file:///secret">\n```'} />);
|
|
assert.doesNotMatch(html, /<(script|img|iframe|svg)\b/);
|
|
assert.doesNotMatch(html, /href="(javascript|file):/);
|
|
assert.match(html, /href="https:\/\/example.com"/);
|
|
assert.match(html, /rel="noopener noreferrer"/);
|
|
assert.match(html, /<script>/);
|
|
});
|
|
|
|
test('README only renders registered local rasterized images and placeholders otherwise', () => {
|
|
const path = `/assets/${'a'.repeat(64)}.png`;
|
|
const html = renderToStaticMarkup(<PluginReadme markdown={`  `} images={{ [path]: 'data:image/png;base64,YQ==' }} />);
|
|
assert.match(html, /src="data:image\/png;base64,YQ=="/);
|
|
assert.match(html, /\[tracker\]/);
|
|
assert.match(html, /\[bad\]/);
|
|
assert.doesNotMatch(html, /evil\.test/);
|
|
});
|