mirror of
https://github.com/usebruno/bruno.git
synced 2025-02-15 17:29:20 +01:00
Merge remote-tracking branch 'origin' into feature/add-raw-file-request-body-option
This commit is contained in:
commit
559e57d92b
@ -18,6 +18,9 @@
|
|||||||
"pack": "electron-builder --dir",
|
"pack": "electron-builder --dir",
|
||||||
"test": "jest"
|
"test": "jest"
|
||||||
},
|
},
|
||||||
|
"jest": {
|
||||||
|
"modulePaths": ["node_modules"]
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@aws-sdk/credential-providers": "3.525.0",
|
"@aws-sdk/credential-providers": "3.525.0",
|
||||||
"@usebruno/common": "0.1.0",
|
"@usebruno/common": "0.1.0",
|
||||||
|
@ -408,10 +408,13 @@ const registerNetworkIpc = (mainWindow) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// run post-response script
|
// run post-response script
|
||||||
|
const responseScript = compact(scriptingConfig.flow === 'natural' ? [
|
||||||
|
get(collectionRoot, 'request.script.res'), get(request, 'script.res')
|
||||||
|
] : [
|
||||||
|
get(request, 'script.res'), get(collectionRoot, 'request.script.res')
|
||||||
|
]).join(os.EOL);
|
||||||
|
|
||||||
let scriptResult;
|
let scriptResult;
|
||||||
const responseScript = compact([get(request, 'script.res'), get(collectionRoot, 'request.script.res')]).join(
|
|
||||||
os.EOL
|
|
||||||
);
|
|
||||||
if (responseScript?.length) {
|
if (responseScript?.length) {
|
||||||
const scriptRuntime = new ScriptRuntime();
|
const scriptRuntime = new ScriptRuntime();
|
||||||
scriptResult = await scriptRuntime.runResponseScript(
|
scriptResult = await scriptRuntime.runResponseScript(
|
||||||
@ -592,10 +595,13 @@ const registerNetworkIpc = (mainWindow) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// run tests
|
// run tests
|
||||||
const testFile = compact([
|
const testScript = item.draft ? get(item.draft, 'request.tests') : get(item, 'request.tests');
|
||||||
item.draft ? get(item.draft, 'request.tests') : get(item, 'request.tests'),
|
const testFile = compact(scriptingConfig.flow === 'natural' ? [
|
||||||
get(collectionRoot, 'request.tests')
|
get(collectionRoot, 'request.tests'), testScript,
|
||||||
|
] : [
|
||||||
|
testScript, get(collectionRoot, 'request.tests')
|
||||||
]).join(os.EOL);
|
]).join(os.EOL);
|
||||||
|
|
||||||
if (typeof testFile === 'string') {
|
if (typeof testFile === 'string') {
|
||||||
const testRuntime = new TestRuntime();
|
const testRuntime = new TestRuntime();
|
||||||
const testResults = await testRuntime.runTests(
|
const testResults = await testRuntime.runTests(
|
||||||
@ -1029,10 +1035,13 @@ const registerNetworkIpc = (mainWindow) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// run tests
|
// run tests
|
||||||
const testFile = compact([
|
const testScript = item.draft ? get(item.draft, 'request.tests') : get(item, 'request.tests');
|
||||||
item.draft ? get(item.draft, 'request.tests') : get(item, 'request.tests'),
|
const testFile = compact(scriptingConfig.flow === 'natural' ? [
|
||||||
get(collectionRoot, 'request.tests')
|
get(collectionRoot, 'request.tests'), testScript
|
||||||
|
] : [
|
||||||
|
testScript, get(collectionRoot, 'request.tests')
|
||||||
]).join(os.EOL);
|
]).join(os.EOL);
|
||||||
|
|
||||||
if (typeof testFile === 'string') {
|
if (typeof testFile === 'string') {
|
||||||
const testRuntime = new TestRuntime();
|
const testRuntime = new TestRuntime();
|
||||||
const testResults = await testRuntime.runTests(
|
const testResults = await testRuntime.runTests(
|
||||||
|
@ -51,26 +51,26 @@ const getOAuth2AuthorizationCode = (request, codeChallenge, collectionUid) => {
|
|||||||
const { oauth2 } = request;
|
const { oauth2 } = request;
|
||||||
const { callbackUrl, clientId, authorizationUrl, scope, state, pkce } = oauth2;
|
const { callbackUrl, clientId, authorizationUrl, scope, state, pkce } = oauth2;
|
||||||
|
|
||||||
let oauth2QueryParams =
|
const authorizationUrlWithQueryParams = new URL(authorizationUrl);
|
||||||
(authorizationUrl.indexOf('?') > -1 ? '&' : '?') + `client_id=${clientId}&response_type=code`;
|
authorizationUrlWithQueryParams.searchParams.append('response_type', 'code');
|
||||||
|
authorizationUrlWithQueryParams.searchParams.append('client_id', clientId);
|
||||||
if (callbackUrl) {
|
if (callbackUrl) {
|
||||||
oauth2QueryParams += `&redirect_uri=${callbackUrl}`;
|
authorizationUrlWithQueryParams.searchParams.append('redirect_uri', callbackUrl);
|
||||||
}
|
}
|
||||||
if (scope) {
|
if (scope) {
|
||||||
oauth2QueryParams += `&scope=${scope}`;
|
authorizationUrlWithQueryParams.searchParams.append('scope', scope);
|
||||||
}
|
}
|
||||||
if (pkce) {
|
if (pkce) {
|
||||||
oauth2QueryParams += `&code_challenge=${codeChallenge}&code_challenge_method=S256`;
|
authorizationUrlWithQueryParams.searchParams.append('code_challenge', codeChallenge);
|
||||||
|
authorizationUrlWithQueryParams.searchParams.append('code_challenge_method', 'S256');
|
||||||
}
|
}
|
||||||
if (state) {
|
if (state) {
|
||||||
oauth2QueryParams += `&state=${state}`;
|
authorizationUrlWithQueryParams.searchParams.append('state', state);
|
||||||
}
|
}
|
||||||
|
|
||||||
const authorizationUrlWithQueryParams = authorizationUrl + oauth2QueryParams;
|
|
||||||
try {
|
try {
|
||||||
const oauth2Store = new Oauth2Store();
|
const oauth2Store = new Oauth2Store();
|
||||||
const { authorizationCode } = await authorizeUserInWindow({
|
const { authorizationCode } = await authorizeUserInWindow({
|
||||||
authorizeUrl: authorizationUrlWithQueryParams,
|
authorizeUrl: authorizationUrlWithQueryParams.toString(),
|
||||||
callbackUrl,
|
callbackUrl,
|
||||||
session: oauth2Store.getSessionIdOfCollection(collectionUid)
|
session: oauth2Store.getSessionIdOfCollection(collectionUid)
|
||||||
});
|
});
|
||||||
|
@ -119,7 +119,7 @@ const mergeFolderLevelVars = (request, requestTreePath) => {
|
|||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
const mergeFolderLevelScripts = (request, requestTreePath) => {
|
const mergeFolderLevelScripts = (request, requestTreePath, scriptFlow) => {
|
||||||
let folderCombinedPreReqScript = [];
|
let folderCombinedPreReqScript = [];
|
||||||
let folderCombinedPostResScript = [];
|
let folderCombinedPostResScript = [];
|
||||||
let folderCombinedTests = [];
|
let folderCombinedTests = [];
|
||||||
@ -147,12 +147,20 @@ const mergeFolderLevelScripts = (request, requestTreePath) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (folderCombinedPostResScript.length) {
|
if (folderCombinedPostResScript.length) {
|
||||||
|
if (scriptFlow === 'natural') {
|
||||||
|
request.script.res = compact([...folderCombinedPostResScript, request?.script?.res || '']).join(os.EOL);
|
||||||
|
} else {
|
||||||
request.script.res = compact([request?.script?.res || '', ...folderCombinedPostResScript.reverse()]).join(os.EOL);
|
request.script.res = compact([request?.script?.res || '', ...folderCombinedPostResScript.reverse()]).join(os.EOL);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (folderCombinedTests.length) {
|
if (folderCombinedTests.length) {
|
||||||
|
if (scriptFlow === 'natural') {
|
||||||
|
request.tests = compact([...folderCombinedTests, request?.tests || '']).join(os.EOL);
|
||||||
|
} else {
|
||||||
request.tests = compact([request?.tests || '', ...folderCombinedTests.reverse()]).join(os.EOL);
|
request.tests = compact([request?.tests || '', ...folderCombinedTests.reverse()]).join(os.EOL);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const parseFormData = (datas, collectionPath) => {
|
const parseFormData = (datas, collectionPath) => {
|
||||||
@ -301,10 +309,12 @@ const prepareRequest = (item, collection) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// scriptFlow is either "sandwich" or "natural"
|
||||||
|
const scriptFlow = collection.brunoConfig?.scripts?.flow ?? 'sandwich';
|
||||||
const requestTreePath = getTreePathFromCollectionToItem(collection, item);
|
const requestTreePath = getTreePathFromCollectionToItem(collection, item);
|
||||||
if (requestTreePath && requestTreePath.length > 0) {
|
if (requestTreePath && requestTreePath.length > 0) {
|
||||||
mergeFolderLevelHeaders(request, requestTreePath);
|
mergeFolderLevelHeaders(request, requestTreePath);
|
||||||
mergeFolderLevelScripts(request, requestTreePath);
|
mergeFolderLevelScripts(request, requestTreePath, scriptFlow);
|
||||||
mergeFolderLevelVars(request, requestTreePath);
|
mergeFolderLevelVars(request, requestTreePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,25 +1,15 @@
|
|||||||
// damn jest throws an error when no tests are found in a file
|
const { configureRequest } = require('../../src/ipc/network/index');
|
||||||
// --passWithNoTests doesn't work
|
|
||||||
|
|
||||||
describe('dummy test', () => {
|
describe('index: configureRequest', () => {
|
||||||
it('should pass', () => {
|
it("Should add 'http://' to the URL if no protocol is specified", async () => {
|
||||||
expect(true).toBe(true);
|
const request = { method: 'GET', url: 'test-domain', body: {} };
|
||||||
|
await configureRequest(null, request, null, null, null, null);
|
||||||
|
expect(request.url).toEqual('http://test-domain');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should NOT add 'http://' to the URL if a protocol is specified", async () => {
|
||||||
|
const request = { method: 'GET', url: 'ftp://test-domain', body: {} };
|
||||||
|
await configureRequest(null, request, null, null, null, null);
|
||||||
|
expect(request.url).toEqual('ftp://test-domain');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// todo: fix this failing test
|
|
||||||
// const { configureRequest } = require('../../src/ipc/network/index');
|
|
||||||
|
|
||||||
// describe('index: configureRequest', () => {
|
|
||||||
// it("Should add 'http://' to the URL if no protocol is specified", async () => {
|
|
||||||
// const request = { method: 'GET', url: 'test-domain', body: {} };
|
|
||||||
// await configureRequest(null, request, null, null, null, null);
|
|
||||||
// expect(request.url).toEqual('http://test-domain');
|
|
||||||
// });
|
|
||||||
|
|
||||||
// it("Should NOT add 'http://' to the URL if a protocol is specified", async () => {
|
|
||||||
// const request = { method: 'GET', url: 'ftp://test-domain', body: {} };
|
|
||||||
// await configureRequest(null, request, null, null, null, null);
|
|
||||||
// expect(request.url).toEqual('ftp://test-domain');
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
|
Loading…
Reference in New Issue
Block a user