Install: log proxy use, if any, to aid with debugging

This commit is contained in:
Lovell Fuller 2022-12-06 19:35:47 +00:00
parent 9d760f3958
commit def99a294a
3 changed files with 14 additions and 7 deletions

View File

@ -167,7 +167,7 @@ try {
} else { } else {
const url = distBaseUrl + tarFilename; const url = distBaseUrl + tarFilename;
libvips.log(`Downloading ${url}`); libvips.log(`Downloading ${url}`);
simpleGet({ url: url, agent: agent() }, function (err, response) { simpleGet({ url: url, agent: agent(libvips.log) }, function (err, response) {
if (err) { if (err) {
fail(err); fail(err);
} else if (response.statusCode === 404) { } else if (response.statusCode === 404) {

View File

@ -18,7 +18,7 @@ function env (key) {
return process.env[key]; return process.env[key];
} }
module.exports = function () { module.exports = function (log) {
try { try {
const proxy = new url.URL(proxies.map(env).find(is.string)); const proxy = new url.URL(proxies.map(env).find(is.string));
const tunnel = proxy.protocol === 'https:' const tunnel = proxy.protocol === 'https:'
@ -27,6 +27,7 @@ module.exports = function () {
const proxyAuth = proxy.username && proxy.password const proxyAuth = proxy.username && proxy.password
? `${decodeURIComponent(proxy.username)}:${decodeURIComponent(proxy.password)}` ? `${decodeURIComponent(proxy.username)}:${decodeURIComponent(proxy.password)}`
: null; : null;
log(`Via proxy ${proxy.protocol}://${proxy.hostname}:${proxy.port} ${proxyAuth ? 'with' : 'no'} credentials`);
return tunnel({ return tunnel({
proxy: { proxy: {
port: Number(proxy.port), port: Number(proxy.port),

View File

@ -10,34 +10,40 @@ describe('HTTP agent', function () {
it('HTTPS proxy with auth from HTTPS_PROXY', function () { it('HTTPS proxy with auth from HTTPS_PROXY', function () {
process.env.HTTPS_PROXY = 'https://user:pass@secure:123'; process.env.HTTPS_PROXY = 'https://user:pass@secure:123';
const proxy = agent(); let logMsg = '';
const proxy = agent(msg => { logMsg = msg; });
delete process.env.HTTPS_PROXY; delete process.env.HTTPS_PROXY;
assert.strictEqual('object', typeof proxy); assert.strictEqual('object', typeof proxy);
assert.strictEqual('secure', proxy.options.proxy.host); assert.strictEqual('secure', proxy.options.proxy.host);
assert.strictEqual(123, proxy.options.proxy.port); assert.strictEqual(123, proxy.options.proxy.port);
assert.strictEqual('user:pass', proxy.options.proxy.proxyAuth); assert.strictEqual('user:pass', proxy.options.proxy.proxyAuth);
assert.strictEqual(443, proxy.defaultPort); assert.strictEqual(443, proxy.defaultPort);
assert.strictEqual(logMsg, 'Via proxy https:://secure:123 with credentials');
}); });
it('HTTPS proxy with auth from HTTPS_PROXY using credentials containing special characters', function () { it('HTTPS proxy with auth from HTTPS_PROXY using credentials containing special characters', function () {
process.env.HTTPS_PROXY = 'https://user,:pass=@secure:123'; process.env.HTTPS_PROXY = 'https://user,:pass=@secure:789';
const proxy = agent(); let logMsg = '';
const proxy = agent(msg => { logMsg = msg; });
delete process.env.HTTPS_PROXY; delete process.env.HTTPS_PROXY;
assert.strictEqual('object', typeof proxy); assert.strictEqual('object', typeof proxy);
assert.strictEqual('secure', proxy.options.proxy.host); assert.strictEqual('secure', proxy.options.proxy.host);
assert.strictEqual(123, proxy.options.proxy.port); assert.strictEqual(789, proxy.options.proxy.port);
assert.strictEqual('user,:pass=', proxy.options.proxy.proxyAuth); assert.strictEqual('user,:pass=', proxy.options.proxy.proxyAuth);
assert.strictEqual(443, proxy.defaultPort); assert.strictEqual(443, proxy.defaultPort);
assert.strictEqual(logMsg, 'Via proxy https:://secure:789 with credentials');
}); });
it('HTTP proxy without auth from npm_config_proxy', function () { it('HTTP proxy without auth from npm_config_proxy', function () {
process.env.npm_config_proxy = 'http://plaintext:456'; process.env.npm_config_proxy = 'http://plaintext:456';
const proxy = agent(); let logMsg = '';
const proxy = agent(msg => { logMsg = msg; });
delete process.env.npm_config_proxy; delete process.env.npm_config_proxy;
assert.strictEqual('object', typeof proxy); assert.strictEqual('object', typeof proxy);
assert.strictEqual('plaintext', proxy.options.proxy.host); assert.strictEqual('plaintext', proxy.options.proxy.host);
assert.strictEqual(456, proxy.options.proxy.port); assert.strictEqual(456, proxy.options.proxy.port);
assert.strictEqual(null, proxy.options.proxy.proxyAuth); assert.strictEqual(null, proxy.options.proxy.proxyAuth);
assert.strictEqual(443, proxy.defaultPort); assert.strictEqual(443, proxy.defaultPort);
assert.strictEqual(logMsg, 'Via proxy http:://plaintext:456 no credentials');
}); });
}); });