mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-11 09:51:30 +00:00
fix(proxy): proxy config export from v2 to import in v3 (#8112)
* FIXED regression for proxy config from v2 to v3 * REMOVED console.log * ADDED test case with fixture to test proxy import * ADDED proxy handling for older brunoConfig in packages/bruno-electron/src/utils/collection-import.js * RESOLVED githiub converstation changed afterAll --> afterEach * ADDED guard to transformProxyConfig(brunoConfig.proxy) function
This commit is contained in:
@@ -28,6 +28,7 @@ const { cookiesStore } = require('../store/cookies');
|
||||
const { parseLargeRequestWithRedaction } = require('../utils/parse');
|
||||
const { wsClient } = require('../ipc/network/ws-event-handlers');
|
||||
const { hasSubDirectories } = require('../utils/filesystem');
|
||||
const { transformProxyConfig } = require('@usebruno/requests');
|
||||
|
||||
const {
|
||||
DEFAULT_GITIGNORE,
|
||||
@@ -1227,7 +1228,9 @@ const registerRendererEventHandlers = (mainWindow, watcher) => {
|
||||
ignore: ['node_modules', '.git']
|
||||
};
|
||||
}
|
||||
|
||||
if (brunoConfig.proxy) {
|
||||
brunoConfig.proxy = transformProxyConfig(brunoConfig.proxy);
|
||||
}
|
||||
return brunoConfig;
|
||||
};
|
||||
|
||||
@@ -2442,7 +2445,7 @@ const registerRendererEventHandlers = (mainWindow, watcher) => {
|
||||
|
||||
await fsExtra.move(collectionDir, finalCollectionPath);
|
||||
if (tempDir !== collectionDir) {
|
||||
await fsExtra.remove(tempDir).catch(() => {});
|
||||
await fsExtra.remove(tempDir).catch(() => { });
|
||||
}
|
||||
|
||||
const uid = generateUidBasedOnHash(finalCollectionPath);
|
||||
@@ -2455,7 +2458,7 @@ const registerRendererEventHandlers = (mainWindow, watcher) => {
|
||||
|
||||
return finalCollectionPath;
|
||||
} catch (error) {
|
||||
await fsExtra.remove(tempDir).catch(() => {});
|
||||
await fsExtra.remove(tempDir).catch(() => { });
|
||||
throw error;
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -4,6 +4,7 @@ const { ipcMain } = require('electron');
|
||||
const { sanitizeName, createDirectory, writeFile, safeWriteFileSync, getCollectionStats } = require('./filesystem');
|
||||
const { generateUidBasedOnHash, stringifyJson } = require('./common');
|
||||
const { stringifyRequestViaWorker, stringifyCollection, stringifyEnvironment, stringifyFolder, DEFAULT_COLLECTION_FORMAT } = require('@usebruno/filestore');
|
||||
const { transformProxyConfig } = require('@usebruno/requests/dist/cjs');
|
||||
|
||||
/**
|
||||
* Recursively find a unique folder name by appending incremental numbers
|
||||
@@ -93,6 +94,10 @@ async function importCollection(collection, collectionLocation, mainWindow, uniq
|
||||
};
|
||||
}
|
||||
|
||||
if (brunoConfig.proxy) {
|
||||
brunoConfig.proxy = transformProxyConfig(brunoConfig.proxy);
|
||||
}
|
||||
|
||||
return brunoConfig;
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
{
|
||||
"name": "proxy-collection-v2",
|
||||
"version": "1",
|
||||
"items": [
|
||||
{
|
||||
"type": "http",
|
||||
"name": "proxy-get",
|
||||
"filename": "proxy-get.bru",
|
||||
"seq": 1,
|
||||
"settings": {
|
||||
"encodeUrl": true,
|
||||
"timeout": 0
|
||||
},
|
||||
"tags": [],
|
||||
"request": {
|
||||
"url": "https://httpbin.org/get?paramName=paramValue",
|
||||
"method": "GET",
|
||||
"headers": [
|
||||
{
|
||||
"name": "headerKey",
|
||||
"value": "headerValue",
|
||||
"enabled": true
|
||||
}
|
||||
],
|
||||
"params": [
|
||||
{
|
||||
"name": "paramName",
|
||||
"value": "paramValue",
|
||||
"type": "query",
|
||||
"enabled": true
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"mode": "none",
|
||||
"formUrlEncoded": [],
|
||||
"multipartForm": [],
|
||||
"file": []
|
||||
},
|
||||
"script": {},
|
||||
"vars": {},
|
||||
"assertions": [],
|
||||
"tests": "",
|
||||
"docs": "",
|
||||
"auth": {
|
||||
"mode": "inherit"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"environments": [],
|
||||
"root": {
|
||||
"request": {
|
||||
"headers": [
|
||||
{
|
||||
"name": "collectionHeader",
|
||||
"value": "collectionHeaderValue",
|
||||
"enabled": true,
|
||||
"uid": "ZPXDKmXFtuYkq1KLjYIlz"
|
||||
}
|
||||
]
|
||||
},
|
||||
"docs": "This is collection Doc"
|
||||
},
|
||||
"brunoConfig": {
|
||||
"version": "1",
|
||||
"name": "proxy-collection-v2",
|
||||
"type": "collection",
|
||||
"ignore": [
|
||||
"node_modules",
|
||||
".git"
|
||||
],
|
||||
"size": 0.0001430511474609375,
|
||||
"filesCount": 1,
|
||||
"proxy": {
|
||||
"enabled": true,
|
||||
"protocol": "http",
|
||||
"hostname": "127.0.0.1",
|
||||
"port": 8080,
|
||||
"auth": {
|
||||
"enabled": false,
|
||||
"username": "",
|
||||
"password": ""
|
||||
},
|
||||
"bypassProxy": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
37
tests/import/bruno/import-bruno-JSON-v2.spec.ts
Normal file
37
tests/import/bruno/import-bruno-JSON-v2.spec.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import path from 'path';
|
||||
import { test, expect } from '../../../playwright';
|
||||
import { importCollection, closeAllCollections } from '../../utils/page';
|
||||
import { buildCommonLocators } from '../../utils/page/locators';
|
||||
|
||||
test.describe('Import Bruno v2 JSON collection', () => {
|
||||
test.afterEach(async ({ page }) => {
|
||||
await closeAllCollections(page);
|
||||
});
|
||||
|
||||
test('proxy settings are preserved after importing a v2 JSON collection', async ({ page, createTmpDir }) => {
|
||||
const collectionName = 'proxy-collection-v2';
|
||||
const collectionFile = path.join(__dirname, 'fixtures', 'bruno-v2-json-collection-with-proxy.json');
|
||||
const locators = buildCommonLocators(page);
|
||||
|
||||
await test.step('Import v2 JSON collection', async () => {
|
||||
await importCollection(page, collectionFile, await createTmpDir('v2-json-proxy-import'), {
|
||||
expectedCollectionName: collectionName
|
||||
});
|
||||
});
|
||||
|
||||
await test.step('Open collection settings → Proxy tab', async () => {
|
||||
await locators.sidebar.collection(collectionName).hover();
|
||||
await locators.actions.collectionActions(collectionName).click();
|
||||
await locators.dropdown.item('Settings').click();
|
||||
await locators.paneTabs.collectionSettingsTab('proxy').click();
|
||||
});
|
||||
|
||||
await test.step('Verify proxy settings match the imported file', async () => {
|
||||
await expect(page.locator('input[name="enabled"][value="true"]')).toBeChecked();
|
||||
await expect(page.locator('input[name="protocol"][value="http"]')).toBeChecked();
|
||||
await expect(page.locator('#hostname')).toHaveValue('127.0.0.1');
|
||||
await expect(page.locator('#port')).toHaveValue('8080');
|
||||
await expect(page.locator('input[name="auth.disabled"]')).not.toBeChecked();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user