mirror of
https://github.com/nodejs/node.git
synced 2025-05-02 22:16:31 +00:00

Adds a new `../common/fixtures' module to begin normalizing `test/fixtures` use. Our test code is a bit inconsistent with regards to use of the fixtures directory. Some code uses `path.join()`, some code uses string concats, some other code uses template strings, etc. In mnay cases, significant duplication of code is seen when accessing fixture files, etc. This updates many (but by no means all) of the tests in the test suite to use the new consistent API. There are still many more to update, which would make an excelent Code-n-Learn exercise. PR-URL: https://github.com/nodejs/node/pull/14332 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Michaël Zasso <targos@protonmail.com>
66 lines
1.5 KiB
JavaScript
66 lines
1.5 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
|
|
const assert = require('assert');
|
|
const tls = require('tls');
|
|
const stream = require('stream');
|
|
const net = require('net');
|
|
const fixtures = require('../common/fixtures');
|
|
|
|
const options = { key: fixtures.readSync('test_key.pem'),
|
|
cert: fixtures.readSync('test_cert.pem'),
|
|
ca: [ fixtures.readSync('test_ca.pem') ],
|
|
ciphers: 'AES256-GCM-SHA384' };
|
|
const content = 'hello world';
|
|
const recv_bufs = [];
|
|
let send_data = '';
|
|
const server = tls.createServer(options, function(s) {
|
|
s.on('data', function(c) {
|
|
recv_bufs.push(c);
|
|
});
|
|
});
|
|
server.listen(0, function() {
|
|
const raw = net.connect(this.address().port);
|
|
|
|
let pending = false;
|
|
raw.on('readable', function() {
|
|
if (pending)
|
|
p._read();
|
|
});
|
|
|
|
const p = new stream.Duplex({
|
|
read: function read() {
|
|
pending = false;
|
|
|
|
const chunk = raw.read();
|
|
if (chunk) {
|
|
this.push(chunk);
|
|
} else {
|
|
pending = true;
|
|
}
|
|
},
|
|
write: function write(data, enc, cb) {
|
|
raw.write(data, enc, cb);
|
|
}
|
|
});
|
|
|
|
const socket = tls.connect({
|
|
socket: p,
|
|
rejectUnauthorized: false
|
|
}, function() {
|
|
for (let i = 0; i < 50; ++i) {
|
|
socket.write(content);
|
|
send_data += content;
|
|
}
|
|
socket.end();
|
|
server.close();
|
|
});
|
|
});
|
|
|
|
process.on('exit', function() {
|
|
const recv_data = (Buffer.concat(recv_bufs)).toString();
|
|
assert.strictEqual(send_data, recv_data);
|
|
});
|