-
Notifications
You must be signed in to change notification settings - Fork 1
/
1365.js
43 lines (33 loc) · 1.03 KB
/
1365.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
const express = require('express')
const cookieParser = require('cookie-parser')
const app = express()
app.use(cookieParser('yolo'))
app.get('/', function(req, res) {
res.cookie('test', 'value', { signed: true })
res.sendStatus(200)
})
app.get('/cookie', function(req, res) {
res.send(req.signedCookies['test'])
})
const server = app.listen(5000, () => {
console.log('listening on http://localhost:5000')
main()
.catch(e => console.error('error', e))
.then(() => server.close())
})
const cookie = require('cookie-signature')
const Nightmare = require('nightmare')
async function main() {
const nightmare = Nightmare()
const name = 'test'
const secret = 'yolo'
const value = 'coolness'
const signed = 's:' + cookie.sign(value, secret)
const headers = {
Cookie: [name, signed].map(encodeURIComponent).join('=')
}
await nightmare.goto('http://localhost:5000/cookie', headers)
const res = await nightmare.evaluate(() => document.body.textContent)
console.log('cookie =', res)
await nightmare.end()
}