41 lines
1.8 KiB
JavaScript
41 lines
1.8 KiB
JavaScript
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const { makeCalendarData, makeVcard } = require('../desktop/dav-codecs.cjs');
|
|
|
|
test('serializes calendar events with escaped values and stable injected identifiers', () => {
|
|
const data = makeCalendarData({
|
|
date: '2026-10-16',
|
|
title: 'Review, plan; follow-up',
|
|
place: 'Room A, west',
|
|
notes: 'First line\nSecond line',
|
|
_dav: { uid: 'event-1' }
|
|
}, { now: () => new Date('2026-10-16T12:34:56.000Z') });
|
|
|
|
assert.match(data, /UID:event-1\r\n/);
|
|
assert.match(data, /DTSTAMP:20261016T123456Z\r\n/);
|
|
assert.match(data, /DTSTART;VALUE=DATE:20261016\r\n/);
|
|
assert.match(data, /SUMMARY:Review\\, plan\\; follow-up\r\n/);
|
|
assert.match(data, /LOCATION:Room A\\, west\r\n/);
|
|
assert.match(data, /DESCRIPTION:First line\\nSecond line\r\n/);
|
|
});
|
|
|
|
test('serializes contacts with escaped fields and an injected identifier', () => {
|
|
const data = makeVcard({
|
|
name: 'Ada Example Lovelace',
|
|
email: 'ada@example.com',
|
|
note: 'Research, analysis; mathematics',
|
|
_dav: { uid: 'contact-1' }
|
|
});
|
|
|
|
assert.equal(data,
|
|
'BEGIN:VCARD\r\nVERSION:3.0\r\nUID:contact-1\r\nFN:Ada Example Lovelace\r\n' +
|
|
'N:Example Lovelace;Ada;;;\r\nEMAIL:ada@example.com\r\n' +
|
|
'NOTE:Research\\, analysis\\; mathematics\r\nEND:VCARD\r\n');
|
|
});
|
|
|
|
test('rejects DAV identifiers that can inject fields or escape resource paths', () => {
|
|
assert.throws(() => makeCalendarData({ date: '2026-10-16', title: 'Bad', _dav: { uid: 'good\r\nX-Evil: yes' } }), /identifier is invalid/);
|
|
assert.throws(() => makeCalendarData({ date: '2026-10-16', title: 'Bad', _dav: { uid: '../other' } }), /identifier is invalid/);
|
|
assert.throws(() => makeVcard({ name: 'Bad', email: 'x@example.test', _dav: { uid: 'x'.repeat(256) } }), /identifier is invalid/);
|
|
});
|