chore: add unit test for reserved header

Co-authored-by: Samuel Attard <sattard@anthropic.com>
This commit is contained in:
trop[bot]
2025-12-19 10:09:02 +00:00
committed by GitHub
parent c7987719c0
commit 9ee7a48f33

View File

@@ -1,4 +1,4 @@
import { ipcMain, protocol, session, WebContents, webContents } from 'electron/main';
import { ipcMain, net, protocol, session, WebContents, webContents } from 'electron/main';
import { expect } from 'chai';
import * as WebSocket from 'ws';
@@ -455,6 +455,35 @@ describe('webRequest module', () => {
}));
expect(onSendHeadersCalled).to.be.true();
});
it('can inject Proxy-Authorization header for net module requests', async () => {
// Proxy-Authorization is normally rejected by Chromium's network service
// for security reasons. However, for Electron's trusted net module,
// webRequest.onBeforeSendHeaders should be able to inject it via the
// TrustedHeaderClient code path.
const proxyAuthValue = 'Basic test-credentials';
let receivedProxyAuth: string | undefined;
const server = http.createServer((req, res) => {
receivedProxyAuth = req.headers['proxy-authorization'];
res.end('ok');
});
const { url: serverUrl } = await listen(server);
try {
ses.webRequest.onBeforeSendHeaders((details, callback) => {
const requestHeaders = details.requestHeaders;
requestHeaders['Proxy-Authorization'] = proxyAuthValue;
callback({ requestHeaders });
});
const response = await net.fetch(serverUrl, { bypassCustomProtocolHandlers: true });
expect(response.ok).to.be.true();
expect(receivedProxyAuth).to.equal(proxyAuthValue);
} finally {
server.close();
}
});
});
describe('webRequest.onSendHeaders', () => {