Skip to content

Commit

Permalink
test: require symlinked binary module twice
Browse files Browse the repository at this point in the history
Attempt to load the binary module disguised
behind two symlinked locations.

Big thanks to Michael Mifsud <[email protected]>
for preparing a proper test case.
  • Loading branch information
saper committed May 3, 2016
1 parent 4561bd1 commit 2500a92
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/addons/symlinked-module/binding.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <node.h>
#include <v8.h>

void Method(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
args.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, "world"));
}

void init(v8::Local<v8::Object> target) {
NODE_SET_METHOD(target, "hello", Method);
}

NODE_MODULE(binding, init);
8 changes: 8 additions & 0 deletions test/addons/symlinked-module/binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
'targets': [
{
'target_name': 'binding',
'sources': [ 'binding.cc' ]
}
]
}
10 changes: 10 additions & 0 deletions test/addons/symlinked-module/submodule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';
require('../../common');
const path = require('path');
const assert = require('assert');

module.exports.test = function(bindingDir) {
var mod = require(path.join(bindingDir, 'binding.node'));
assert(mod != null);
assert(mod.hello() == 'world');
};
32 changes: 32 additions & 0 deletions test/addons/symlinked-module/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';
const common = require('../../common');
const fs = require('fs');
const path = require('path');
const assert = require('assert');

common.refreshTmpDir();

var destDir = path.resolve(common.tmpDir);

var location = [path.join(destDir, 'first'), path.join(destDir, 'second')];
fs.mkdirSync(location[0]);
try {
fs.symlinkSync(location[0], location[1]);
} catch (EPERM) {
console.log('1..0 # Skipped: module identity test (no privs for symlinks)');
return;
}

const addonPath = path.join(__dirname, 'build', 'Release', 'binding.node');

var contents = fs.readFileSync(addonPath);
fs.writeFileSync(path.join(location[0], 'binding.node'), contents);
fs.writeFileSync(path.join(location[1], 'binding.node'), contents);

var primary = require(path.join(location[0], 'binding.node'));
assert(primary != null);
assert(primary.hello() == 'world');
var secondary = require(path.join(location[1], 'binding.node'));
assert(secondary != null);
assert(secondary.hello() == 'world');
require('./submodule').test(location[1]);

0 comments on commit 2500a92

Please sign in to comment.