Blame view

node_modules/jayson/test/https.client-server.test.js 2.21 KB
f7563de62   Palak Handa   first commit
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
  var should = require('should');
  var fs = require('fs');
  var jayson = require(__dirname + '/..');
  var support = require('./support');
  var common = support.common;
  var http = require('http');
  var https = require('https');
  var url = require('url');
  
  var serverOptions = {
    ca: [fs.readFileSync('./test/fixtures/keys/ca1-cert.pem')],
    key: fs.readFileSync('./test/fixtures/keys/agent1-key.pem'),
    cert: fs.readFileSync('./test/fixtures/keys/agent1-cert.pem')
  };
  
  describe('Jayson.Https', function() {
  
    describe('server', function() {
  
      var server = null;
  
      after(function() {
        server.close();
      });
  
      it('should listen to a local port', function(done) {
          server = jayson.server(support.methods, support.options).https(serverOptions);
          server.listen(3000, 'localhost', done);
      });
  
      it('should be an instance of https.Server', function() {
        server.should.be.instanceof(https.Server);
      });
  
    });
  
    describe('client', function() {
      
      var server = jayson.server(support.server.methods, support.server.options);
      var server_https = server.https(serverOptions);
      var client = jayson.client.https({
        reviver: support.server.options.reviver,
        replacer: support.server.options.replacer,
        host: 'localhost',
        port: 3000,
        ca: serverOptions.ca
      });
  
      before(function(done) {
        server_https.listen(3000, 'localhost', done);
      });
  
      after(function() {
        server_https.close();
      });
  
      describe('common tests', common(client));
  
      it('should emit an event with the http response', function(done) {
        var hasFired = false;
  
        client.on('http response', function(res) {
          res.should.be.instanceof(http.IncomingMessage);
          hasFired = true;
        });
  
        client.request('add', [9, 4], function(err, response) {
          if(err) throw err;
          hasFired.should.be.ok;
          done();
        });
      });
  
      it('should accept a URL string as the first argument', function() {
        var urlStr = 'https://localhost:3000';
        var client = jayson.client.https(urlStr);
        var urlObj = url.parse(urlStr);
        Object.keys(urlObj).forEach(function(key) {
          client.options.should.have.property(key, urlObj[key]);
        });
      });
  
    });
  
  });