Blame view

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