| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,7 @@ | |||
| 5 | 5 | #include "node_errors.h" | |
| 6 | 6 | #include "node_external_reference.h" | |
| 7 | 7 | #include "node_url_pattern.h" | |
| 8 | + #include "permission/permission.h" | ||
| 8 | 9 | #include "util.h" | |
| 9 | 10 | ||
| 10 | 11 | #include <string> | |
@@ -450,6 +451,8 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) { | |||
| 450 | 451 | return THROW_ERR_DLOPEN_DISABLED( | |
| 451 | 452 | env, "Cannot load native addon because loading addons is disabled."); | |
| 452 | 453 | } | |
| 454 | + THROW_IF_INSUFFICIENT_PERMISSIONS( | ||
| 455 | + env, permission::PermissionScope::kAddon, ""); | ||
| 453 | 456 | ||
| 454 | 457 | auto context = env->context(); | |
| 455 | 458 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,38 @@ | |||
| 1 | + // Flags: --permission --allow-addons --allow-fs-read=* | ||
| 2 | + 'use strict'; | ||
| 3 | + | ||
| 4 | + const common = require('../common'); | ||
| 5 | + const { isMainThread } = require('worker_threads'); | ||
| 6 | + | ||
| 7 | + if (!isMainThread) { | ||
| 8 | + common.skip('This test only works on a main thread'); | ||
| 9 | + } | ||
| 10 | + | ||
| 11 | + const assert = require('assert'); | ||
| 12 | + | ||
| 13 | + let bindingPath; | ||
| 14 | + try { | ||
| 15 | + bindingPath = require.resolve( | ||
| 16 | + `../addons/hello-world/build/${common.buildType}/binding`); | ||
| 17 | + } catch (err) { | ||
| 18 | + if (err.code !== 'MODULE_NOT_FOUND') { | ||
| 19 | + throw err; | ||
| 20 | + } | ||
| 21 | + common.skip('addon not found'); | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + function openAddon() { | ||
| 25 | + process.dlopen({ exports: {} }, bindingPath); | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + assert.ok(process.permission.has('addon')); | ||
| 29 | + openAddon(); | ||
| 30 | + | ||
| 31 | + process.permission.drop('addon'); | ||
| 32 | + assert.ok(!process.permission.has('addon')); | ||
| 33 | + assert.throws(() => { | ||
| 34 | + openAddon(); | ||
| 35 | + }, common.expectsError({ | ||
| 36 | + code: 'ERR_ACCESS_DENIED', | ||
| 37 | + permission: 'Addon', | ||
| 38 | + })); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments