From 2500a9208e1658460e794c1f11758816464bcbf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Cie=C5=9Blak?= Date: Mon, 2 May 2016 23:46:50 +0000 Subject: [PATCH] test: require symlinked binary module twice Attempt to load the binary module disguised behind two symlinked locations. Big thanks to Michael Mifsud for preparing a proper test case. --- test/addons/symlinked-module/binding.cc | 13 +++++++++ test/addons/symlinked-module/binding.gyp | 8 ++++++ test/addons/symlinked-module/submodule.js | 10 +++++++ test/addons/symlinked-module/test.js | 32 +++++++++++++++++++++++ 4 files changed, 63 insertions(+) create mode 100644 test/addons/symlinked-module/binding.cc create mode 100644 test/addons/symlinked-module/binding.gyp create mode 100644 test/addons/symlinked-module/submodule.js create mode 100644 test/addons/symlinked-module/test.js diff --git a/test/addons/symlinked-module/binding.cc b/test/addons/symlinked-module/binding.cc new file mode 100644 index 00000000000000..cdf9904e3f8d47 --- /dev/null +++ b/test/addons/symlinked-module/binding.cc @@ -0,0 +1,13 @@ +#include +#include + +void Method(const v8::FunctionCallbackInfo& args) { + v8::Isolate* isolate = args.GetIsolate(); + args.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, "world")); +} + +void init(v8::Local target) { + NODE_SET_METHOD(target, "hello", Method); +} + +NODE_MODULE(binding, init); diff --git a/test/addons/symlinked-module/binding.gyp b/test/addons/symlinked-module/binding.gyp new file mode 100644 index 00000000000000..3bfb84493f3e87 --- /dev/null +++ b/test/addons/symlinked-module/binding.gyp @@ -0,0 +1,8 @@ +{ + 'targets': [ + { + 'target_name': 'binding', + 'sources': [ 'binding.cc' ] + } + ] +} diff --git a/test/addons/symlinked-module/submodule.js b/test/addons/symlinked-module/submodule.js new file mode 100644 index 00000000000000..0372e69d95594e --- /dev/null +++ b/test/addons/symlinked-module/submodule.js @@ -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'); +}; diff --git a/test/addons/symlinked-module/test.js b/test/addons/symlinked-module/test.js new file mode 100644 index 00000000000000..1c14f29a398648 --- /dev/null +++ b/test/addons/symlinked-module/test.js @@ -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]);