Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

62 righe
1.7 KiB

  1. // test that we can tunnel a https request over an http proxy
  2. // keeping all the CA and whatnot intact.
  3. //
  4. // Note: this requires that squid is installed.
  5. // If the proxy fails to start, we'll just log a warning and assume success.
  6. var server = require('./server')
  7. , assert = require('assert')
  8. , request = require('../main.js')
  9. , fs = require('fs')
  10. , path = require('path')
  11. , caFile = path.resolve(__dirname, 'ssl/npm-ca.crt')
  12. , ca = fs.readFileSync(caFile)
  13. , child_process = require('child_process')
  14. , sqConf = path.resolve(__dirname, 'squid.conf')
  15. , sqArgs = ['-f', sqConf, '-N', '-d', '5']
  16. , proxy = 'http://localhost:3128'
  17. , hadError = null
  18. var squid = child_process.spawn('squid', sqArgs);
  19. var ready = false
  20. squid.stderr.on('data', function (c) {
  21. console.error('SQUIDERR ' + c.toString().trim().split('\n')
  22. .join('\nSQUIDERR '))
  23. ready = c.toString().match(/ready to serve requests/i)
  24. })
  25. squid.stdout.on('data', function (c) {
  26. console.error('SQUIDOUT ' + c.toString().trim().split('\n')
  27. .join('\nSQUIDOUT '))
  28. })
  29. squid.on('exit', function (c) {
  30. console.error('exit '+c)
  31. if (c && !ready) {
  32. console.error('squid must be installed to run this test.')
  33. c = null
  34. hadError = null
  35. process.exit(0)
  36. return
  37. }
  38. if (c) {
  39. hadError = hadError || new Error('Squid exited with '+c)
  40. }
  41. if (hadError) throw hadError
  42. })
  43. setTimeout(function F () {
  44. if (!ready) return setTimeout(F, 100)
  45. request({ uri: 'https://registry.npmjs.org/request/'
  46. , proxy: 'http://localhost:3128'
  47. , ca: ca
  48. , json: true }, function (er, body) {
  49. hadError = er
  50. console.log(er || typeof body)
  51. if (!er) console.log("ok")
  52. squid.kill('SIGKILL')
  53. })
  54. }, 100)