Skip to content

Commit

Permalink
test: include strace openat test
Browse files Browse the repository at this point in the history
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
  • Loading branch information
RafaelGSS committed Jan 30, 2023
1 parent 22a2ec6 commit 3cc256f
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions test/parallel/test-strace-openat-openssl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
'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 (spawnSync('strace', ['-V']).status !== 0) {
common.skip('missing strace');
}

{
const allowedOpenCalls = new Set([
'/etc/ssl/openssl.cnf',
]);
const strace = spawn('strace', [
'-f', '-ff',
'-e', 'trace=open,openat',
'-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`);
});

strace.on('error', common.mustNotCall());
strace.on('exit', common.mustCall((code) => {
assert.strictEqual(code, 0);
const missingKeys = Array.from(allowedOpenCalls.keys());
if (missingKeys.length) {
assert.fail(`The following openat call are missing: ${missingKeys.join(',')}`);
}
}));
}

0 comments on commit 3cc256f

Please sign in to comment.