mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-11 09:51:30 +00:00
fix: honor OS-level PAC configuration in system proxy mode (#7766)
This commit is contained in:
6
tests/proxy/system-pac/fixtures/collection/bruno.json
Normal file
6
tests/proxy/system-pac/fixtures/collection/bruno.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"version": "1",
|
||||
"name": "system-pac-proxy-test",
|
||||
"type": "collection",
|
||||
"ignore": []
|
||||
}
|
||||
21
tests/proxy/system-pac/fixtures/collection/direct.bru
Normal file
21
tests/proxy/system-pac/fixtures/collection/direct.bru
Normal file
@@ -0,0 +1,21 @@
|
||||
meta {
|
||||
name: direct
|
||||
type: http
|
||||
seq: 2
|
||||
}
|
||||
|
||||
get {
|
||||
url: http://localhost:19000/direct
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
assert {
|
||||
res.status: eq 200
|
||||
}
|
||||
|
||||
tests {
|
||||
test("request bypassed proxy (system PAC returned DIRECT)", function() {
|
||||
expect(res.headers['x-proxied']).to.be.undefined;
|
||||
});
|
||||
}
|
||||
21
tests/proxy/system-pac/fixtures/collection/proxied.bru
Normal file
21
tests/proxy/system-pac/fixtures/collection/proxied.bru
Normal file
@@ -0,0 +1,21 @@
|
||||
meta {
|
||||
name: proxied
|
||||
type: http
|
||||
seq: 1
|
||||
}
|
||||
|
||||
get {
|
||||
url: http://localhost:19000/proxied
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
assert {
|
||||
res.status: eq 200
|
||||
}
|
||||
|
||||
tests {
|
||||
test("request was routed through system PAC proxy", function() {
|
||||
expect(res.headers['x-proxied']).to.equal('test-proxy');
|
||||
});
|
||||
}
|
||||
14
tests/proxy/system-pac/init-user-data/preferences.json
Normal file
14
tests/proxy/system-pac/init-user-data/preferences.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"maximized": false,
|
||||
"lastOpenedCollections": ["{{projectRoot}}/tests/proxy/system-pac/fixtures/collection"],
|
||||
"preferences": {
|
||||
"onboarding": {
|
||||
"hasLaunchedBefore": true,
|
||||
"hasSeenWelcomeModal": true
|
||||
},
|
||||
"proxy": {
|
||||
"source": "inherit",
|
||||
"config": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
103
tests/proxy/system-pac/system-pac-proxy.spec.ts
Normal file
103
tests/proxy/system-pac/system-pac-proxy.spec.ts
Normal file
@@ -0,0 +1,103 @@
|
||||
import * as path from 'path';
|
||||
import { execFileSync } from 'child_process';
|
||||
import { pathToFileURL } from 'url';
|
||||
import { test } from '../../../playwright';
|
||||
import { setSandboxMode, runCollection, validateRunnerResults } from '../../utils/page';
|
||||
import { startServers, stopServers, PAC_PORT, type TestServers } from '../pac/server';
|
||||
|
||||
// GNOME's system-wide proxy schema — provided by gsettings-desktop-schemas.
|
||||
// Writes need an active dbus session (see CI workflow's dbus-run-session wrapper).
|
||||
const GNOME_PROXY_SCHEMA = 'org.gnome.system.proxy';
|
||||
|
||||
function enableSystemPac(pacUrl: string) {
|
||||
// Set URL first, then flip mode — otherwise auto mode briefly has no URL
|
||||
execFileSync('gsettings', ['set', GNOME_PROXY_SCHEMA, 'autoconfig-url', pacUrl]);
|
||||
execFileSync('gsettings', ['set', GNOME_PROXY_SCHEMA, 'mode', 'auto']);
|
||||
}
|
||||
|
||||
function disableSystemPac() {
|
||||
execFileSync('gsettings', ['reset', GNOME_PROXY_SCHEMA, 'mode']);
|
||||
execFileSync('gsettings', ['reset', GNOME_PROXY_SCHEMA, 'autoconfig-url']);
|
||||
}
|
||||
|
||||
// Detects schema availability so we can skip cleanly on minimal images
|
||||
// (e.g. containers without gsettings-desktop-schemas installed).
|
||||
function gnomeProxySchemaAvailable(): boolean {
|
||||
try {
|
||||
execFileSync('gsettings', ['get', GNOME_PROXY_SCHEMA, 'mode'], { stdio: 'ignore' });
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
test.describe('System Proxy with PAC', () => {
|
||||
test.skip(
|
||||
process.platform !== 'linux',
|
||||
'Linux-only: relies on gsettings to set OS-level PAC'
|
||||
);
|
||||
|
||||
test.skip(
|
||||
process.platform === 'linux' && !gnomeProxySchemaAvailable(),
|
||||
'Linux: skipping because the org.gnome.system.proxy GSettings schema is not available on this runner'
|
||||
);
|
||||
|
||||
let servers: TestServers;
|
||||
|
||||
test.beforeAll(async () => {
|
||||
servers = await startServers();
|
||||
});
|
||||
|
||||
test.afterAll(async () => {
|
||||
// Revert OS proxy settings even if a test failed, so the runner is left clean.
|
||||
try {
|
||||
disableSystemPac();
|
||||
} finally {
|
||||
if (servers) {
|
||||
await stopServers(servers);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Covers the common corporate setup: PAC hosted at an HTTP URL (e.g. WPAD).
|
||||
test('resolves OS-level PAC URL in system proxy mode (HTTP PAC)', async ({ launchElectronApp }) => {
|
||||
const pacUrl = `http://localhost:${PAC_PORT}/test.pac`;
|
||||
enableSystemPac(pacUrl);
|
||||
|
||||
const initUserDataPath = path.join(__dirname, 'init-user-data');
|
||||
const app = await launchElectronApp({ initUserDataPath });
|
||||
|
||||
const page = await app.firstWindow();
|
||||
await page.locator('[data-app-state="loaded"]').waitFor({ timeout: 30000 });
|
||||
|
||||
await setSandboxMode(page, 'system-pac-proxy-test', 'developer');
|
||||
await runCollection(page, 'system-pac-proxy-test');
|
||||
await validateRunnerResults(page, {
|
||||
totalRequests: 2,
|
||||
passed: 2,
|
||||
failed: 0,
|
||||
skipped: 0
|
||||
});
|
||||
});
|
||||
|
||||
// Covers the local-file PAC case (user-selected .pac file on disk).
|
||||
test('resolves OS-level PAC URL in system proxy mode (file:// PAC)', async ({ launchElectronApp }) => {
|
||||
const pacUrl = pathToFileURL(path.join(__dirname, '..', 'pac', 'fixtures', 'pac-files', 'test.pac')).href;
|
||||
enableSystemPac(pacUrl);
|
||||
|
||||
const initUserDataPath = path.join(__dirname, 'init-user-data');
|
||||
const app = await launchElectronApp({ initUserDataPath });
|
||||
|
||||
const page = await app.firstWindow();
|
||||
await page.locator('[data-app-state="loaded"]').waitFor({ timeout: 30000 });
|
||||
|
||||
await setSandboxMode(page, 'system-pac-proxy-test', 'developer');
|
||||
await runCollection(page, 'system-pac-proxy-test');
|
||||
await validateRunnerResults(page, {
|
||||
totalRequests: 2,
|
||||
passed: 2,
|
||||
failed: 0,
|
||||
skipped: 0
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user