aboutsummaryrefslogtreecommitdiff
path: root/test/parallel/test-fs-open-mode-mask.js
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2018-05-09 22:44:44 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2018-05-17 17:14:35 +0800
commita18e130e597c3efc1df7bd86198c2b5762d4fbae (patch)
tree584b4e8b5c5a67a3272f2e66646de497777e4dc4 /test/parallel/test-fs-open-mode-mask.js
parent0d9500daedbb61770359c34383a8d4784bcabd56 (diff)
downloadandroid-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-open-mode-mask.js')
-rw-r--r--test/parallel/test-fs-open-mode-mask.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/test/parallel/test-fs-open-mode-mask.js b/test/parallel/test-fs-open-mode-mask.js
new file mode 100644
index 0000000000..4db41864af
--- /dev/null
+++ b/test/parallel/test-fs-open-mode-mask.js
@@ -0,0 +1,48 @@
+'use strict';
+
+// This tests that mode > 0o777 will be masked off with 0o777 in fs.open().
+
+const common = require('../common');
+const assert = require('assert');
+const path = require('path');
+const fs = require('fs');
+
+let mode;
+
+if (common.isWindows) {
+ mode = 0o444;
+} 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 file = path.join(tmpdir.path, `openSync-${suffix}.txt`);
+ const fd = fs.openSync(file, 'w+', input);
+ assert.strictEqual(fs.fstatSync(fd).mode & 0o777, mode);
+ fs.closeSync(fd);
+ assert.strictEqual(fs.statSync(file).mode & 0o777, mode);
+ }
+
+ {
+ const file = path.join(tmpdir.path, `open-${suffix}.txt`);
+ fs.open(file, 'w+', input, common.mustCall((err, fd) => {
+ assert.ifError(err);
+ assert.strictEqual(fs.fstatSync(fd).mode & 0o777, mode);
+ fs.closeSync(fd);
+ assert.strictEqual(fs.statSync(file).mode & 0o777, mode);
+ }));
+ }
+}
+
+test(mode, true);
+test(mode, false);