From 52e348335f7e5903348452cb30af7c6fd61ea905 Mon Sep 17 00:00:00 2001 From: Refael Ackermann Date: Thu, 4 May 2017 15:56:03 -0400 Subject: [PATCH] test: fix chmod mask testing on windows Currently this uncovers a regression in `fs.fchmodSync(fd, mode_sync);` No solution yet... Also as issue on macOS in test-fs-chmod:94 fail to access file1 Fixes:https://github.com/nodejs/node/issues/12803 --- test/known_issues/test-fs-fchmod-12835.js | 37 +++++++++++++++++++++++ test/parallel/parallel.status | 4 +++ test/parallel/test-fs-chmod.js | 28 +++++++++++++---- 3 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 test/known_issues/test-fs-fchmod-12835.js diff --git a/test/known_issues/test-fs-fchmod-12835.js b/test/known_issues/test-fs-fchmod-12835.js new file mode 100644 index 00000000000000..49619b6e0cfb7f --- /dev/null +++ b/test/known_issues/test-fs-fchmod-12835.js @@ -0,0 +1,37 @@ +'use strict'; +const common = require('../common'); + +// Windows only: Test fchmod on files with `attrib -a -h -i -r -s` +// setting RO then can't set RW back + +const {strictEqual, ok} = require('assert'); +const {execSync} = require('child_process'); +const fs = require('fs'); + +ok(common.isWindows, 'reset of test only for windows'); + +process.on('exit', function() { + console.log('Trying to cleanup'); + try { + execSync(`del /q /f ${tmpFile}`); + } catch (e) { + console.log(e); + } +}); + +const RO = 0o100444; // 33060 0b1000000100100100 +const RW = 0o100666; // 33206 0b1000000110110110 + +const tmpFile = `${common.tmpDir}\\${Date.now()}gigi.js`; + +const fd = fs.openSync(tmpFile, 'a'); +execSync(`attrib -a -h -i -r -s ${tmpFile}`); +fs.fchmodSync(fd, RO); +const actual2 = fs.fstatSync(fd).mode; +console.log(`${tmpFile} mode: ${actual2}`); +strictEqual(actual2, RO); + +fs.fchmodSync(fd, RW); // This does not work. +const actual3 = fs.fstatSync(fd).mode; +console.log(`${tmpFile} mode: ${actual3}`); +strictEqual(actual3, RW); // BANG! diff --git a/test/parallel/parallel.status b/test/parallel/parallel.status index 4703fdd05e2dae..96e97ce8fd7e40 100644 --- a/test/parallel/parallel.status +++ b/test/parallel/parallel.status @@ -7,10 +7,14 @@ prefix parallel [true] # This section applies to all platforms [$system==win32] +# https://github.com/nodejs/node/issues/12803 +test-fs-chmod : PASS,FLAKY [$system==linux] [$system==macos] +# https://github.com/nodejs/node/issues/12803 +test-fs-chmod : PASS,FLAKY [$arch==arm || $arch==arm64] diff --git a/test/parallel/test-fs-chmod.js b/test/parallel/test-fs-chmod.js index de48b096c68b74..a27afa9ed0776c 100644 --- a/test/parallel/test-fs-chmod.js +++ b/test/parallel/test-fs-chmod.js @@ -24,9 +24,11 @@ const common = require('../common'); const assert = require('assert'); const path = require('path'); const fs = require('fs'); +const {execSync} = require('child_process'); let mode_async; let mode_sync; +const windows_writable_mask = 0o222; // Need to hijack fs.open/close to make sure that things // get closed once they're opened. @@ -64,15 +66,27 @@ function closeSync() { // On Windows chmod is only able to manipulate read-only bit if (common.isWindows) { - mode_async = 0o400; // read-only - mode_sync = 0o600; // read-write + mode_async = 0o444; // read-only + mode_sync = 0o666; // read-write } else { mode_async = 0o777; mode_sync = 0o644; } -const file1 = path.join(common.fixturesDir, 'a.js'); -const file2 = path.join(common.fixturesDir, 'a1.js'); +const file1 = path.join(common.tmpDir, Date.now() + 'duck.js'); +const file2 = path.join(common.tmpDir, Date.now() + 'goose.js'); +fs.writeFileSync(file1, 'ga ga'); +fs.writeFileSync(file2, 'waq waq'); +// to flush some buffers +console.log('written'); +console.log('written some more'); +if (common.isWindows) { + execSync(`attrib -a -h -i -r -s ${file1}`); + execSync(`attrib -a -h -i -r -s ${file2}`); +} else { + execSync(`touch ${file1}`); + execSync(`touch ${file2}`); +} fs.chmod(file1, mode_async.toString(8), common.mustCall((err) => { assert.ifError(err); @@ -87,7 +101,7 @@ fs.chmod(file1, mode_async.toString(8), common.mustCall((err) => { fs.chmodSync(file1, mode_sync); if (common.isWindows) { - assert.ok((fs.statSync(file1).mode & 0o777) & mode_sync); + assert.ok((fs.statSync(file1).mode & 0o777) & windows_writable_mask); } else { assert.strictEqual(mode_sync, fs.statSync(file1).mode & 0o777); } @@ -109,7 +123,7 @@ fs.open(file2, 'a', common.mustCall((err, fd) => { fs.fchmodSync(fd, mode_sync); if (common.isWindows) { - assert.ok((fs.fstatSync(fd).mode & 0o777) & mode_sync); + assert.ok((fs.fstatSync(fd).mode & 0o777) & windows_writable_mask); } else { assert.strictEqual(mode_sync, fs.fstatSync(fd).mode & 0o777); } @@ -139,5 +153,7 @@ if (fs.lchmod) { process.on('exit', function() { + fs.chmodSync(file1, mode_sync); + fs.chmodSync(file2, mode_sync); assert.strictEqual(0, openCount); });