Skip to content

Commit 9330d7e

Browse files
TrottBethGriggs
authored andcommitted
test: add known_issues test for fs.copyFile()
On macOS, fs.copyFile() may not respect file permissions. There is a PR for libuv that should fix this, but until it lands and we can either float a patch or upgrade libuv, have a known_issues test. Ref: #26936 Ref: libuv/libuv#2233 PR-URL: #26939 Refs: #26936 Refs: libuv/libuv#2233 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Signed-off-by: Beth Griggs <Bethany.Griggs@uk.ibm.com>
1 parent d76c30c commit 9330d7e

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

test/known_issues/known_issues.status

+6
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,24 @@ prefix known_issues
77
[true] # This section applies to all platforms
88

99
[$system==win32]
10+
test-fs-copyfile-respect-permissions: SKIP
1011

1112
[$system==linux]
1213
test-vm-timeout-escape-promise: PASS,FLAKY
14+
test-fs-copyfile-respect-permissions: SKIP
1315

1416
[$system==macos]
1517

1618
[$system==solaris]
19+
test-fs-copyfile-respect-permissions: SKIP
1720

1821
[$system==freebsd]
22+
test-fs-copyfile-respect-permissions: SKIP
1923

2024
[$system==aix]
25+
test-fs-copyfile-respect-permissions: SKIP
2126

2227
[$arch==arm]
2328
# https://github.com/nodejs/node/issues/24120
2429
test-vm-timeout-escape-nexttick: PASS,FLAKY
30+
test-fs-copyfile-respect-permissions: SKIP
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
'use strict';
2+
3+
// Test that fs.copyFile() respects file permissions.
4+
// Ref: https://github.com/nodejs/node/issues/26936
5+
6+
const common = require('../common');
7+
8+
const tmpdir = require('../common/tmpdir');
9+
tmpdir.refresh();
10+
11+
const assert = require('assert');
12+
const fs = require('fs');
13+
const path = require('path');
14+
15+
let n = 0;
16+
17+
function beforeEach() {
18+
n++;
19+
const source = path.join(tmpdir.path, `source${n}`);
20+
const dest = path.join(tmpdir.path, `dest${n}`);
21+
fs.writeFileSync(source, 'source');
22+
fs.writeFileSync(dest, 'dest');
23+
fs.chmodSync(dest, '444');
24+
25+
const check = (err) => {
26+
assert.strictEqual(err.code, 'EACCESS');
27+
assert.strictEqual(fs.readFileSync(dest, 'utf8'), 'dest');
28+
};
29+
30+
return { source, dest, check };
31+
}
32+
33+
// Test synchronous API.
34+
{
35+
const { source, dest, check } = beforeEach();
36+
assert.throws(() => { fs.copyFileSync(source, dest); }, check);
37+
}
38+
39+
// Test promises API.
40+
{
41+
const { source, dest, check } = beforeEach();
42+
assert.throws(async () => { await fs.promises.copyFile(source, dest); },
43+
check);
44+
}
45+
46+
// Test callback API.
47+
{
48+
const { source, dest, check } = beforeEach();
49+
fs.copyFile(source, dest, common.mustCall(check));
50+
}

0 commit comments

Comments
 (0)