Skip to content
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

Closed
wants to merge 3 commits into from
Closed

test: check that modules backed by read-only files can load (win32) #20116

wants to merge 3 commits into from

Conversation

billti
Copy link
Contributor

@billti billti commented Apr 18, 2018

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

This is the test-case for the issue at #20112 . This fails with the issue present, and passes with the fix applied.

Note: Even before any changes, vcbuild test gave a ton of failures for me, so not sure if that is my machine or something more fundamental. This test behaves as expected though.

CC @vsemozhetbyt, @cjihrig, @richardlau

@nodejs-github-bot nodejs-github-bot added test Issues and PRs related to the tests. v10.x labels Apr 18, 2018

if (process.platform == 'win32') {
// Create readOnlyMod.js and set to read only
const readOnlyMod = fixtures.path('readOnlyMod');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of writing to the fixtures dir, and thus the source tree, can we create this in tmpdir instead?

Copy link
Member

@Trott Trott Apr 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the sum total of the change would be:

  • require tmpdir instead of fixtures
  • call tmpdir.refresh() once
  • Use tmpdir.path instead of fixtures.path

cp.execSync(`icacls.exe "${readOnlyModFullPath}" /remove "%USERNAME%" /inheritance:e`);

// Delete the file
fs.unlinkSync(readOnlyModFullPath);
Copy link
Member

Choose a reason for hiding this comment

The 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.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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...).

Copy link
Member

@Trott Trott Apr 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(If you use common/tmpdir rather than os.tmpdir, there is no need to clean up because tests are expected to refresh tmpdir before they do anything in it.)

@Trott
Copy link
Member

Trott commented Apr 18, 2018

Hi, @billti! Thanks for this!

@nodejs/testing PTAL

@Trott
Copy link
Member

Trott commented Apr 18, 2018

I guess @nodejs/platform-windows too...

@Trott
Copy link
Member

Trott commented Apr 18, 2018

Whoops! Not os.tmpdir(). Use common/tmpdir! https://github.com/nodejs/node/tree/master/test/common#tmpdir-module

Or look at another test to see some example code:

const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
const s = fs.createWriteStream(path.join(tmpdir.path, 'nocallback'));

@Trott
Copy link
Member

Trott commented Apr 18, 2018

Hmmm...I think this pull request is against the wrong branch. It should be against master and it will flow from there into v10.x-staging and v10.x...

@billti
Copy link
Contributor Author

billti commented Apr 18, 2018

I switched to the tmpdir requested.

I added the test for the v10.x branch as from the linked issue I thought that was what is being targeted ASAP in order to get the 10.0 release done. I can target whatever branch you want though. Just let me know.

@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented Apr 18, 2018

Thank you!
There are some linting nits in the test, You can quickly lint your file in this way from the project root folder:

node tools/node_modules/eslint/bin/eslint.js test/parallel/test-module-readonly.js

Currently, you will get:

Some errors:
j:\temp\_git\node-fork\test\parallel\1test-module-readonly.js
   1:1   error  Mandatory module "common" must be loaded       node-core/required-modules
   1:1   error  Use the global form of 'use strict'            strict
   8:22  error  Expected '===' and instead saw '=='            eqeqeq
   9:1   error  Expected indentation of 2 spaces but found 4   indent
  10:1   error  Expected indentation of 2 spaces but found 4   indent
  11:1   error  Expected indentation of 2 spaces but found 4   indent
  12:1   error  Expected indentation of 2 spaces but found 4   indent
  12:47  error  Strings must use singlequote                   quotes
  13:1   error  Expected indentation of 2 spaces but found 4   indent
  13:43  error  Strings must use singlequote                   quotes
  15:1   error  Expected indentation of 2 spaces but found 4   indent
  15:1   error  Line 15 exceeds the maximum line length of 80  max-len
  16:1   error  Expected indentation of 2 spaces but found 4   indent
  16:1   error  Line 16 exceeds the maximum line length of 80  max-len
  17:1   error  Expected indentation of 2 spaces but found 4   indent
  18:1   error  Expected indentation of 2 spaces but found 4   indent
  20:1   error  Expected indentation of 2 spaces but found 4   indent
  21:1   error  Expected indentation of 2 spaces but found 4   indent
  22:1   error  Expected indentation of 4 spaces but found 8   indent
  23:1   error  Expected indentation of 4 spaces but found 8   indent
  23:15  error  'mymod' is assigned a value but never used     no-unused-vars
  24:1   error  Expected indentation of 2 spaces but found 4   indent
  24:7   error  Expected space(s) after "catch"                keyword-spacing
  25:1   error  Expected indentation of 4 spaces but found 8   indent
  26:1   error  Expected indentation of 2 spaces but found 4   indent
  28:1   error  Expected indentation of 2 spaces but found 4   indent
  29:1   error  Expected indentation of 2 spaces but found 4   indent
  29:1   error  Line 29 exceeds the maximum line length of 80  max-len
  31:1   error  Expected indentation of 2 spaces but found 4   indent
  32:1   error  Expected indentation of 2 spaces but found 4   indent
  34:1   error  Expected indentation of 2 spaces but found 4   indent
  34:17  error  Use assert.ifError(except) instead             node-core/prefer-assert-iferror

✖ 32 problems (32 errors, 0 warnings)
  24 errors, 0 warnings potentially fixable with the `--fix` option.

About Mandatory module "common" must be loaded you can read in https://github.com/nodejs/node/blob/master/doc/guides/writing-tests.md

@vsemozhetbyt vsemozhetbyt added fs Issues and PRs related to the fs subsystem / file system. and removed fs Issues and PRs related to the fs subsystem / file system. labels Apr 18, 2018
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();

if (process.platform == 'win32') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

common.isWindows

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%"`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Long line here, whitespace/indent errors elsewhere. Can you run make lint?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is a Windows test the equivalent is vcbuild lint (or vcbuild lint-js to just lint the JavaScript files).

Copy link
Member

@richardlau richardlau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. We have a guide to writing tests at https://github.com/nodejs/node/blob/master/doc/guides/writing-tests.md which explains things like starting the test with require('../common').

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%"`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is a Windows test the equivalent is vcbuild lint (or vcbuild lint-js to just lint the JavaScript files).

Copy link
Member

@richardlau richardlau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh and as has been pointed out by @Trott, please retarget this to the master branch as that's where the libuv fix will go first before being backported into the v10.x branches.

@richardlau richardlau added the blocked PRs that are blocked by other issues or PRs. label Apr 18, 2018
@richardlau
Copy link
Member

Adding the blocked label as this test is expected to fail (even when the lint issues have been addressed) until we get a libuv with libuv/libuv#1800.

const tmpdir = require('../common/tmpdir');
tmpdir.refresh();

if (process.platform == 'win32') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is currently a Windows only test, you can do:

if (!common.isWindows) {
  common.skip('test only runs on Windows');
}

This will skip the test on other platforms and exit the process.

// Delete the file
fs.unlinkSync(readOnlyModFullPath);

if (except) throw except;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of an if, we'd ideally want an assertion, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Trott
Copy link
Member

Trott commented Apr 18, 2018

vcbuild lint will flag a bunch of stuff on this file (or at least should) like needing a 'use strict'; and requiring the test common module. But I think those will be easy fixes.

@Trott
Copy link
Member

Trott commented Apr 18, 2018

(Sorry for all the style nits that are getting picked. We try to put as many of them into the linter as possible rather than having them come up in PR review. Thanks for your patience with it all!)

@billti
Copy link
Contributor Author

billti commented Apr 18, 2018

No problem. I think I have all the issues addressed. Just trying to run all the tests/linting now. I'll open a new pull request against 'master' when it's ready, and link & close this one when done.

@billti
Copy link
Contributor Author

billti commented Apr 18, 2018

Opened new pull request against master in #20138 which should address all comments (so far 😉).

@billti billti closed this Apr 18, 2018
@billti billti deleted the test-read-only-modules branch April 18, 2018 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked PRs that are blocked by other issues or PRs. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants