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-fs-mkdir-mode-mask.js | |
parent | 0d9500daedbb61770359c34383a8d4784bcabd56 (diff) | |
download | android-node-v8-a18e130e597c3efc1df7bd86198c2b5762d4fbae.tar.gz android-node-v8-a18e130e597c3efc1df7bd86198c2b5762d4fbae.tar.bz2 android-node-v8-a18e130e597c3efc1df7bd86198c2b5762d4fbae.zip |
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-fs-mkdir-mode-mask.js')
-rw-r--r-- | test/parallel/test-fs-mkdir-mode-mask.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/test/parallel/test-fs-mkdir-mode-mask.js b/test/parallel/test-fs-mkdir-mode-mask.js new file mode 100644 index 0000000000..e4e8a42348 --- /dev/null +++ b/test/parallel/test-fs-mkdir-mode-mask.js @@ -0,0 +1,45 @@ +'use strict'; + +// This tests that mode > 0o777 will be masked off with 0o777 in fs.mkdir(). + +const common = require('../common'); +const assert = require('assert'); +const path = require('path'); +const fs = require('fs'); + +let mode; + +if (common.isWindows) { + common.skip('mode is not supported in mkdir on Windows'); + return; +} else { + mode = 0o644; +} + +const maskToIgnore = 0o10000; + +const tmpdir = require('../common/tmpdir'); +tmpdir.refresh(); + +function test(mode, asString) { + const suffix = asString ? 'str' : 'num'; + const input = asString ? + (mode | maskToIgnore).toString(8) : (mode | maskToIgnore); + + { + const dir = path.join(tmpdir.path, `mkdirSync-${suffix}`); + fs.mkdirSync(dir, input); + assert.strictEqual(fs.statSync(dir).mode & 0o777, mode); + } + + { + const dir = path.join(tmpdir.path, `mkdir-${suffix}`); + fs.mkdir(dir, input, common.mustCall((err) => { + assert.ifError(err); + assert.strictEqual(fs.statSync(dir).mode & 0o777, mode); + })); + } +} + +test(mode, true); +test(mode, false); |