Files
wekan/server/lib/tests/impersonationReportQuery.tests.js
T
Lauri Ojansivu 339729fd95 Tests for newest Security/Reports features (positive + negative)
- client/lib/tests/renderLinksPlainText.tests.js: the 'render links as plain text'
  toggle and XSS hardening. Config assertions (stripLinks adds <a> to FORBID_TAGS,
  default does not, KEEP_CONTENT) plus real sanitizeHTML() behavior: <a> stripped to
  its text when stripLinks, kept by default, and javascript: hrefs / event handlers /
  <script> removed regardless.
- client/lib/tests/alwaysShowCodeAsText.tests.js: escapeHtmlSource (exposed on the
  Markdown export) escapes <script>/comments/quotes/ampersand-first so code is shown
  not executed; leaves plain text and empty strings unchanged.
- server/lib/tests/impersonationReportQuery.tests.js: the Impersonation report search
  selector (extracted to models/lib/impersonationReportQuery.js so it is testable
  without re-registering the publication) builds a case-insensitive $or across the
  identity fields, escapes regex metacharacters, and is empty for a blank term.

The MimeBleed fix (fileValidationBypass.security.tests.js), SortBleed
(boards.security.tests.js) and import/export anonymization
(importExportSecurity.tests.js) already carry positive + negative tests.
2026-07-14 17:01:35 +03:00

33 lines
1.4 KiB
JavaScript

/* eslint-env mocha */
import { expect } from 'chai';
import { impersonationQuery } from '/models/lib/impersonationReportQuery';
// Unit tests for the Admin Panel / Reports / Impersonation search-selector builder.
describe('impersonationReportQuery', function() {
it('returns an empty selector when there is no search term (negative)', function() {
expect(impersonationQuery('')).to.deep.equal({});
expect(impersonationQuery(undefined)).to.deep.equal({});
expect(impersonationQuery(null)).to.deep.equal({});
});
it('builds a case-insensitive $or across the identity fields', function() {
const q = impersonationQuery('alice');
expect(q).to.have.property('$or');
const fields = q.$or.map(clause => Object.keys(clause)[0]);
expect(fields).to.have.members(['adminId', 'userId', 'boardId', 'attachmentId', 'reason']);
q.$or.forEach(clause => {
const rx = Object.values(clause)[0];
expect(rx).to.be.instanceof(RegExp);
expect(rx.flags).to.contain('i');
expect(rx.test('ALICE')).to.equal(true); // case-insensitive
});
});
it('escapes regex metacharacters so the term is matched literally (negative)', function() {
const q = impersonationQuery('a.b*c');
const rx = q.$or[0].adminId;
expect(rx.test('a.b*c')).to.equal(true); // the literal string matches
expect(rx.test('aXbYYc')).to.equal(false); // '.' and '*' are NOT treated as wildcards
});
});