Skip to content

Commit 1208513

Browse files
committed
test: include strace openat test
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
1 parent 22a2ec6 commit 1208513

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

t.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const { ReadableStream } = require('node:stream/web')
2+
3+
async function main() {
4+
const stream = new ReadableStream({
5+
start(controller) {
6+
controller.close();
7+
},
8+
});
9+
10+
const reader = stream.getReader();
11+
12+
await reader.closed;
13+
reader.releaseLock(); // the error is created here
14+
try {
15+
await reader.closed; // this should throw the invalid state error
16+
} catch(e) {
17+
console.log(e)
18+
}
19+
}
20+
21+
let debug
22+
23+
async function main2() {
24+
const stream = new ReadableStream({
25+
start(controller) {
26+
controller.close();
27+
},
28+
});
29+
30+
const reader = stream.getReader();
31+
32+
await reader.closed;
33+
reader.releaseLock(); // the error is created here
34+
try {
35+
await reader.closed; // this should throw the invalid state error
36+
} catch(e) {
37+
debug = e.stack
38+
console.log(e)
39+
}
40+
41+
debugger
42+
}
43+
44+
main().then(main2)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const { spawn, spawnSync } = require('node:child_process');
5+
const { createInterface } = require('node:readline');
6+
const assert = require('node:assert');
7+
8+
if (!common.hasCrypto)
9+
common.skip('missing crypto');
10+
if (!common.isLinux)
11+
common.skip('linux only');
12+
if (spawnSync('strace', ['-V']).status !== 0) {
13+
common.skip('missing strace');
14+
}
15+
16+
{
17+
const allowedOpenCalls = new Set([
18+
'/etc/ssl/openssl.cnf',
19+
]);
20+
const strace = spawn('strace', [
21+
'-f', '-ff',
22+
'-e', 'trace=open,openat',
23+
'-s', '512',
24+
'-D', process.execPath, '-e', 'require("crypto")',
25+
]);
26+
27+
// stderr is the default for strace
28+
const rl = createInterface({ input: strace.stderr });
29+
rl.on('line', (line) => {
30+
if (!line.startsWith('open')) {
31+
return;
32+
}
33+
34+
const file = line.match(/"(.*?)"/)[1];
35+
// skip .so reading attempt
36+
if (file.match(/.+\.so(\.?)/) !== null) {
37+
return;
38+
}
39+
assert(allowedOpenCalls.delete(file), `${file} is not in the list of allowed openat calls`);
40+
});
41+
42+
strace.on('error', common.mustNotCall());
43+
strace.on('exit', common.mustCall((code) => {
44+
assert.strictEqual(code, 0);
45+
const missingKeys = Array.from(allowedOpenCalls.keys());
46+
if (missingKeys.length) {
47+
assert.fail(`The following openat call are missing: ${missingKeys.join(',')}`);
48+
}
49+
}));
50+
}

0 commit comments

Comments
 (0)