-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
48 lines (43 loc) · 1.1 KB
/
test.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 TestRunner from 'test-runner'
import Blacklist from 'lws-blacklist'
import Lws from 'lws'
import fetch from 'node-fetch'
import { strict as a } from 'assert'
const tom = new TestRunner.Tom()
tom.test('simple', async function () {
const port = 8000 + this.index
const lws = await Lws.create({
port,
stack: Blacklist,
blacklist: /\/one/
})
try {
const response = await fetch(`http://localhost:${port}/one`)
const response2 = await fetch(`http://localhost:${port}/two`)
a.equal(response.status, 403)
a.equal(response2.status, 404)
} catch (err) {
throw err
} finally {
lws.server.close()
}
})
tom.test('wildcard', async function () {
const port = 8000 + this.index
const lws = await Lws.create({
port,
stack: Blacklist,
blacklist: /.*\.php$/
})
try {
const response = await fetch(`http://localhost:${port}/one.php`)
const response2 = await fetch(`http://localhost:${port}/two`)
a.equal(response.status, 403)
a.equal(response2.status, 404)
} catch (err) {
throw err
} finally {
lws.server.close()
}
})
export default tom