GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: make tls-socket-default-options tests run · nodejs/node@861fa65

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/parallel
    • test-tls-socket-default-options.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/parallel/test-tls-socket-default-options.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-tls-socket-default-options.js
+50-46Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,59 @@
11
'use strict';
22
const common = require('../common');
3+
4+
// Test a directly created TLS socket supports no options, and empty options.
5+
36
const assert = require('assert');
7+
const join = require('path').join;
8+
const {
9+
connect, keys, tls
10+
} = require(join(common.fixturesDir, 'tls-connect'));
411

512
if (!common.hasCrypto) {
613
common.skip('missing crypto');
7-
return;
8-
}
9-
const tls = require('tls');
10-
11-
const fs = require('fs');
12-
13-
const sent = 'hello world';
14-
15-
const serverOptions = {
16-
isServer: true,
17-
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
18-
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
19-
};
20-
21-
function testSocketOptions(socket, socketOptions) {
22-
let received = '';
23-
const server = tls.createServer(serverOptions, function(s) {
24-
s.on('data', function(chunk) {
25-
received += chunk;
26-
});
27-
28-
s.on('end', function() {
29-
server.close();
30-
s.destroy();
31-
assert.strictEqual(received, sent);
32-
setImmediate(runTests);
33-
});
34-
}).listen(0, function() {
35-
const c = new tls.TLSSocket(socket, socketOptions);
36-
c.connect(this.address().port, function() {
37-
c.end(sent);
38-
});
39-
});
40-
14+
process.exit(0);
4115
}
4216

43-
const testArgs = [
44-
[],
45-
[undefined, {}]
46-
];
47-
48-
let n = 0;
49-
function runTests() {
50-
if (n++ < testArgs.length) {
51-
testSocketOptions.apply(null, testArgs[n]);
52-
}
17+
test(undefined, (err) => {
18+
assert.strictEqual(err.message, 'unable to verify the first certificate');
19+
});
20+
21+
test({}, (err) => {
22+
assert.strictEqual(err.message, 'unable to verify the first certificate');
23+
});
24+
25+
test({secureContext: tls.createSecureContext({ca: keys.agent1.ca})}, (err) => {
26+
assert.ifError(err);
27+
});
28+
29+
function test(client, callback) {
30+
callback = common.mustCall(callback);
31+
connect({
32+
server: {
33+
key: keys.agent1.key,
34+
cert: keys.agent1.cert,
35+
},
36+
}, function(err, pair, cleanup) {
37+
assert.strictEqual(err.message, 'unable to verify the first certificate');
38+
let recv = '';
39+
pair.server.server.once('secureConnection', common.mustCall((conn) => {
40+
conn.on('data', (data) => recv += data);
41+
conn.on('end', common.mustCall(() => {
42+
// Server sees nothing wrong with connection, even though the client's
43+
// authentication of the server cert failed.
44+
assert.strictEqual(recv, 'hello');
45+
cleanup();
46+
}));
47+
}));
48+
49+
// Client doesn't support the 'secureConnect' event, and doesn't error if
50+
// authentication failed. Caller must explicitly check for failure.
51+
(new tls.TLSSocket(null, client)).connect(pair.server.server.address().port)
52+
.on('connect', common.mustCall(function() {
53+
this.end('hello');
54+
}))
55+
.on('secure', common.mustCall(function() {
56+
callback(this.ssl.verifyError());
57+
}));
58+
});
5359
}
54-
55-
runTests();

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.