Skip to content

Commit 6b33002

Browse files
Sylphy-0xd3acSylphy-0xd3ac
authored andcommitted
test: Add glob test for restricted directory
Add a new test case in test-fs-glob.mjs to verify that glob does not throw errors when used in a restricted directory. Also delete the test-fs-readdir-error-handling.mjs file as its functionality is now covered by the new test.
1 parent 817b3fe commit 6b33002

File tree

2 files changed

+20
-31
lines changed

2 files changed

+20
-31
lines changed

test/parallel/test-fs-glob.mjs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as common from '../common/index.mjs';
22
import tmpdir from '../common/tmpdir.js';
33
import { resolve, dirname, sep, relative, join, isAbsolute } from 'node:path';
44
import { mkdir, writeFile, symlink, glob as asyncGlob } from 'node:fs/promises';
5-
import { glob, globSync, Dirent } from 'node:fs';
5+
import { glob, globSync, chmodSync, Dirent } from 'node:fs';
66
import { test, describe } from 'node:test';
77
import { pathToFileURL } from 'node:url';
88
import { promisify } from 'node:util';
@@ -518,3 +518,22 @@ describe('fsPromises glob - exclude', function() {
518518
});
519519
}
520520
});
521+
522+
describe('glob - with restricted directory', function() {
523+
test('*', async () => {
524+
const restrictedDir = tmpdir.resolve('restricted');
525+
await mkdir(restrictedDir, { recursive: true });
526+
chmodSync(restrictedDir, 0o000);
527+
try {
528+
const results = [];
529+
for await (const match of asyncGlob('*', { cwd: restrictedDir })) {
530+
results.push(match);
531+
}
532+
assert.ok(true, 'glob completed without throwing on readdir error');
533+
} finally {
534+
try {
535+
chmodSync(restrictedDir, 0o755);
536+
} catch {}
537+
}
538+
});
539+
});

test/parallel/test-fs-readdir-error-handling.mjs

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)