/* eslint-env mocha */ import { expect } from 'chai'; import { getSecureDOMPurifyConfig, sanitizeHTML } from '/imports/lib/secureDOMPurify'; // Tests for the Admin Panel / Features / Security "Render links as plain text" // toggle and the underlying XSS hardening. Runs client-side, so DOMPurify has a // real DOM and sanitizeHTML() exercises the actual sanitizer, not just its config. describe('secureDOMPurify — render links as plain text + XSS hardening', function() { // Config-level assertions need no DOM, so they hold in any environment. describe('getSecureDOMPurifyConfig(options)', function() { it('forbids the tag only when stripLinks is set', function() { expect(getSecureDOMPurifyConfig({ stripLinks: true }).FORBID_TAGS).to.include('a'); }); it('does NOT forbid by default (negative)', function() { expect(getSecureDOMPurifyConfig().FORBID_TAGS).to.not.include('a'); }); it('keeps inner content so a stripped link leaves its visible text', function() { expect(getSecureDOMPurifyConfig({ stripLinks: true }).KEEP_CONTENT).to.equal(true); }); }); describe('sanitizeHTML() link handling', function() { it('drops the wrapper but keeps its visible text when stripLinks is true', function() { const out = sanitizeHTML('Company Board', { stripLinks: true }); expect(out).to.not.match(/ by default (negative)', function() { const out = sanitizeHTML('Company Board'); expect(out).to.match(/x').toLowerCase(); expect(out).to.not.contain('javascript:'); }); it('strips event-handler attributes', function() { const out = sanitizeHTML('').toLowerCase(); expect(out).to.not.contain('onerror'); }); it('removes hello'); expect(out.toLowerCase()).to.not.contain('just text

'); expect(out).to.contain('just'); expect(out).to.match(/