~webapps/unity-js-scopes/node.js

« back to all changes in this revision

Viewing changes to test/parallel/test-tls-peer-certificate-multi-keys.js

  • Committer: Marcus Tomlinson
  • Date: 2015-11-13 07:59:04 UTC
  • Revision ID: marcus.tomlinson@canonical.com-20151113075904-h0swczmoq1rvstfc
Node v4 (stable)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
'use strict';
 
2
var common = require('../common');
 
3
var assert = require('assert');
 
4
 
 
5
if (!common.hasCrypto) {
 
6
  console.log('1..0 # Skipped: missing crypto');
 
7
  return;
 
8
}
 
9
var tls = require('tls');
 
10
 
 
11
var fs = require('fs');
 
12
var util = require('util');
 
13
var join = require('path').join;
 
14
var spawn = require('child_process').spawn;
 
15
 
 
16
var options = {
 
17
  key: fs.readFileSync(join(common.fixturesDir, 'agent.key')),
 
18
  cert: fs.readFileSync(join(common.fixturesDir, 'multi-alice.crt'))
 
19
};
 
20
var verified = false;
 
21
 
 
22
var server = tls.createServer(options, function(cleartext) {
 
23
  cleartext.end('World');
 
24
});
 
25
server.listen(common.PORT, function() {
 
26
  var socket = tls.connect({
 
27
    port: common.PORT,
 
28
    rejectUnauthorized: false
 
29
  }, function() {
 
30
    var peerCert = socket.getPeerCertificate();
 
31
    common.debug(util.inspect(peerCert));
 
32
    assert.deepEqual(peerCert.subject.OU,
 
33
                     ['Information Technology', 'Engineering', 'Marketing']);
 
34
    verified = true;
 
35
    server.close();
 
36
  });
 
37
  socket.end('Hello');
 
38
});
 
39
 
 
40
process.on('exit', function() {
 
41
  assert.ok(verified);
 
42
});