mirror of
https://github.com/unraid/api.git
synced 2026-02-14 03:58:30 -06:00
This gets the original 3 component tests refactored to better follow the Vue Testing Library philosophy and test behavior. This also adds a new test file for the server store. Additional batches of tests will be added in proceeding PR's. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Chores** - Streamlined internal code organization and improved maintenance through refined import structures and cleanup of redundant files. - **Tests** - Expanded and restructured automated tests across core components, including new test files for `Auth`, `DownloadApiLogs`, and `KeyActions` to ensure robust behavior. - Enhanced test configuration and mock implementations for a more reliable, consistent testing environment. - Introduced best practices for testing Vue components and Pinia stores. These updates optimize performance and stability behind the scenes without altering the end-user experience. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: mdatelle <mike@datelle.net>
48 lines
1.6 KiB
TypeScript
48 lines
1.6 KiB
TypeScript
import { Markdown } from '~/helpers/markdown';
|
|
import { baseUrl } from 'marked-base-url';
|
|
import { describe, expect, test } from 'vitest';
|
|
|
|
// add a random extension to the instance
|
|
const instance = Markdown.create(baseUrl('https://unraid.net'));
|
|
const parse = async (content: string) => ({
|
|
fromDefault: await Markdown.parse(content),
|
|
fromInstance: await instance.parse(content),
|
|
});
|
|
|
|
describe('sanitization', () => {
|
|
test('strips javascript', async () => {
|
|
const parsed = await parse(`<img src=x onerror=alert(1)//><script>console.log('hello')</script>`);
|
|
expect(parsed.fromDefault).toMatchSnapshot();
|
|
expect(parsed.fromInstance).toMatchSnapshot();
|
|
});
|
|
|
|
test('strips various XSS vectors', async () => {
|
|
const vectors = [
|
|
'<a href="javascript:alert(1)">click me</a>',
|
|
"<IMG SRC=JaVaScRiPt:alert('XSS')>",
|
|
'"><script>alert(document.cookie)</script>',
|
|
'<style>@import \'javascript:alert("XSS")\';</style>',
|
|
];
|
|
|
|
for (const vector of vectors) {
|
|
const parsed = await parse(vector);
|
|
expect(parsed.fromDefault).not.toContain('javascript:');
|
|
expect(parsed.fromInstance).not.toContain('javascript:');
|
|
}
|
|
});
|
|
});
|
|
|
|
describe('extensibility', () => {
|
|
test('works with other extensions', async () => {
|
|
const parsed = await parse(`[Contact](/contact)`);
|
|
expect(parsed.fromDefault).toMatchInlineSnapshot(`
|
|
"<p><a href="/contact">Contact</a></p>
|
|
"
|
|
`);
|
|
expect(parsed.fromInstance).toMatchInlineSnapshot(`
|
|
"<p><a href="https://unraid.net/contact">Contact</a></p>
|
|
"
|
|
`);
|
|
});
|
|
});
|