tls_options_spec.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. var needle = require('..'),
  2. https = require('https'),
  3. helpers = require('./helpers'),
  4. should = require('should');
  5. describe('tls options', function() {
  6. describe('rejectUnauthorized: false', function() {
  7. var url = 'https://expired-rsa-dv.ssl.com/';
  8. it('is an expired cert', function(done) {
  9. needle.get(url, function(err, resp) {
  10. err.code.should.eql('CERT_HAS_EXPIRED')
  11. should.not.exist(resp)
  12. done()
  13. })
  14. })
  15. it('allows fetching pages under expired certificates', function(done) {
  16. needle.get(url, { rejectUnauthorized: false }, function(err, resp) {
  17. should.not.exist(err);
  18. resp.statusCode.should.eql(200);
  19. done()
  20. })
  21. })
  22. it('also works when using custom agent', function(done) {
  23. var agent = new https.Agent({ rejectUnauthorized: true })
  24. // should overwrite value from custom agent
  25. needle.get(url, { rejectUnauthorized: false }, function(err, resp) {
  26. should.not.exist(err);
  27. resp.statusCode.should.eql(200);
  28. done()
  29. })
  30. })
  31. it('also works with shared/default agent', function(done) {
  32. var agent = new https.Agent({ rejectUnauthorized: true })
  33. needle.defaults({ agent: agent })
  34. // should overwrite value from custom agent
  35. needle.get(url, { rejectUnauthorized: false }, function(err, resp) {
  36. should.not.exist(err);
  37. resp.statusCode.should.eql(200);
  38. needle.defaults({ agent: null })
  39. done()
  40. })
  41. })
  42. })
  43. })