utils_spec.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. var helpers = require('./helpers'),
  2. should = require('should'),
  3. sinon = require('sinon'),
  4. utils = require('./../lib/utils');
  5. describe('utils.should_proxy_to()', function() {
  6. var should_proxy_to = utils.should_proxy_to;
  7. var noProxy = ".ic1.mycorp,localhost,127.0.0.1,*.mycorp.org";
  8. var noProxyWithPorts = " ,.mycorp.org:1234,.ic1.mycorp,localhost,127.0.0.1";
  9. var uris = {
  10. hostname: "http://registry.random.opr.mycorp.org",
  11. with_port: "http://registry.random.opr.mycorp.org:9874",
  12. with_another_port: "http://registry.random.opr.mycorp.org:1234",
  13. localhost: "http://localhost",
  14. ip: "http://127.0.0.1"
  15. }
  16. it("returns true if NO_PROXY is undefined", function(done) {
  17. process.env.NO_PROXY = undefined;
  18. should_proxy_to(uris.hostname).should.true()
  19. delete process.env.NO_PROXY;
  20. done();
  21. });
  22. it("returns true if NO_PROXY is empty", function(done) {
  23. process.env.NO_PROXY = "";
  24. should_proxy_to(uris.hostname).should.true()
  25. delete process.env.NO_PROXY;
  26. done();
  27. });
  28. it("returns false if NO_PROXY is a wildcard", function(done) {
  29. process.env.NO_PROXY = "*";
  30. should_proxy_to(uris.hostname).should.false()
  31. delete process.env.NO_PROXY;
  32. done();
  33. });
  34. it("returns true if the host matches and the ports don't (URI doesn't have port specified)", function(done) {
  35. process.env.NO_PROXY = noProxyWithPorts;
  36. should_proxy_to(uris.hostname).should.true()
  37. delete process.env.NO_PROXY;
  38. done();
  39. });
  40. it("returns true if the host matches and the ports don't (both have a port specified but just different values)", function(done) {
  41. process.env.NO_PROXY = noProxyWithPorts;
  42. should_proxy_to(uris.with_port).should.true()
  43. delete process.env.NO_PROXY;
  44. done();
  45. });
  46. it("returns false if the host matches and the ports don't (no_proxy pattern doesn't have a port)", function(done) {
  47. process.env.NO_PROXY = noProxy;
  48. should_proxy_to(uris.with_port).should.false()
  49. delete process.env.NO_PROXY;
  50. done();
  51. });
  52. it("returns false if host matches", function(done) {
  53. process.env.NO_PROXY = noProxy;
  54. should_proxy_to(uris.hostname).should.false()
  55. delete process.env.NO_PROXY;
  56. done();
  57. });
  58. it("returns false if the host and port matches", function(done) {
  59. process.env.NO_PROXY = noProxyWithPorts;
  60. should_proxy_to(uris.with_another_port).should.false()
  61. delete process.env.NO_PROXY;
  62. done();
  63. });
  64. it("returns false if the host matches (localhost)", function(done) {
  65. process.env.NO_PROXY = noProxy;
  66. should_proxy_to(uris.localhost).should.false()
  67. delete process.env.NO_PROXY;
  68. done();
  69. });
  70. it("returns false if the host matches (ip)", function(done) {
  71. process.env.NO_PROXY = noProxy;
  72. should_proxy_to(uris.ip).should.false()
  73. delete process.env.NO_PROXY;
  74. done();
  75. });
  76. it("returns false if the host matches (ip)", function(done) {
  77. process.env.NO_PROXY = noProxy.replace(/,g/, " ");
  78. should_proxy_to(uris.ip).should.false()
  79. delete process.env.NO_PROXY;
  80. done();
  81. });
  82. it("returns false if the host matches (ip)", function(done) {
  83. process.env.NO_PROXY = noProxy.replace(/,g/, " ");
  84. should_proxy_to(uris.ip).should.false()
  85. delete process.env.NO_PROXY;
  86. done();
  87. });
  88. })