diff options
Diffstat (limited to 'web-ui/test/spec/helpers/sanitizer.spec.js')
-rw-r--r-- | web-ui/test/spec/helpers/sanitizer.spec.js | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/web-ui/test/spec/helpers/sanitizer.spec.js b/web-ui/test/spec/helpers/sanitizer.spec.js new file mode 100644 index 00000000..acd4b2b2 --- /dev/null +++ b/web-ui/test/spec/helpers/sanitizer.spec.js @@ -0,0 +1,49 @@ +define(['helpers/sanitizer'], function (sanitizer) { + 'use strict'; + + describe('sanitizer', function () { + + describe('sanitizer.addLineBreaks', function () { + it('should add line breaks', function () { + var expectedOutput = 'foo<br/>bar'; + var output = sanitizer.addLineBreaks('foo\nbar'); + expect(output).toEqual(expectedOutput); + }); + }); + + describe('sanitizer.purifyHtml', function () { + it('should fire up DOMPurify', function () { + var expectedOutput = '123<a target="_blank">I am a dolphin!</a>'; + var output = sanitizer.purifyHtml('123<a href="javascript:alert(1)">I am a dolphin!</a>'); + expect(output).toEqual(expectedOutput); + }); + }); + + describe('sanitizer.purifyText', function () { + it('should escape HTML', function () { + var expectedOutput = '123<a>asd</a>'; + var output = sanitizer.purifyText('123<a>asd</a>'); + expect(output).toEqual(expectedOutput); + }); + }); + + describe('sanitizer.sanitize', function () { + it('should sanitize a plaintext mail', function () { + var expectedOutput = '123<a>asd</a>'; + var output = sanitizer.sanitize({ + textPlainBody: '123<a>asd</a>' + }); + expect(output).toEqual(expectedOutput); + }); + + it('should sanitize an html mail', function () { + var expectedOutput = '<div>123<a target="_blank">I am a dolphin!</a>foobar</div>'; + var output = sanitizer.sanitize({ + htmlBody: '<div>123<a href="javascript:alert(1)">I am a dolphin!</a>foobar</div>' + }); + expect(output).toEqual(expectedOutput); + }); + }); + + }); +}); |