proxy.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. var assert = require('assert').strict,
  2. proxy = require('../../../scripts/util/proxy');
  3. describe('proxy', function() {
  4. var oldEnvironment;
  5. beforeEach(function() {
  6. oldEnvironment = process.env;
  7. });
  8. afterEach(function() {
  9. process.env = oldEnvironment;
  10. });
  11. describe('without an npm proxy config', function() {
  12. delete process.env.npm_config_https_proxy;
  13. delete process.env.npm_config_proxy;
  14. delete process.env.npm_config_http_proxy;
  15. it('should return an empty string', function() {
  16. assert.strictEqual('', proxy());
  17. });
  18. it('should ignore system proxy environment variables', function() {
  19. process.env.HTTPS_PROXY = 'http://https_proxy.com';
  20. process.env.PROXY = 'http://proxy.com';
  21. process.env.HTTP_PROXY = 'http://http_proxy.com';
  22. assert.strictEqual('', proxy());
  23. });
  24. });
  25. describe('with an npm proxy config', function() {
  26. beforeEach(function() {
  27. process.env.npm_config_https_proxy = 'http://https_proxy.com';
  28. process.env.npm_config_proxy = 'http://proxy.com';
  29. process.env.npm_config_http_proxy = 'http://http_proxy.com';
  30. });
  31. describe('https_proxy', function() {
  32. it('should have the highest precedence', function() {
  33. assert.strictEqual(process.env.npm_config_https_proxy, proxy());
  34. });
  35. });
  36. describe('proxy', function() {
  37. it('should have the higher precedence than https_proxy', function() {
  38. assert.strictEqual(process.env.npm_config_https_proxy, proxy());
  39. delete process.env.npm_config_https_proxy;
  40. assert.strictEqual(process.env.npm_config_proxy, proxy());
  41. });
  42. it('should have the lower precedence than http_proxy', function() {
  43. delete process.env.npm_config_https_proxy;
  44. assert.strictEqual(process.env.npm_config_proxy, proxy());
  45. delete process.env.npm_config_proxy;
  46. assert.strictEqual(process.env.npm_config_http_proxy, proxy());
  47. });
  48. });
  49. describe('http_proxy', function() {
  50. it('should have the lowest precedence', function() {
  51. assert.strictEqual(process.env.npm_config_https_proxy, proxy());
  52. delete process.env.npm_config_https_proxy;
  53. assert.strictEqual(process.env.npm_config_proxy, proxy());
  54. delete process.env.npm_config_proxy;
  55. assert.strictEqual(process.env.npm_config_http_proxy, proxy());
  56. });
  57. });
  58. });
  59. });