6e2296f1df93b2c6f2e3580cae50fb5cc8b15e4e.svn-base
1.72 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// test that we can tunnel a https request over an http proxy
// keeping all the CA and whatnot intact.
//
// Note: this requires that squid is installed.
// If the proxy fails to start, we'll just log a warning and assume success.
var server = require('./server')
, assert = require('assert')
, request = require('../main.js')
, fs = require('fs')
, path = require('path')
, caFile = path.resolve(__dirname, 'ssl/npm-ca.crt')
, ca = fs.readFileSync(caFile)
, child_process = require('child_process')
, sqConf = path.resolve(__dirname, 'squid.conf')
, sqArgs = ['-f', sqConf, '-N', '-d', '5']
, proxy = 'http://localhost:3128'
, hadError = null
var squid = child_process.spawn('squid', sqArgs);
var ready = false
squid.stderr.on('data', function (c) {
console.error('SQUIDERR ' + c.toString().trim().split('\n')
.join('\nSQUIDERR '))
ready = c.toString().match(/ready to serve requests/i)
})
squid.stdout.on('data', function (c) {
console.error('SQUIDOUT ' + c.toString().trim().split('\n')
.join('\nSQUIDOUT '))
})
squid.on('exit', function (c) {
console.error('exit '+c)
if (c && !ready) {
console.error('squid must be installed to run this test.')
c = null
hadError = null
process.exit(0)
return
}
if (c) {
hadError = hadError || new Error('Squid exited with '+c)
}
if (hadError) throw hadError
})
setTimeout(function F () {
if (!ready) return setTimeout(F, 100)
request({ uri: 'https://registry.npmjs.org/request/'
, proxy: 'http://localhost:3128'
, ca: ca
, json: true }, function (er, body) {
hadError = er
console.log(er || typeof body)
if (!er) console.log("ok")
squid.kill('SIGKILL')
})
}, 100)