diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2018-05-09 22:44:44 +0800 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2018-05-17 17:14:35 +0800 |
commit | a18e130e597c3efc1df7bd86198c2b5762d4fbae (patch) | |
tree | 584b4e8b5c5a67a3272f2e66646de497777e4dc4 /test/parallel/test-process-umask.js | |
parent | 0d9500daedbb61770359c34383a8d4784bcabd56 (diff) | |
download | node-new-a18e130e597c3efc1df7bd86198c2b5762d4fbae.tar.gz |
lib: mask mode_t type of arguments with 0o777
- Introduce the `validateAndMaskMode` validator that
validates `mode_t` arguments and mask them with 0o777
if they are 32-bit unsigned integer or octal string
to be more consistent with POSIX APIs.
- Use the validator in fs APIs and process.umask for
consistency.
- Add tests for 32-bit unsigned modes larger than 0o777.
PR-URL: https://github.com/nodejs/node/pull/20636
Fixes: https://github.com/nodejs/node/issues/20498
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Diffstat (limited to 'test/parallel/test-process-umask.js')
-rw-r--r-- | test/parallel/test-process-umask.js | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/test/parallel/test-process-umask.js b/test/parallel/test-process-umask.js index 869619f191..1d496f05ef 100644 --- a/test/parallel/test-process-umask.js +++ b/test/parallel/test-process-umask.js @@ -33,20 +33,20 @@ if (common.isWindows) { const old = process.umask(mask); -assert.strictEqual(parseInt(mask, 8), process.umask(old)); +assert.strictEqual(process.umask(old), parseInt(mask, 8)); // confirm reading the umask does not modify it. // 1. If the test fails, this call will succeed, but the mask will be set to 0 -assert.strictEqual(old, process.umask()); +assert.strictEqual(process.umask(), old); // 2. If the test fails, process.umask() will return 0 -assert.strictEqual(old, process.umask()); +assert.strictEqual(process.umask(), old); assert.throws(() => { process.umask({}); }, { - code: 'ERR_INVALID_ARG_TYPE', - message: 'The "mask" argument must be one of type number, string, or ' + - 'undefined. Received type object' + code: 'ERR_INVALID_ARG_VALUE', + message: 'The argument \'mask\' must be a 32-bit unsigned integer ' + + 'or an octal string. Received {}' }); ['123x', 'abc', '999'].forEach((value) => { @@ -54,6 +54,7 @@ assert.throws(() => { process.umask(value); }, { code: 'ERR_INVALID_ARG_VALUE', - message: `The argument 'mask' must be an octal string. Received '${value}'` + message: 'The argument \'mask\' must be a 32-bit unsigned integer ' + + `or an octal string. Received '${value}'` }); }); |