26 lines
1.2 KiB
TypeScript
26 lines
1.2 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import html from '../index.html?raw';
|
|
import themeScript from '../public/theme-init.js?raw';
|
|
|
|
// The host sends Content-Security-Policy "script-src 'self'": an inline script in the admin page is blocked there, so the
|
|
// page must have none (the theme is set by /theme-init.js, a file of its own).
|
|
describe('the admin page and the Content-Security-Policy', () => {
|
|
it('has no inline script', () => {
|
|
const inline = [...html.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)].filter(([, attributes]) => !/\bsrc\s*=/.test(attributes));
|
|
|
|
expect(inline).toEqual([]);
|
|
});
|
|
|
|
it('sets the theme from a file of its own, before the app', () => {
|
|
expect(html.indexOf('src="/theme-init.js"')).toBeGreaterThan(-1);
|
|
expect(html.indexOf('src="/theme-init.js"')).toBeLessThan(html.indexOf('src="/src/main.tsx"'));
|
|
expect(themeScript).toContain("localStorage.getItem('cms-theme')");
|
|
expect(themeScript).toContain('classList.add');
|
|
});
|
|
|
|
it('has no inline event handlers or javascript: links either', () => {
|
|
expect(html).not.toMatch(/\son[a-z]+\s*=/i);
|
|
expect(html).not.toMatch(/javascript:/i);
|
|
});
|
|
});
|