1 // test that we can tunnel a https request over an http proxy
2 // keeping all the CA and whatnot intact.
4 // Note: this requires that squid is installed.
5 // If the proxy fails to start, we'll just log a warning and assume success.
7 var server = require('./server')
8 , assert = require('assert')
9 , request = require('../main.js')
11 , path = require('path')
12 , caFile = path.resolve(__dirname, 'ssl/npm-ca.crt')
13 , ca = fs.readFileSync(caFile)
14 , child_process = require('child_process')
15 , sqConf = path.resolve(__dirname, 'squid.conf')
16 , sqArgs = ['-f', sqConf, '-N', '-d', '5']
17 , proxy = 'http://localhost:3128'
20 var squid = child_process.spawn('squid', sqArgs);
23 squid.stderr.on('data', function (c) {
24 console.error('SQUIDERR ' + c.toString().trim().split('\n')
26 ready = c.toString().match(/ready to serve requests/i)
29 squid.stdout.on('data', function (c) {
30 console.error('SQUIDOUT ' + c.toString().trim().split('\n')
34 squid.on('exit', function (c) {
35 console.error('squid: exit '+c)
37 console.error('squid must be installed to run this test.')
38 console.error('skipping this test. please install squid and run again if you need to test tunneling.')
46 hadError = hadError || new Error('Squid exited with '+c)
48 if (hadError) throw hadError
51 setTimeout(function F () {
52 if (!ready) return setTimeout(F, 100)
53 request({ uri: 'https://registry.npmjs.org/'
54 , proxy: 'http://localhost:3128'
57 , json: true }, function (er, body) {
59 console.log(er || typeof body)
60 if (!er) console.log("ok")