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>
PR-URL: #46150
Reviewed-By: Michael Dawson <midawson@redhat.com>
  • Loading branch information
RafaelGSS authored and danielleadams committed Apr 5, 2023
1 parent 7e08ca1 commit 3b70e7a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test-asan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ jobs:
CXX: clang++
LINK: clang++
CONFIG_FLAGS: --enable-asan
ASAN: true
steps:
- uses: actions/checkout@v3
with:
Expand Down
2 changes: 2 additions & 0 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ const isFreeBSD = process.platform === 'freebsd';
const isOpenBSD = process.platform === 'openbsd';
const isLinux = process.platform === 'linux';
const isOSX = process.platform === 'darwin';
const isAsan = process.env.ASAN !== undefined;
const isPi = (() => {
try {
// Normal Raspberry Pi detection is to find the `Raspberry Pi` string in
Expand Down Expand Up @@ -898,6 +899,7 @@ const common = {
invalidArgTypeHelper,
isAIX,
isAlive,
isAsan,
isDumbTerminal,
isFreeBSD,
isLinux,
Expand Down
61 changes: 61 additions & 0 deletions test/parallel/test-strace-openat-openssl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
'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 (spawnSync('strace').error !== undefined) {
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`);
});
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(',')}`);
}
}));
}

0 comments on commit 3b70e7a

Please sign in to comment.