mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-17 21:15:32 +09:00
fix(desktop): honour the system proxy in main-process requests (#3270)
This commit is contained in:
1 parent
6de6be2358
commit
3071bc7525
16 files changed
+542
-19
No files matched your search
@@ -726,6 +726,116 @@ describe('DesktopSelectedInstanceClient', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('DesktopOutboundHTTP system proxy routes', () => {
|
||||
function proxiedOutboundHTTP() {
|
||||
const sent = [];
|
||||
const resolved = [];
|
||||
const outboundHTTP = new DesktopOutboundHTTP({
|
||||
resolveHostAddresses: async (hostname) => {
|
||||
resolved.push(hostname);
|
||||
throw Object.assign(new Error(`getaddrinfo ENOTFOUND ${hostname}`), {syscall: 'getaddrinfo'});
|
||||
},
|
||||
resolveProxy: async (url) =>
|
||||
url.startsWith('https://direct.example') ? 'DIRECT' : 'PROXY 127.0.0.1:7890; DIRECT',
|
||||
sendThroughSession: async (request) => {
|
||||
sent.push({method: request.method, url: request.url.href, headers: request.headers});
|
||||
return {
|
||||
headers: {'content-type': 'image/png'},
|
||||
message: Readable.from([PNG_BYTES]),
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
};
|
||||
},
|
||||
});
|
||||
return {outboundHTTP, resolved, sent};
|
||||
}
|
||||
|
||||
test('an instance behind the system proxy is anchored and fetched without a local lookup', async () => {
|
||||
const {outboundHTTP, resolved, sent} = proxiedOutboundHTTP();
|
||||
const requirement = await outboundHTTP.registerAnchoredOrigins({
|
||||
anchorOrigin: 'https://api.blocked.example',
|
||||
origins: ['https://media.blocked.example'],
|
||||
});
|
||||
assert.equal(requirement, 'public');
|
||||
const message = await outboundHTTP.request({
|
||||
body: null,
|
||||
expectedOrigin: 'https://media.blocked.example',
|
||||
headers: {Accept: 'image/png'},
|
||||
method: 'GET',
|
||||
originTrust: DesktopOriginTrust.REGISTERED,
|
||||
serviceName: 'test',
|
||||
signal: null,
|
||||
timeoutMs: 500,
|
||||
url: 'https://media.blocked.example/avatar.png',
|
||||
});
|
||||
assert.deepEqual(
|
||||
await readBoundedMessage({
|
||||
declaredBytes: null,
|
||||
description: 'proxied',
|
||||
maxBytes: 64,
|
||||
maxChunks: 4,
|
||||
message: message.message,
|
||||
}),
|
||||
PNG_BYTES,
|
||||
);
|
||||
assert.deepEqual(resolved, []);
|
||||
assert.deepEqual(sent, [
|
||||
{method: 'GET', url: 'https://media.blocked.example/avatar.png', headers: {Accept: 'image/png'}},
|
||||
]);
|
||||
outboundHTTP.cleanup();
|
||||
});
|
||||
|
||||
test('a proxied download goes through the session and a direct one keeps the pinned lookup', async () => {
|
||||
const {outboundHTTP, resolved, sent} = proxiedOutboundHTTP();
|
||||
const message = await outboundHTTP.get({
|
||||
context: 'test',
|
||||
timeoutMs: 500,
|
||||
url: new URL('https://cdn.blocked.example/icon.png'),
|
||||
});
|
||||
message.message.resume();
|
||||
await assert.rejects(
|
||||
outboundHTTP.get({context: 'test', timeoutMs: 500, url: new URL('https://direct.example/icon.png')}),
|
||||
/could not be reached/,
|
||||
);
|
||||
assert.deepEqual(
|
||||
sent.map((entry) => entry.url),
|
||||
['https://cdn.blocked.example/icon.png'],
|
||||
);
|
||||
assert.deepEqual(resolved, ['direct.example']);
|
||||
outboundHTTP.cleanup();
|
||||
});
|
||||
|
||||
test('a proxied route keeps the cleartext and private address rules', async () => {
|
||||
const {outboundHTTP, sent} = proxiedOutboundHTTP();
|
||||
await outboundHTTP.registerAnchoredOrigins({
|
||||
anchorOrigin: 'https://api.blocked.example',
|
||||
origins: ['http://10.0.0.1'],
|
||||
});
|
||||
const request = (url, originTrust = DesktopOriginTrust.BOUND) => ({
|
||||
body: null,
|
||||
expectedOrigin: new URL(url).origin,
|
||||
headers: null,
|
||||
method: 'GET',
|
||||
originTrust,
|
||||
serviceName: 'test',
|
||||
signal: null,
|
||||
timeoutMs: 500,
|
||||
url,
|
||||
});
|
||||
await assert.rejects(outboundHTTP.request(request('http://plain.blocked.example/x')), /requires https/);
|
||||
await assert.rejects(
|
||||
outboundHTTP.request(request('http://10.0.0.1/x', DesktopOriginTrust.REGISTERED)),
|
||||
/cannot authorize the privately resolving origin/,
|
||||
);
|
||||
await assert.rejects(
|
||||
outboundHTTP.get({context: 'test', timeoutMs: 500, url: new URL('https://10.0.0.1/x')}),
|
||||
/could not be reached/,
|
||||
);
|
||||
assert.deepEqual(sent, []);
|
||||
outboundHTTP.cleanup();
|
||||
});
|
||||
});
|
||||
|
||||
describe('desktop instance launch surfaces', () => {
|
||||
test('--fluxer-instance is a development-only API endpoint flag', () => {
|
||||
const originalDefaultApp = process.defaultApp;
|
||||
|
||||
Reference in new issue
Block a user