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('../index')
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|Accepting HTTP Socket connections/i)
29
squid.stdout.on('data', function (c) {
30
console.error('SQUIDOUT ' + c.toString().trim().split('\n')
34
squid.on('error', function (c) {
35
console.error('squid: error '+c)
42
squid.on('exit', function (c) {
43
console.error('squid: exit '+c)
50
hadError = hadError || new Error('Squid exited with '+c)
52
if (hadError) throw hadError
55
setTimeout(function F () {
56
if (!ready) return setTimeout(F, 100)
57
request({ uri: 'https://registry.npmjs.org/'
58
, proxy: 'http://localhost:3128'
61
, json: true }, function (er, body) {
63
console.log(er || typeof body)
64
if (!er) console.log("ok")
69
function notInstalled() {
70
console.error('squid must be installed to run this test.')
71
console.error('skipping this test. please install squid and run again if you need to test tunneling.')