notification
This commit is contained in:
@@ -12,7 +12,10 @@ const {
|
||||
normalizeOptionalHttpUrl,
|
||||
isPdfBuffer,
|
||||
sanitizeDocumentFileName,
|
||||
getDocumentContentDisposition
|
||||
getDocumentContentDisposition,
|
||||
normalizeNotificationActionUrl,
|
||||
normalizeNotificationAudiences,
|
||||
normalizeNotificationSeverity
|
||||
} = require('../backend/server');
|
||||
|
||||
async function withTestServer(run) {
|
||||
@@ -58,6 +61,31 @@ test('application URLs accept only HTTP and HTTPS protocols', () => {
|
||||
assert.match(normalizeOptionalHttpUrl('https://example.com/path'), /^https:\/\/example\.com\/path/);
|
||||
});
|
||||
|
||||
test('notification links stay inside the application', () => {
|
||||
assert.equal(normalizeNotificationActionUrl('#asset-borrows'), '#asset-borrows');
|
||||
assert.equal(normalizeNotificationActionUrl('/pages/index.html#notifications'), '/pages/index.html#notifications');
|
||||
assert.equal(normalizeNotificationActionUrl('https://attacker.example'), null);
|
||||
assert.equal(normalizeNotificationActionUrl('//attacker.example/path'), null);
|
||||
assert.equal(normalizeNotificationActionUrl('/\\attacker.example/path'), null);
|
||||
assert.equal(normalizeNotificationActionUrl('javascript:alert(1)'), null);
|
||||
});
|
||||
|
||||
test('notification audiences are normalized and deduplicated', () => {
|
||||
assert.deepEqual(normalizeNotificationAudiences([]), []);
|
||||
assert.deepEqual(normalizeNotificationAudiences([{ type: 'all' }]), [{ type: 'all', value: null }]);
|
||||
assert.deepEqual(normalizeNotificationAudiences([
|
||||
{ type: 'role', value: 'Admin' },
|
||||
{ type: 'role', value: 'admin' },
|
||||
{ type: 'user', value: '5' },
|
||||
{ type: 'user', value: 'invalid' }
|
||||
]), [
|
||||
{ type: 'role', value: 'admin' },
|
||||
{ type: 'user', value: '5' }
|
||||
]);
|
||||
assert.equal(normalizeNotificationSeverity('WARNING'), 'warning');
|
||||
assert.equal(normalizeNotificationSeverity('unknown'), 'info');
|
||||
});
|
||||
|
||||
test('PDF uploads require a PDF header and end-of-file marker', () => {
|
||||
assert.equal(isPdfBuffer(Buffer.from('%PDF-1.7\nbody\n%%EOF')), true);
|
||||
assert.equal(isPdfBuffer(Buffer.from('%PDF-1.7\nbody without trailer')), false);
|
||||
|
||||
Reference in New Issue
Block a user