diff --git a/packages/bruno-electron/src/ipc/collection.js b/packages/bruno-electron/src/ipc/collection.js index 9cade6668..83ef0c8c9 100644 --- a/packages/bruno-electron/src/ipc/collection.js +++ b/packages/bruno-electron/src/ipc/collection.js @@ -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) { diff --git a/packages/bruno-electron/src/utils/collection-import.js b/packages/bruno-electron/src/utils/collection-import.js index 4cfeac60b..4d541d60f 100644 --- a/packages/bruno-electron/src/utils/collection-import.js +++ b/packages/bruno-electron/src/utils/collection-import.js @@ -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; }; diff --git a/tests/import/bruno/fixtures/bruno-v2-json-collection-with-proxy.json b/tests/import/bruno/fixtures/bruno-v2-json-collection-with-proxy.json new file mode 100644 index 000000000..d8ea92dc5 --- /dev/null +++ b/tests/import/bruno/fixtures/bruno-v2-json-collection-with-proxy.json @@ -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": "" + } + } +} \ No newline at end of file diff --git a/tests/import/bruno/import-bruno-JSON-v2.spec.ts b/tests/import/bruno/import-bruno-JSON-v2.spec.ts new file mode 100644 index 000000000..1c9f3416a --- /dev/null +++ b/tests/import/bruno/import-bruno-JSON-v2.spec.ts @@ -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(); + }); + }); +});