-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.js
49 lines (39 loc) · 1.79 KB
/
tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import test from 'ava';
import scrubber from './index';
test('eliminates scripts and iframes by default', t => {
let scriptText = 'hello <script>malicious();</script>',
frameText = 'goodbye<iframe src="malicious.com"></iframe>',
scriptScrubbed = scrubber({scriptText}),
frameScrubbed = scrubber({frameText});
t.is(scriptScrubbed.scrubbed.scriptText, 'hello ');
t.is(frameScrubbed.scrubbed.frameText, 'goodbye');
});
test('leaves scripts and iframes alone if other selector passed', t => {
let testText = '<script>whoKnew();</script><p>good</p><p class="kill">bad</p><iframe></iframe>',
scrubbed = scrubber({testText}, ['.kill']);
t.is(scrubbed.scrubbed.testText, '<script>whoKnew();</script><p>good</p><iframe></iframe>')
});
test('finds nested version of selector', t => {
let nested = '<div><p>Hello</p><script>pwn3d();</script></div>',
scrubbed = scrubber({nested});
t.is(scrubbed.scrubbed.nested, '<div><p>Hello</p></div>');
});
test('elminates multiple offending elements if present.', t => {
let nested = '<div><p>Hello</p><script>pwn3d();</script></div><iframe> \
</iframe><script>different</script>',
scrubbed = scrubber({nested});
t.is(scrubbed.scrubbed.nested, '<div><p>Hello</p></div>');
});
test('eliminates off-case offending elements', t => {
let nested = '<div><p>Hello</p><sCrIpt>pwn3d();</ScrIPt></div><iframe> \
</iframe><script>different</script>',
scrubbed = scrubber({nested});
t.is(scrubbed.scrubbed.nested, '<div><p>Hello</p></div>');
})
test('escapes incident output', t => {
let nested = '<div><p>Hello</p><sCrIpt>pwn3d();</ScrIPt></div><iframe> \
</iframe><script>different</script>',
scrubbed = scrubber({nested});
t.is(scrubbed.incidents.length, 3);
t.is(scrubbed.incidents[0], '<script>pwn3d();</script>');
});