-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
35 lines (30 loc) · 1.14 KB
/
test.js
File metadata and controls
35 lines (30 loc) · 1.14 KB
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
import {exec} from 'child_process'
import test from 'ava'
import got from 'got'
import makeAgent from '.'
const testSNI = (wait, host, agentOptions, connectOptions) => new Promise((resolve, reject) => {
setTimeout(() => {
got(host, {agent: makeAgent(agentOptions, connectOptions)})
}, wait)
exec(`tshark -Y ssl.handshake.type==1 -T fields -e ssl.handshake.extensions_server_name -a duration:${Math.ceil(wait * 2 / 1000)}`, (err, stdout) => {
if (err) {
reject(err)
} else {
stdout = stdout.toString().split('\n').filter(e => e.length > 0)
console.log(`SNI for ${host} request: [${stdout.join(', ')}]`)
resolve(stdout.includes(host))
}
})
})
// May need to be slower
const sniWait = 1000
const sniHost = 'github.com'
test.serial('SNI on normal request', async t => {
t.true(await testSNI(sniWait, sniHost))
})
test.serial('No SNI on request with servername: null', async t => {
t.false(await testSNI(sniWait, sniHost, {servername: null}))
})
test.serial('No SNI on request with servername: undefined using connectOptions', async t => {
t.false(await testSNI(sniWait, sniHost, null, {servername: undefined}))
})