Merge remote-tracking branch 'origin' into feature/add-raw-file-request-body-option

This commit is contained in:
Zachary Elliott 2024-08-03 20:51:01 -06:00
commit 559e57d92b
5 changed files with 56 additions and 44 deletions

View File

@ -18,6 +18,9 @@
"pack": "electron-builder --dir",
"test": "jest"
},
"jest": {
"modulePaths": ["node_modules"]
},
"dependencies": {
"@aws-sdk/credential-providers": "3.525.0",
"@usebruno/common": "0.1.0",

View File

@ -408,10 +408,13 @@ const registerNetworkIpc = (mainWindow) => {
}
// 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;
const responseScript = compact([get(request, 'script.res'), get(collectionRoot, 'request.script.res')]).join(
os.EOL
);
if (responseScript?.length) {
const scriptRuntime = new ScriptRuntime();
scriptResult = await scriptRuntime.runResponseScript(
@ -592,10 +595,13 @@ const registerNetworkIpc = (mainWindow) => {
}
// run tests
const testFile = compact([
item.draft ? get(item.draft, 'request.tests') : get(item, 'request.tests'),
get(collectionRoot, 'request.tests')
const testScript = item.draft ? get(item.draft, 'request.tests') : get(item, 'request.tests');
const testFile = compact(scriptingConfig.flow === 'natural' ? [
get(collectionRoot, 'request.tests'), testScript,
] : [
testScript, get(collectionRoot, 'request.tests')
]).join(os.EOL);
if (typeof testFile === 'string') {
const testRuntime = new TestRuntime();
const testResults = await testRuntime.runTests(
@ -1029,10 +1035,13 @@ const registerNetworkIpc = (mainWindow) => {
}
// run tests
const testFile = compact([
item.draft ? get(item.draft, 'request.tests') : get(item, 'request.tests'),
get(collectionRoot, 'request.tests')
const testScript = item.draft ? get(item.draft, 'request.tests') : get(item, 'request.tests');
const testFile = compact(scriptingConfig.flow === 'natural' ? [
get(collectionRoot, 'request.tests'), testScript
] : [
testScript, get(collectionRoot, 'request.tests')
]).join(os.EOL);
if (typeof testFile === 'string') {
const testRuntime = new TestRuntime();
const testResults = await testRuntime.runTests(

View File

@ -51,26 +51,26 @@ const getOAuth2AuthorizationCode = (request, codeChallenge, collectionUid) => {
const { oauth2 } = request;
const { callbackUrl, clientId, authorizationUrl, scope, state, pkce } = oauth2;
let oauth2QueryParams =
(authorizationUrl.indexOf('?') > -1 ? '&' : '?') + `client_id=${clientId}&response_type=code`;
const authorizationUrlWithQueryParams = new URL(authorizationUrl);
authorizationUrlWithQueryParams.searchParams.append('response_type', 'code');
authorizationUrlWithQueryParams.searchParams.append('client_id', clientId);
if (callbackUrl) {
oauth2QueryParams += `&redirect_uri=${callbackUrl}`;
authorizationUrlWithQueryParams.searchParams.append('redirect_uri', callbackUrl);
}
if (scope) {
oauth2QueryParams += `&scope=${scope}`;
authorizationUrlWithQueryParams.searchParams.append('scope', scope);
}
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) {
oauth2QueryParams += `&state=${state}`;
authorizationUrlWithQueryParams.searchParams.append('state', state);
}
const authorizationUrlWithQueryParams = authorizationUrl + oauth2QueryParams;
try {
const oauth2Store = new Oauth2Store();
const { authorizationCode } = await authorizeUserInWindow({
authorizeUrl: authorizationUrlWithQueryParams,
authorizeUrl: authorizationUrlWithQueryParams.toString(),
callbackUrl,
session: oauth2Store.getSessionIdOfCollection(collectionUid)
});

View File

@ -119,7 +119,7 @@ const mergeFolderLevelVars = (request, requestTreePath) => {
}));
};
const mergeFolderLevelScripts = (request, requestTreePath) => {
const mergeFolderLevelScripts = (request, requestTreePath, scriptFlow) => {
let folderCombinedPreReqScript = [];
let folderCombinedPostResScript = [];
let folderCombinedTests = [];
@ -147,11 +147,19 @@ const mergeFolderLevelScripts = (request, requestTreePath) => {
}
if (folderCombinedPostResScript.length) {
request.script.res = compact([request?.script?.res || '', ...folderCombinedPostResScript.reverse()]).join(os.EOL);
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);
}
}
if (folderCombinedTests.length) {
request.tests = compact([request?.tests || '', ...folderCombinedTests.reverse()]).join(os.EOL);
if (scriptFlow === 'natural') {
request.tests = compact([...folderCombinedTests, request?.tests || '']).join(os.EOL);
} else {
request.tests = compact([request?.tests || '', ...folderCombinedTests.reverse()]).join(os.EOL);
}
}
};
@ -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);
if (requestTreePath && requestTreePath.length > 0) {
mergeFolderLevelHeaders(request, requestTreePath);
mergeFolderLevelScripts(request, requestTreePath);
mergeFolderLevelScripts(request, requestTreePath, scriptFlow);
mergeFolderLevelVars(request, requestTreePath);
}

View File

@ -1,25 +1,15 @@
// damn jest throws an error when no tests are found in a file
// --passWithNoTests doesn't work
const { configureRequest } = require('../../src/ipc/network/index');
describe('dummy test', () => {
it('should pass', () => {
expect(true).toBe(true);
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');
});
});
// 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');
// });
// });