-
Notifications
You must be signed in to change notification settings - Fork 29.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: check that modules backed by read-only files can load (win32) #20116
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const cp = require('child_process'); | ||
|
||
const tmpdir = require('../common/tmpdir'); | ||
tmpdir.refresh(); | ||
|
||
if (process.platform == 'win32') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is currently a Windows only test, you can do:
This will skip the test on other platforms and exit the process. |
||
// Create readOnlyMod.js and set to read only | ||
const readOnlyMod = path.join(tmpdir.path, 'readOnlyMod'); | ||
const readOnlyModRelative = path.relative(__dirname, readOnlyMod); | ||
const readOnlyModFullPath = readOnlyMod + ".js"; | ||
fs.writeFileSync(readOnlyModFullPath, "module.exports = 42;"); | ||
|
||
// Removed any inherited ACEs, and any explicitly granted ACEs for the current user | ||
cp.execSync(`icacls.exe "${readOnlyModFullPath}" /inheritance:r /remove "%USERNAME%"`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Long line here, whitespace/indent errors elsewhere. Can you run There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As this is a Windows test the equivalent is |
||
// Grant the current user read & execute only | ||
cp.execSync(`icacls.exe "${readOnlyModFullPath}" /grant "%USERNAME%":RX`); | ||
|
||
let except = null; | ||
try { | ||
// Attempt to load the module. Will fail if write access is required | ||
const mymod = require(readOnlyModRelative); | ||
} catch(err) { | ||
except = err; | ||
} | ||
|
||
// Remove the expliclty granted rights, and reenable inheritance | ||
cp.execSync(`icacls.exe "${readOnlyModFullPath}" /remove "%USERNAME%" /inheritance:e`); | ||
|
||
// Delete the file | ||
fs.unlinkSync(readOnlyModFullPath); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (If we use the tmpdir module instead of the fixtures module, then there is no need to unlink.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just pushed a change to use tmpdir. I figured cleaning up is safer than having another run try and overwrite the same file (permissions shouldn't conflict as it should be a different tmpdir if under a different account, but just to be safe...). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (If you use |
||
|
||
if (except) throw except; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. e.g., |
||
} | ||
// TODO: Similar checks on *nix-like systems (e.g. using chmod or the like) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
common.isWindows