Files
node/test/parallel/test-permission-has-reference-types.js
T
Seungmin Nam c4336d90c0 permission: support URL and Uint8Array as has()/drop() reference
normalizeReference() adds URL and Uint8Array support to has()/drop();
the existing string/Buffer behavior is unchanged. BufferValue replaces
Utf8Value so a Buffer/TypedArray reference is copied as raw bytes
instead of a lossy UTF-8 conversion.

Signed-off-by: seungmin Nam <nhjbest22@g.skku.edu>
PR-URL: https://github.com/nodejs/node/pull/65492
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2026-08-31 14:59:47 +00:00

49 lines
1.2 KiB
JavaScript

'use strict';
// Test that process.permission.has()/drop() accept a URL or Uint8Array reference.
require('../common');
const { spawnSync } = require('child_process');
const assert = require('assert');
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
process.exit(0);
}
const tmpdir = require('../common/tmpdir');
const fixtures = require('../common/fixtures');
const fs = require('fs');
const path = require('path');
tmpdir.refresh();
const allowedDir = path.join(tmpdir.path, 'allowed');
const deniedDir = path.join(tmpdir.path, 'denied');
fs.mkdirSync(allowedDir);
fs.mkdirSync(deniedDir);
const allowedFile = path.join(allowedDir, 'a.txt');
const deniedFile = path.join(deniedDir, 'b.txt');
fs.writeFileSync(allowedFile, 'allowed');
fs.writeFileSync(deniedFile, 'denied');
const { status, stderr } = spawnSync(
process.execPath,
[
'--permission',
`--allow-fs-read=${allowedDir}`,
fixtures.path('permission', 'has-reference-types.js'),
],
{
env: {
...process.env,
ALLOWED_DIR: allowedDir,
ALLOWED_FILE: allowedFile,
DENIED_FILE: deniedFile,
},
},
);
assert.strictEqual(status, 0, stderr.toString());