Skip to content

Commit 4b80a7b

Browse files
authored
permission: support fs.mkdtemp
PR-URL: #47470 Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
1 parent 63ee335 commit 4b80a7b

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/node_file.cc

+2
Original file line numberDiff line numberDiff line change
@@ -2678,6 +2678,8 @@ static void Mkdtemp(const FunctionCallbackInfo<Value>& args) {
26782678

26792679
BufferValue tmpl(isolate, args[0]);
26802680
CHECK_NOT_NULL(*tmpl);
2681+
THROW_IF_INSUFFICIENT_PERMISSIONS(
2682+
env, permission::PermissionScope::kFileSystemWrite, tmpl.ToStringView());
26812683

26822684
const enum encoding encoding = ParseEncoding(isolate, args[1], UTF8);
26832685

test/fixtures/permission/fs-write.js

+17
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,23 @@ const absoluteProtectedFolder = path.resolve(relativeProtectedFolder);
130130
}));
131131
}
132132

133+
{
134+
assert.throws(() => {
135+
fs.mkdtempSync(path.join(blockedFolder, 'any-folder'));
136+
}, common.expectsError({
137+
code: 'ERR_ACCESS_DENIED',
138+
permission: 'FileSystemWrite',
139+
}));
140+
assert.throws(() => {
141+
fs.mkdtemp(path.join(relativeProtectedFolder, 'any-folder'), (err) => {
142+
assert.ifError(err);
143+
});
144+
}, common.expectsError({
145+
code: 'ERR_ACCESS_DENIED',
146+
permission: 'FileSystemWrite',
147+
}));
148+
}
149+
133150
// fs.rename
134151
{
135152
assert.throws(() => {

0 commit comments

Comments
 (0)