mirror of
https://github.com/usebruno/bruno.git
synced 2025-06-28 16:01:25 +02:00
feat(#306): allow fs access inside scripts
This commit is contained in:
parent
8d89496304
commit
0cf18e6804
@ -103,6 +103,8 @@ const registerNetworkIpc = (mainWindow) => {
|
|||||||
const request = prepareRequest(_request);
|
const request = prepareRequest(_request);
|
||||||
const envVars = getEnvVars(environment);
|
const envVars = getEnvVars(environment);
|
||||||
const processEnvVars = getProcessEnvVars(collectionUid);
|
const processEnvVars = getProcessEnvVars(collectionUid);
|
||||||
|
const brunoConfig = getBrunoConfig(collectionUid);
|
||||||
|
const allowScriptFilesystemAccess = get(brunoConfig, 'filesystemAccess.allow', false);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// make axios work in node using form data
|
// make axios work in node using form data
|
||||||
@ -154,7 +156,8 @@ const registerNetworkIpc = (mainWindow) => {
|
|||||||
collectionVariables,
|
collectionVariables,
|
||||||
collectionPath,
|
collectionPath,
|
||||||
onConsoleLog,
|
onConsoleLog,
|
||||||
processEnvVars
|
processEnvVars,
|
||||||
|
allowScriptFilesystemAccess
|
||||||
);
|
);
|
||||||
|
|
||||||
mainWindow.webContents.send('main:script-environment-update', {
|
mainWindow.webContents.send('main:script-environment-update', {
|
||||||
@ -166,7 +169,6 @@ const registerNetworkIpc = (mainWindow) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// proxy configuration
|
// proxy configuration
|
||||||
const brunoConfig = getBrunoConfig(collectionUid);
|
|
||||||
const proxyEnabled = get(brunoConfig, 'proxy.enabled', false);
|
const proxyEnabled = get(brunoConfig, 'proxy.enabled', false);
|
||||||
if (proxyEnabled) {
|
if (proxyEnabled) {
|
||||||
const proxyProtocol = get(brunoConfig, 'proxy.protocol');
|
const proxyProtocol = get(brunoConfig, 'proxy.protocol');
|
||||||
@ -278,7 +280,8 @@ const registerNetworkIpc = (mainWindow) => {
|
|||||||
collectionVariables,
|
collectionVariables,
|
||||||
collectionPath,
|
collectionPath,
|
||||||
onConsoleLog,
|
onConsoleLog,
|
||||||
processEnvVars
|
processEnvVars,
|
||||||
|
allowScriptFilesystemAccess
|
||||||
);
|
);
|
||||||
|
|
||||||
mainWindow.webContents.send('main:script-environment-update', {
|
mainWindow.webContents.send('main:script-environment-update', {
|
||||||
@ -323,7 +326,8 @@ const registerNetworkIpc = (mainWindow) => {
|
|||||||
collectionVariables,
|
collectionVariables,
|
||||||
collectionPath,
|
collectionPath,
|
||||||
onConsoleLog,
|
onConsoleLog,
|
||||||
processEnvVars
|
processEnvVars,
|
||||||
|
allowScriptFilesystemAccess
|
||||||
);
|
);
|
||||||
|
|
||||||
mainWindow.webContents.send('main:run-request-event', {
|
mainWindow.webContents.send('main:run-request-event', {
|
||||||
@ -397,7 +401,8 @@ const registerNetworkIpc = (mainWindow) => {
|
|||||||
collectionVariables,
|
collectionVariables,
|
||||||
collectionPath,
|
collectionPath,
|
||||||
onConsoleLog,
|
onConsoleLog,
|
||||||
processEnvVars
|
processEnvVars,
|
||||||
|
allowScriptFilesystemAccess
|
||||||
);
|
);
|
||||||
|
|
||||||
mainWindow.webContents.send('main:run-request-event', {
|
mainWindow.webContents.send('main:run-request-event', {
|
||||||
@ -483,6 +488,8 @@ const registerNetworkIpc = (mainWindow) => {
|
|||||||
const collectionUid = collection.uid;
|
const collectionUid = collection.uid;
|
||||||
const collectionPath = collection.pathname;
|
const collectionPath = collection.pathname;
|
||||||
const folderUid = folder ? folder.uid : null;
|
const folderUid = folder ? folder.uid : null;
|
||||||
|
const brunoConfig = getBrunoConfig(collectionUid);
|
||||||
|
const allowScriptFilesystemAccess = get(brunoConfig, 'filesystemAccess.allow', false);
|
||||||
|
|
||||||
const onConsoleLog = (type, args) => {
|
const onConsoleLog = (type, args) => {
|
||||||
console[type](...args);
|
console[type](...args);
|
||||||
@ -588,7 +595,8 @@ const registerNetworkIpc = (mainWindow) => {
|
|||||||
collectionVariables,
|
collectionVariables,
|
||||||
collectionPath,
|
collectionPath,
|
||||||
onConsoleLog,
|
onConsoleLog,
|
||||||
processEnvVars
|
processEnvVars,
|
||||||
|
allowScriptFilesystemAccess
|
||||||
);
|
);
|
||||||
|
|
||||||
mainWindow.webContents.send('main:script-environment-update', {
|
mainWindow.webContents.send('main:script-environment-update', {
|
||||||
@ -599,7 +607,6 @@ const registerNetworkIpc = (mainWindow) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// proxy configuration
|
// proxy configuration
|
||||||
const brunoConfig = getBrunoConfig(collectionUid);
|
|
||||||
const proxyEnabled = get(brunoConfig, 'proxy.enabled', false);
|
const proxyEnabled = get(brunoConfig, 'proxy.enabled', false);
|
||||||
if (proxyEnabled) {
|
if (proxyEnabled) {
|
||||||
const proxyProtocol = get(brunoConfig, 'proxy.protocol');
|
const proxyProtocol = get(brunoConfig, 'proxy.protocol');
|
||||||
@ -690,7 +697,8 @@ const registerNetworkIpc = (mainWindow) => {
|
|||||||
collectionVariables,
|
collectionVariables,
|
||||||
collectionPath,
|
collectionPath,
|
||||||
onConsoleLog,
|
onConsoleLog,
|
||||||
processEnvVars
|
processEnvVars,
|
||||||
|
allowScriptFilesystemAccess
|
||||||
);
|
);
|
||||||
|
|
||||||
mainWindow.webContents.send('main:script-environment-update', {
|
mainWindow.webContents.send('main:script-environment-update', {
|
||||||
@ -733,7 +741,8 @@ const registerNetworkIpc = (mainWindow) => {
|
|||||||
collectionVariables,
|
collectionVariables,
|
||||||
collectionPath,
|
collectionPath,
|
||||||
onConsoleLog,
|
onConsoleLog,
|
||||||
processEnvVars
|
processEnvVars,
|
||||||
|
allowScriptFilesystemAccess
|
||||||
);
|
);
|
||||||
|
|
||||||
mainWindow.webContents.send('main:run-folder-event', {
|
mainWindow.webContents.send('main:run-folder-event', {
|
||||||
@ -812,7 +821,8 @@ const registerNetworkIpc = (mainWindow) => {
|
|||||||
collectionVariables,
|
collectionVariables,
|
||||||
collectionPath,
|
collectionPath,
|
||||||
onConsoleLog,
|
onConsoleLog,
|
||||||
processEnvVars
|
processEnvVars,
|
||||||
|
allowScriptFilesystemAccess
|
||||||
);
|
);
|
||||||
|
|
||||||
mainWindow.webContents.send('main:run-folder-event', {
|
mainWindow.webContents.send('main:run-folder-event', {
|
||||||
|
@ -2,10 +2,11 @@ const Handlebars = require('handlebars');
|
|||||||
const { cloneDeep } = require('lodash');
|
const { cloneDeep } = require('lodash');
|
||||||
|
|
||||||
class Bru {
|
class Bru {
|
||||||
constructor(envVariables, collectionVariables, processEnvVars) {
|
constructor(envVariables, collectionVariables, processEnvVars, collectionPath) {
|
||||||
this.envVariables = envVariables;
|
this.envVariables = envVariables;
|
||||||
this.collectionVariables = collectionVariables;
|
this.collectionVariables = collectionVariables;
|
||||||
this.processEnvVars = cloneDeep(processEnvVars || {});
|
this.processEnvVars = cloneDeep(processEnvVars || {});
|
||||||
|
this.collectionPath = collectionPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
_interpolateEnvVar = (str) => {
|
_interpolateEnvVar = (str) => {
|
||||||
@ -24,6 +25,10 @@ class Bru {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
cwd() {
|
||||||
|
return this.collectionPath;
|
||||||
|
}
|
||||||
|
|
||||||
getEnvName() {
|
getEnvName() {
|
||||||
return this.envVariables.__name__;
|
return this.envVariables.__name__;
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ const util = require('util');
|
|||||||
const zlib = require('zlib');
|
const zlib = require('zlib');
|
||||||
const url = require('url');
|
const url = require('url');
|
||||||
const punycode = require('punycode');
|
const punycode = require('punycode');
|
||||||
|
const fs = require('fs');
|
||||||
const Bru = require('../bru');
|
const Bru = require('../bru');
|
||||||
const BrunoRequest = require('../bruno-request');
|
const BrunoRequest = require('../bruno-request');
|
||||||
const BrunoResponse = require('../bruno-response');
|
const BrunoResponse = require('../bruno-response');
|
||||||
@ -27,6 +28,8 @@ const CryptoJS = require('crypto-js');
|
|||||||
class ScriptRuntime {
|
class ScriptRuntime {
|
||||||
constructor() {}
|
constructor() {}
|
||||||
|
|
||||||
|
// This approach is getting out of hand
|
||||||
|
// Need to refactor this to use a single arg (object) instead of 7
|
||||||
async runRequestScript(
|
async runRequestScript(
|
||||||
script,
|
script,
|
||||||
request,
|
request,
|
||||||
@ -34,9 +37,10 @@ class ScriptRuntime {
|
|||||||
collectionVariables,
|
collectionVariables,
|
||||||
collectionPath,
|
collectionPath,
|
||||||
onConsoleLog,
|
onConsoleLog,
|
||||||
processEnvVars
|
processEnvVars,
|
||||||
|
allowScriptFilesystemAccess
|
||||||
) {
|
) {
|
||||||
const bru = new Bru(envVariables, collectionVariables, processEnvVars);
|
const bru = new Bru(envVariables, collectionVariables, processEnvVars, collectionPath);
|
||||||
const req = new BrunoRequest(request);
|
const req = new BrunoRequest(request);
|
||||||
|
|
||||||
const context = {
|
const context = {
|
||||||
@ -84,7 +88,8 @@ class ScriptRuntime {
|
|||||||
axios,
|
axios,
|
||||||
chai,
|
chai,
|
||||||
'node-fetch': fetch,
|
'node-fetch': fetch,
|
||||||
'crypto-js': CryptoJS
|
'crypto-js': CryptoJS,
|
||||||
|
fs: allowScriptFilesystemAccess ? fs : undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -105,9 +110,10 @@ class ScriptRuntime {
|
|||||||
collectionVariables,
|
collectionVariables,
|
||||||
collectionPath,
|
collectionPath,
|
||||||
onConsoleLog,
|
onConsoleLog,
|
||||||
processEnvVars
|
processEnvVars,
|
||||||
|
allowScriptFilesystemAccess
|
||||||
) {
|
) {
|
||||||
const bru = new Bru(envVariables, collectionVariables, processEnvVars);
|
const bru = new Bru(envVariables, collectionVariables, processEnvVars, collectionPath);
|
||||||
const req = new BrunoRequest(request);
|
const req = new BrunoRequest(request);
|
||||||
const res = new BrunoResponse(response);
|
const res = new BrunoResponse(response);
|
||||||
|
|
||||||
@ -138,6 +144,16 @@ class ScriptRuntime {
|
|||||||
external: true,
|
external: true,
|
||||||
root: [collectionPath],
|
root: [collectionPath],
|
||||||
mock: {
|
mock: {
|
||||||
|
// node libs
|
||||||
|
path,
|
||||||
|
stream,
|
||||||
|
util,
|
||||||
|
url,
|
||||||
|
http,
|
||||||
|
https,
|
||||||
|
punycode,
|
||||||
|
zlib,
|
||||||
|
// 3rd party libs
|
||||||
atob,
|
atob,
|
||||||
btoa,
|
btoa,
|
||||||
lodash,
|
lodash,
|
||||||
@ -146,7 +162,8 @@ class ScriptRuntime {
|
|||||||
nanoid,
|
nanoid,
|
||||||
axios,
|
axios,
|
||||||
'node-fetch': fetch,
|
'node-fetch': fetch,
|
||||||
'crypto-js': CryptoJS
|
'crypto-js': CryptoJS,
|
||||||
|
fs: allowScriptFilesystemAccess ? fs : undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,14 @@
|
|||||||
const { NodeVM } = require('vm2');
|
const { NodeVM } = require('vm2');
|
||||||
const chai = require('chai');
|
const chai = require('chai');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const http = require('http');
|
||||||
|
const https = require('https');
|
||||||
|
const stream = require('stream');
|
||||||
|
const util = require('util');
|
||||||
|
const zlib = require('zlib');
|
||||||
|
const url = require('url');
|
||||||
|
const punycode = require('punycode');
|
||||||
|
const fs = require('fs');
|
||||||
const Bru = require('../bru');
|
const Bru = require('../bru');
|
||||||
const BrunoRequest = require('../bruno-request');
|
const BrunoRequest = require('../bruno-request');
|
||||||
const BrunoResponse = require('../bruno-response');
|
const BrunoResponse = require('../bruno-response');
|
||||||
@ -29,9 +37,10 @@ class TestRuntime {
|
|||||||
collectionVariables,
|
collectionVariables,
|
||||||
collectionPath,
|
collectionPath,
|
||||||
onConsoleLog,
|
onConsoleLog,
|
||||||
processEnvVars
|
processEnvVars,
|
||||||
|
allowScriptFilesystemAccess
|
||||||
) {
|
) {
|
||||||
const bru = new Bru(envVariables, collectionVariables, processEnvVars);
|
const bru = new Bru(envVariables, collectionVariables, processEnvVars, collectionPath);
|
||||||
const req = new BrunoRequest(request);
|
const req = new BrunoRequest(request);
|
||||||
const res = new BrunoResponse(response);
|
const res = new BrunoResponse(response);
|
||||||
|
|
||||||
@ -78,6 +87,16 @@ class TestRuntime {
|
|||||||
external: true,
|
external: true,
|
||||||
root: [collectionPath],
|
root: [collectionPath],
|
||||||
mock: {
|
mock: {
|
||||||
|
// node libs
|
||||||
|
path,
|
||||||
|
stream,
|
||||||
|
util,
|
||||||
|
url,
|
||||||
|
http,
|
||||||
|
https,
|
||||||
|
punycode,
|
||||||
|
zlib,
|
||||||
|
// 3rd party libs
|
||||||
atob,
|
atob,
|
||||||
axios,
|
axios,
|
||||||
btoa,
|
btoa,
|
||||||
@ -86,7 +105,8 @@ class TestRuntime {
|
|||||||
uuid,
|
uuid,
|
||||||
nanoid,
|
nanoid,
|
||||||
chai,
|
chai,
|
||||||
'crypto-js': CryptoJS
|
'crypto-js': CryptoJS,
|
||||||
|
fs: allowScriptFilesystemAccess ? fs : undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user