import { describe, expect, it } from 'vitest';
import { purifyGatewayNoticeHtml } from '../src/security/gatewayNoticeHtml.js';
describe('purifyGatewayNoticeHtml', () => {
it('keeps the small inline formatting set used by Ref gateway notices', () => {
const source =
'점검
20시 ' +
'안내 ' +
'상세';
const clean = purifyGatewayNoticeHtml(source);
expect(clean).toContain('점검
');
expect(clean).toContain('style="color:#ff6600;font-size:1.2em;font-weight:bold"');
expect(clean).toContain('안내');
expect(clean).toContain('rel="noopener noreferrer nofollow"');
expect(purifyGatewayNoticeHtml(clean)).toBe(clean);
});
it('removes executable tags, handlers, unsafe URLs and CSS while keeping their plain text', () => {
const source =
'' +
'
' +
'' +
'문구' +
'폰트' +
'링크';
const clean = purifyGatewayNoticeHtml(source);
expect(clean).not.toMatch(/script|
문구');
expect(clean).toContain('폰트');
expect(clean).toContain('링크');
});
it('normalizes empty values', () => {
expect(purifyGatewayNoticeHtml(undefined)).toBe('');
expect(purifyGatewayNoticeHtml(null)).toBe('');
expect(purifyGatewayNoticeHtml('')).toBe('');
});
});