mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
ee9df357ff
On Windows, creating a symlink requires admin privileges. There were two tests which created symlinks which were failing when run as non-admin. test-fs-symlink.js already had a check for privileges on Windows but it had a couple issues: 1. It assumed that whoami was the one that came with windows. However, whoami also ships with Win32 Unix utility ports like the distribution with git, which can cause this to get check tripped up. 2. On failure, the check would just return from the callback instead of exiting 3. whoami was executed asynchronously so the test would run regardless of privilege state. test-fs-options-immutable had no check. As part of this change, I refactored the privilege checking to a function in common, and changed both above tests to use the refactored function. Also documented this function in test\README.md PR-URL: https://github.com/nodejs/node/pull/10477 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: João Reis <reis@janeasystems.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
99 lines
2.6 KiB
JavaScript
99 lines
2.6 KiB
JavaScript
'use strict';
|
|
|
|
/*
|
|
* These tests make sure that the `options` object passed to these functions are
|
|
* never altered.
|
|
*
|
|
* Refer: https://github.com/nodejs/node/issues/7655
|
|
*/
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const path = require('path');
|
|
const fs = require('fs');
|
|
const errHandler = (e) => assert.ifError(e);
|
|
const options = Object.freeze({});
|
|
common.refreshTmpDir();
|
|
|
|
{
|
|
assert.doesNotThrow(() =>
|
|
fs.readFile(__filename, options, common.mustCall(errHandler))
|
|
);
|
|
assert.doesNotThrow(() => fs.readFileSync(__filename, options));
|
|
}
|
|
|
|
{
|
|
assert.doesNotThrow(() =>
|
|
fs.readdir(__dirname, options, common.mustCall(errHandler))
|
|
);
|
|
assert.doesNotThrow(() => fs.readdirSync(__dirname, options));
|
|
}
|
|
|
|
if (common.canCreateSymLink()) {
|
|
const sourceFile = path.resolve(common.tmpDir, 'test-readlink');
|
|
const linkFile = path.resolve(common.tmpDir, 'test-readlink-link');
|
|
|
|
fs.writeFileSync(sourceFile, '');
|
|
fs.symlinkSync(sourceFile, linkFile);
|
|
|
|
assert.doesNotThrow(() =>
|
|
fs.readlink(linkFile, options, common.mustCall(errHandler))
|
|
);
|
|
assert.doesNotThrow(() => fs.readlinkSync(linkFile, options));
|
|
}
|
|
|
|
{
|
|
const fileName = path.resolve(common.tmpDir, 'writeFile');
|
|
assert.doesNotThrow(() => fs.writeFileSync(fileName, 'ABCD', options));
|
|
assert.doesNotThrow(() =>
|
|
fs.writeFile(fileName, 'ABCD', options, common.mustCall(errHandler))
|
|
);
|
|
}
|
|
|
|
{
|
|
const fileName = path.resolve(common.tmpDir, 'appendFile');
|
|
assert.doesNotThrow(() => fs.appendFileSync(fileName, 'ABCD', options));
|
|
assert.doesNotThrow(() =>
|
|
fs.appendFile(fileName, 'ABCD', options, common.mustCall(errHandler))
|
|
);
|
|
}
|
|
|
|
if (!common.isAix) {
|
|
// TODO(thefourtheye) Remove this guard once
|
|
// https://github.com/nodejs/node/issues/5085 is fixed
|
|
{
|
|
let watch;
|
|
assert.doesNotThrow(() => watch = fs.watch(__filename, options, () => {}));
|
|
watch.close();
|
|
}
|
|
|
|
{
|
|
assert.doesNotThrow(() => fs.watchFile(__filename, options, () => {}));
|
|
fs.unwatchFile(__filename);
|
|
}
|
|
}
|
|
|
|
{
|
|
assert.doesNotThrow(() => fs.realpathSync(__filename, options));
|
|
assert.doesNotThrow(() =>
|
|
fs.realpath(__filename, options, common.mustCall(errHandler))
|
|
);
|
|
}
|
|
|
|
{
|
|
const tempFileName = path.resolve(common.tmpDir, 'mkdtemp-');
|
|
assert.doesNotThrow(() => fs.mkdtempSync(tempFileName, options));
|
|
assert.doesNotThrow(() =>
|
|
fs.mkdtemp(tempFileName, options, common.mustCall(errHandler))
|
|
);
|
|
}
|
|
|
|
{
|
|
const fileName = path.resolve(common.tmpDir, 'streams');
|
|
assert.doesNotThrow(() => {
|
|
fs.WriteStream(fileName, options).once('open', () => {
|
|
assert.doesNotThrow(() => fs.ReadStream(fileName, options));
|
|
});
|
|
});
|
|
}
|