downloadoptions.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. var assert = require('assert').strict,
  2. ua = require('../scripts/util/useragent'),
  3. opts = require('../scripts/util/downloadoptions');
  4. describe('util', function() {
  5. describe('downloadoptions', function() {
  6. describe('without a proxy', function() {
  7. it('should look as we expect', function() {
  8. var expected = {
  9. rejectUnauthorized: true,
  10. timeout: 60000,
  11. headers: {
  12. 'User-Agent': ua(),
  13. },
  14. encoding: null,
  15. };
  16. assert.deepStrictEqual(opts(), expected);
  17. });
  18. });
  19. describe('with an npm config proxy', function() {
  20. var proxy = 'http://test.proxy:1234';
  21. before(function() {
  22. process.env.npm_config_proxy = proxy;
  23. });
  24. after(function() {
  25. delete process.env.npm_config_proxy;
  26. });
  27. it('should look as we expect', function() {
  28. var expected = {
  29. rejectUnauthorized: true,
  30. proxy: proxy,
  31. timeout: 60000,
  32. headers: {
  33. 'User-Agent': ua(),
  34. },
  35. encoding: null,
  36. };
  37. assert.deepStrictEqual(opts(), expected);
  38. });
  39. });
  40. describe('with an env proxy proxy', function() {
  41. var proxy = 'http://test.proxy:1234';
  42. before(function() {
  43. process.env.HTTP_PROXY = proxy;
  44. });
  45. after(function() {
  46. delete process.env.HTTP_PROXY;
  47. });
  48. it('should look as we expect', function() {
  49. var expected = {
  50. rejectUnauthorized: true,
  51. timeout: 60000,
  52. headers: {
  53. 'User-Agent': ua(),
  54. },
  55. encoding: null,
  56. };
  57. assert.deepStrictEqual(opts(), expected);
  58. });
  59. });
  60. describe('with SASS_REJECT_UNAUTHORIZED set to false', function() {
  61. beforeEach(function() {
  62. process.env.SASS_REJECT_UNAUTHORIZED = '0';
  63. });
  64. it('should look as we expect', function() {
  65. var expected = {
  66. rejectUnauthorized: false,
  67. timeout: 60000,
  68. headers: {
  69. 'User-Agent': ua(),
  70. },
  71. encoding: null,
  72. };
  73. assert.deepStrictEqual(opts(), expected);
  74. });
  75. });
  76. describe('with SASS_REJECT_UNAUTHORIZED set to true', function() {
  77. beforeEach(function() {
  78. process.env.SASS_REJECT_UNAUTHORIZED = '1';
  79. });
  80. it('should look as we expect', function() {
  81. var expected = {
  82. rejectUnauthorized: true,
  83. timeout: 60000,
  84. headers: {
  85. 'User-Agent': ua(),
  86. },
  87. encoding: null,
  88. };
  89. assert.deepStrictEqual(opts(), expected);
  90. });
  91. });
  92. describe('with npm_config_sass_reject_unauthorized set to true', function() {
  93. beforeEach(function() {
  94. process.env.npm_config_sass_reject_unauthorized = true;
  95. });
  96. it('should look as we expect', function() {
  97. var expected = {
  98. rejectUnauthorized: true,
  99. timeout: 60000,
  100. headers: {
  101. 'User-Agent': ua(),
  102. },
  103. encoding: null,
  104. };
  105. assert.deepStrictEqual(opts(), expected);
  106. });
  107. afterEach(function() {
  108. process.env.npm_config_sass_reject_unauthorized = undefined;
  109. });
  110. });
  111. });
  112. });