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 <marcoippolito54@gmail.com>
Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
  • Loading branch information
RafaelGSS committed Apr 13, 2023
1 parent 78c7475 commit 54d17ff
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 54d17ff

Please sign in to comment.