Skip to content

Commit

Permalink
permission: support fs.mkdtemp
Browse files Browse the repository at this point in the history
PR-URL: #47470
Reviewed-By: Marco Ippolito <[email protected]>
Reviewed-By: Zeyu "Alex" Yang <[email protected]>
  • Loading branch information
RafaelGSS authored Apr 9, 2023
1 parent 63ee335 commit 4b80a7b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2678,6 +2678,8 @@ static void Mkdtemp(const FunctionCallbackInfo<Value>& args) {

BufferValue tmpl(isolate, args[0]);
CHECK_NOT_NULL(*tmpl);
THROW_IF_INSUFFICIENT_PERMISSIONS(
env, permission::PermissionScope::kFileSystemWrite, tmpl.ToStringView());

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

Expand Down
17 changes: 17 additions & 0 deletions test/fixtures/permission/fs-write.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,23 @@ const absoluteProtectedFolder = path.resolve(relativeProtectedFolder);
}));
}

{
assert.throws(() => {
fs.mkdtempSync(path.join(blockedFolder, 'any-folder'));
}, common.expectsError({
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemWrite',
}));
assert.throws(() => {
fs.mkdtemp(path.join(relativeProtectedFolder, 'any-folder'), (err) => {
assert.ifError(err);
});
}, common.expectsError({
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemWrite',
}));
}

// fs.rename
{
assert.throws(() => {
Expand Down

0 comments on commit 4b80a7b

Please sign in to comment.