summaryrefslogtreecommitdiff
path: root/test/parallel/test-fs-fchown.js
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2019-08-05 09:59:28 -0700
committerRich Trott <rtrott@gmail.com>2019-08-07 13:27:55 -0700
commitc072a807178230948ed40dea0708593663efa0cd (patch)
tree5f8cbf04de6d1870deddc696f0b2f70f8149fef3 /test/parallel/test-fs-fchown.js
parent84a638484ead2074625ab5198338bcaf784625c6 (diff)
downloadandroid-node-v8-c072a807178230948ed40dea0708593663efa0cd.tar.gz
android-node-v8-c072a807178230948ed40dea0708593663efa0cd.tar.bz2
android-node-v8-c072a807178230948ed40dea0708593663efa0cd.zip
fs: validate fds as int32s
This commit updates the JS layer's validation of file descriptors to check for int32s >= 0 instead of uint32s. PR-URL: https://github.com/nodejs/node/pull/28984 Fixes: https://github.com/nodejs/node/issues/28980 Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'test/parallel/test-fs-fchown.js')
-rw-r--r--test/parallel/test-fs-fchown.js31
1 files changed, 24 insertions, 7 deletions
diff --git a/test/parallel/test-fs-fchown.js b/test/parallel/test-fs-fchown.js
index 832dd071ea..4872e550db 100644
--- a/test/parallel/test-fs-fchown.js
+++ b/test/parallel/test-fs-fchown.js
@@ -4,13 +4,17 @@ require('../common');
const assert = require('assert');
const fs = require('fs');
-function test(input, errObj) {
+function testFd(input, errObj) {
assert.throws(() => fs.fchown(input), errObj);
assert.throws(() => fs.fchownSync(input), errObj);
- errObj.message = errObj.message.replace('fd', 'uid');
+}
+
+function testUid(input, errObj) {
assert.throws(() => fs.fchown(1, input), errObj);
assert.throws(() => fs.fchownSync(1, input), errObj);
- errObj.message = errObj.message.replace('uid', 'gid');
+}
+
+function testGid(input, errObj) {
assert.throws(() => fs.fchown(1, 1, input), errObj);
assert.throws(() => fs.fchownSync(1, 1, input), errObj);
}
@@ -22,7 +26,11 @@ function test(input, errObj) {
message: 'The "fd" argument must be of type number. Received type ' +
typeof input
};
- test(input, errObj);
+ testFd(input, errObj);
+ errObj.message = errObj.message.replace('fd', 'uid');
+ testUid(input, errObj);
+ errObj.message = errObj.message.replace('uid', 'gid');
+ testGid(input, errObj);
});
[Infinity, NaN].forEach((input) => {
@@ -32,7 +40,11 @@ function test(input, errObj) {
message: 'The value of "fd" is out of range. It must be an integer. ' +
`Received ${input}`
};
- test(input, errObj);
+ testFd(input, errObj);
+ errObj.message = errObj.message.replace('fd', 'uid');
+ testUid(input, errObj);
+ errObj.message = errObj.message.replace('uid', 'gid');
+ testGid(input, errObj);
});
[-1, 2 ** 32].forEach((input) => {
@@ -40,7 +52,12 @@ function test(input, errObj) {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
message: 'The value of "fd" is out of range. It must be ' +
- `>= 0 && < 4294967296. Received ${input}`
+ `>= 0 && <= 2147483647. Received ${input}`
};
- test(input, errObj);
+ testFd(input, errObj);
+ errObj.message = 'The value of "uid" is out of range. It must be >= 0 && ' +
+ `< 4294967296. Received ${input}`;
+ testUid(input, errObj);
+ errObj.message = errObj.message.replace('uid', 'gid');
+ testGid(input, errObj);
});