node/test/parallel/test-strace-openat-openssl.js
Richard Lau 46d12d826f
test: skip strace test with shared openssl
`parallel/test-strace-openat-openssl` was added to check explicitly
for a list of known files that would be opened for a set workload
(`require("crypto")`). This is not reliable when Node.js is linked
to an external/shared OpenSSL library (e.g. it might be configured
to load configuration files from a different default location and/or
load more than one configuration file) so skip this test when Node.js
is built in that way.

PR-URL: https://github.com/nodejs/node/pull/61987
Fixes: https://github.com/nodejs/node/issues/61966
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
2026-02-28 12:17:18 +01:00

68 lines
1.9 KiB
JavaScript

'use strict';
const common = require('../common');
const { spawn, spawnSync } = require('node:child_process');
const { createInterface } = require('node:readline');
const assert = require('node:assert');
if (!common.hasCrypto)
common.skip('missing crypto');
if (!common.isLinux)
common.skip('linux only');
if (common.isASan)
common.skip('strace does not work well with address sanitizer builds');
if (process.config.variables.node_shared_openssl) {
common.skip('external shared openssl may open other files');
}
if (spawnSync('strace').error !== undefined) {
common.skip('missing strace');
}
{
const allowedOpenCalls = new Set([
'/etc/ssl/openssl.cnf',
]);
const syscalls = ['openat'];
if (process.arch !== 'riscv64' && process.arch !== 'riscv32') {
syscalls.push('open');
}
const strace = spawn('strace', [
'-f', '-ff',
'-e', `trace=${syscalls.join(',')}`,
'-s', '512',
'-D', process.execPath, '-e', 'require("crypto")',
]);
// stderr is the default for strace
const rl = createInterface({ input: strace.stderr });
rl.on('line', (line) => {
if (!line.startsWith('open')) {
return;
}
const file = line.match(/"(.*?)"/)[1];
// skip .so reading attempt
if (file.match(/.+\.so(\.?)/) !== null) {
return;
}
// skip /proc/*
if (file.match(/\/proc\/.+/) !== null) {
return;
}
assert(allowedOpenCalls.delete(file), `${file} is not in the list of allowed openat calls`);
});
const debugOutput = [];
strace.stderr.setEncoding('utf8');
strace.stderr.on('data', (chunk) => {
debugOutput.push(chunk.toString());
});
strace.on('error', common.mustNotCall());
strace.on('exit', common.mustCall((code) => {
assert.strictEqual(code, 0, debugOutput);
const missingKeys = Array.from(allowedOpenCalls.keys());
if (missingKeys.length) {
assert.fail(`The following openat call are missing: ${missingKeys.join(',')}`);
}
}));
}