Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
test: require symlinked binary module twice
Attempt to load the binary module disguised
behind two symlinked locations.

Big thanks to Michael Mifsud <xzyfer@gmail.com>
for preparing a proper test case.
  • Loading branch information
saper committed May 3, 2016
commit c97ef1cffd7a0fe11c16c8731975e5d6979be152
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]);