Update the browser, editor, settings, and installer
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import http from 'node:http';
|
||||
import { createGateway } from '../src/gateway.mjs';
|
||||
|
||||
function request(gateway, url, authenticated = true) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const req = http.get({ host: '127.0.0.1', port: gateway.port, path: url, headers: authenticated ? { 'Proxy-Authorization': `Basic ${Buffer.from(`${gateway.username}:${gateway.password}`).toString('base64')}` } : {} }, res => {
|
||||
const chunks = []; res.on('data', chunk => chunks.push(chunk)); res.on('end', () => resolve({ status: res.statusCode, body: Buffer.concat(chunks).toString() }));
|
||||
}); req.on('error', reject);
|
||||
});
|
||||
}
|
||||
test('gateway denies unauthenticated requests, loopback and invalid schemes', async () => {
|
||||
const gateway = await createGateway();
|
||||
try {
|
||||
assert.equal((await request(gateway, 'http://127.0.0.1/', false)).status, 407);
|
||||
assert.equal((await request(gateway, 'http://127.0.0.1/')).status, 403);
|
||||
assert.equal((await request(gateway, 'file:///etc/passwd')).status, 403);
|
||||
assert.equal((await request(gateway, 'http://1.1.1.1:1234/')).status, 403);
|
||||
} finally { await gateway.close(); }
|
||||
});
|
||||
test('gateway connects to the validated address and strips proxy credentials', async () => {
|
||||
const server = http.createServer((req, res) => { assert.equal(req.headers['proxy-authorization'], undefined); res.end(req.headers.host); });
|
||||
await new Promise(resolve => server.listen(0, '127.0.0.1', resolve));
|
||||
let lookups = 0;
|
||||
const gateway = await createGateway({ allowedTestHosts: new Set(['fixture.test']), resolver: async () => { lookups++; return [{ address: '127.0.0.1', family: 4 }]; } });
|
||||
try {
|
||||
const result = await request(gateway, `http://fixture.test:${server.address().port}/`);
|
||||
assert.equal(result.status, 200); assert.match(result.body, /^fixture.test:/); assert.equal(lookups, 1);
|
||||
await gateway.close();
|
||||
await assert.rejects(request(gateway, 'http://fixture.test/'));
|
||||
} finally { await new Promise(resolve => server.close(resolve)); }
|
||||
});
|
||||
Reference in New Issue
Block a user