MCPcopy Index your code
hub / github.com/nodejs/node / test

Function test

test/parallel/test-tls-set-ciphers.js:26–88  ·  view source on GitHub ↗
(cciphers, sciphers, cipher, cerr, serr, options)

Source from the content-addressed store, hash-verified

24
25
26function test(cciphers, sciphers, cipher, cerr, serr, options) {
27 assert(cipher || cerr || serr, 'test missing any expectations');
28 const where = inspect(new Error()).split('\n')[2].replace(/[^(]*/, '');
29
30 const max_tls_ver = (ciphers, options) => {
31 if (options instanceof Object && Object.hasOwn(options, 'maxVersion'))
32 return options.maxVersion;
33 if ((typeof ciphers === 'string' || ciphers instanceof String) && ciphers.length > 0 && !ciphers.includes('TLS_'))
34 return 'TLSv1.2';
35
36 return 'TLSv1.3';
37 };
38
39 connect({
40 client: {
41 checkServerIdentity: (servername, cert) => { },
42 ca: `${keys.agent1.cert}\n${keys.agent6.ca}`,
43 ciphers: cciphers,
44 maxVersion: max_tls_ver(cciphers, options),
45 },
46 server: {
47 cert: keys.agent6.cert,
48 key: keys.agent6.key,
49 ciphers: sciphers,
50 maxVersion: max_tls_ver(sciphers, options),
51 },
52 }, common.mustCall((err, pair, cleanup) => {
53 function u(_) { return _ === undefined ? 'U' : _; }
54 console.log('test:', u(cciphers), u(sciphers),
55 'expect', u(cipher), u(cerr), u(serr));
56 console.log(' ', where);
57 if (!cipher) {
58 console.log('client', pair.client.err ? pair.client.err.code : undefined);
59 console.log('server', pair.server.err ? pair.server.err.code : undefined);
60 if (cerr) {
61 assert(pair.client.err);
62 assert.strictEqual(pair.client.err.code, cerr);
63 }
64 if (serr) {
65 assert(pair.server.err);
66 assert.strictEqual(pair.server.err.code, serr);
67 }
68 return cleanup();
69 }
70
71 const reply = 'So long and thanks for all the fish.';
72
73 assert.ifError(err);
74 assert.ifError(pair.server.err);
75 assert.ifError(pair.client.err);
76 assert(pair.server.conn);
77 assert(pair.client.conn);
78 assert.strictEqual(pair.client.conn.getCipher().name, cipher);
79 assert.strictEqual(pair.server.conn.getCipher().name, cipher);
80
81 pair.server.conn.write(reply);
82
83 pair.client.conn.on('data', common.mustCall((data) => {

Callers 1

Calls 11

max_tls_verFunction · 0.85
inspectFunction · 0.70
connectFunction · 0.70
uFunction · 0.70
cleanupFunction · 0.70
assertFunction · 0.50
splitMethod · 0.45
logMethod · 0.45
writeMethod · 0.45
onMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected