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

discover native modules from process.moduleLoadList ... #34

Closed
wants to merge 5 commits into from
Closed

discover native modules from process.moduleLoadList ... #34

wants to merge 5 commits into from

Conversation

robrich
Copy link
Contributor

@robrich robrich commented Jun 13, 2014

... instead of using a hard-coded list

@@ -1,2 +1,4 @@
*.un~
/node_modules
**/temp/**
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't add these here, especially not ones that are environment-specific (like .idea). For those you should use your global machine .gitignore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As part of the test, I create the temp folder inside the integration folder. I'm good with removing .idea, but not so much with removing /temp/. I'm good with a more specific path though. See https://github.com/robrich/node-sandboxed-module/blob/master/test/integration/test-all-native-modules.js#L14

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, you should remove any files you create during a test; tests need to clean up after themselves.

@domenic
Copy link
Collaborator

domenic commented Jun 13, 2014

Very impressive discovery; excited to have this. Lots of nits, but good stuff overall.

var fs = require('fs');
var path = require('path');
var SandboxedModule = require('../..');
var nativeModules = require('../../lib/native_modules');
Copy link
Collaborator

Choose a reason for hiding this comment

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

After thinking about this test for a while, I am not sure it benefits much to test every single native module. Especially since you're relying on the code that enumerates them inside the test itself.

It might be best to just create a single fixture that does require(require('../lib/native_modules')[0]), or maybe does a few of those, and then test that single fixture, in a similar fashion to the rest of the tests.

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 debated just picking my favorites, but it's this very scenario where our favorite (path) wasn't the problem. Flexing them all runs nearly instantaneously, so I don't see the harm in it. I debated writing one file that required them all, then running SandboxedModule.require() on that file, but then it'd be much less discoverable which module did bad things.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it'd be OK based on the error message from your original bug. And more importantly, it would allow us to check in the fixture, instead of generating it at runtime, which makes the test much easier to understand.

You could still use the list from lib/native_modules, just do

require('../../lib/native_modules').forEach(require);

in the fixture.

@robrich
Copy link
Contributor Author

robrich commented Jun 13, 2014

Changes made, Travis went green.

@robrich
Copy link
Contributor Author

robrich commented Jun 13, 2014

What I really like about using the discovered list to test them all is it's also future-proof. If they include another native module or deprecate one, the test still works. I grant it's not as discoverable, thus the excessive comments, but I do think it's a safer design.

@domenic
Copy link
Collaborator

domenic commented Jun 13, 2014

Yeah, let's use the discovered list, but with a static checked-in fixture instead of writing a bunch of temp files.

@robrich
Copy link
Contributor Author

robrich commented Jun 13, 2014

I rebooted, and suddenly process.moduleLoadList was nearly empty. Switched to monkey patching (pillaged from https://gist.github.com/Benvie/1841241) to get NativeModule, which works like a charm. Also note that when dynamic test fails, it's much easier to know why, so I included both.

@domenic
Copy link
Collaborator

domenic commented Jun 13, 2014

Let me be clearer: I don't want any tests in this repo that create temporary files on the disk :)

@robrich
Copy link
Contributor Author

robrich commented Jun 13, 2014

Thank you for clarifying.

@robrich robrich closed this Jun 13, 2014
@ChrisEineke
Copy link

Will this be re-pulled at some point? I'm running into an issue with a module loading winston-syslog, which has native code to it, on which the sandbox loaders pukes.

@domenic
Copy link
Collaborator

domenic commented Jun 23, 2014

Yes, I've been meaning to revive this and just remove the temp-file creating tests before merging. Thanks for chiming in; that helps me prioritize.

@robrich
Copy link
Contributor Author

robrich commented Jun 24, 2014

Use proxyquire. It has no such issues.

@ChrisEineke
Copy link

domenic: Great. :)
robrich: No. :)

domenic added a commit that referenced this pull request Jul 2, 2014
It is generated via much hackery, but then checked in for a given release, to avoid how this seems way too fragile to do at runtime.

Fixes #33. Inspired greatly by @robrich's work in #34.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants