Skip to content

Commit 659883b

Browse files
committed
refactor: xss tests
1 parent bcabf32 commit 659883b

File tree

5 files changed

+78
-52
lines changed

5 files changed

+78
-52
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
exports['escape when the value is not empty 1'] = {
2+
"title": "<script src=‘http://127.0.0.1:8080/malware.js’></script>"
3+
}
4+

packages/metascraper/test/unit/interface.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,34 @@ it('url is required', async () => {
2828
}
2929
})
3030

31+
it('escape is enabled by default', async () => {
32+
const html = `
33+
<!doctype html>
34+
<html xmlns:og="http://ogp.me/ns#" lang="en">
35+
36+
<head>
37+
<meta charset="utf8">
38+
<title>metascraper</title>
39+
<meta property="og:description" content="The HR startups go to war.">
40+
<meta property="og:image" content="image">
41+
<meta property="og:title" content="<script src='http://127.0.0.1:8080/malware.js'></script>">
42+
<meta property="og:type" content="article">
43+
<meta property="og:url" content="http://127.0.0.1:8080">
44+
</head>
45+
46+
<body>
47+
</body>
48+
</html>
49+
`
50+
51+
const metadata = await metascraper({
52+
html: html,
53+
url: 'http://127.0.0.1:8080'
54+
})
55+
56+
should(metadata.title).be.equal('<script src=‘http://127.0.0.1:8080/malware.js’></script>')
57+
})
58+
3159
it('load extra rules', async () => {
3260
const url = 'https://microlink.io'
3361

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
'use strict'
2+
3+
const metascraper = require('metascraper')([require('metascraper-title')()])
4+
const snapshot = require('snap-shot')
5+
const should = require('should')
6+
7+
const html = `
8+
<!doctype html>
9+
<html xmlns:og="http://ogp.me/ns#" lang="en">
10+
11+
<head>
12+
<meta charset="utf8">
13+
<title>metascraper</title>
14+
<meta property="og:description" content="The HR startups go to war.">
15+
<meta property="og:image" content="image">
16+
<meta property="og:title" content="<script src='http://127.0.0.1:8080/malware.js'></script>">
17+
<meta property="og:type" content="article">
18+
<meta property="og:url" content="http://127.0.0.1:8080">
19+
</head>
20+
21+
<body>
22+
</body>
23+
</html>
24+
`
25+
26+
describe('xss', () => {
27+
it('explicitily disable escape', async () => {
28+
const metadata = await metascraper({
29+
html: html,
30+
url: 'http://127.0.0.1:8080',
31+
escape: false
32+
})
33+
34+
should(metadata.title).be.equal('<script src=‘http://127.0.0.1:8080/malware.js’></script>')
35+
})
36+
37+
it('escape when the value is not empty', async () => {
38+
const metadata = await metascraper({
39+
html: html,
40+
url: 'http://127.0.0.1:8080',
41+
escape: true
42+
})
43+
44+
snapshot(metadata)
45+
})
46+
})

packages/metascraper/test/unit/xss/files/issue-96.html

Lines changed: 0 additions & 16 deletions
This file was deleted.

packages/metascraper/test/unit/xss/xss.js

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)