Skip to content

Commit 583dc5f

Browse files
TrottMylesBorins
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>
1 parent d22b913 commit 583dc5f

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

Diff for: test/known_issues/known_issues.status

+6
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,25 @@ 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-nexttick: PASS,FLAKY
1314
test-vm-timeout-escape-promise: PASS,FLAKY
15+
test-fs-copyfile-respect-permissions: SKIP
1416

1517
[$system==macos]
1618

1719
[$system==solaris]
20+
test-fs-copyfile-respect-permissions: SKIP
1821

1922
[$system==freebsd]
23+
test-fs-copyfile-respect-permissions: SKIP
2024

2125
[$system==aix]
26+
test-fs-copyfile-respect-permissions: SKIP
2227

2328
[$arch==arm]
2429
# https://github.com/nodejs/node/issues/24120
2530
test-vm-timeout-escape-nexttick: PASS,FLAKY
31+
test-fs-copyfile-respect-permissions: SKIP
+50
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)