Skip to content

Commit a3f0e2f

Browse files
author
kanhaiya
committed
Proxy fix for requested URLs
1 parent 67f21d7 commit a3f0e2f

File tree

5 files changed

+103
-18
lines changed

5 files changed

+103
-18
lines changed

lib/conf/node-tunnel-config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"tunnelBinary":{"mac":{"32bit":{"httpPath":"https://downloads.lambdatest.com/tunnel/mac/32bit/LT_Mac.zip","binaryName":"LT_Mac.zip","newHttpPath":"https://downloads.lambdatest.com/tunnel/mac/32bit/ltcomponent.zip","newBinaryName":"ltcomponent.zip","hash":"e75d47b0f7947925ddc9e7843ff41024"},"64bit":{"httpPath":"https://downloads.lambdatest.com/tunnel/mac/64bit/LT_Mac.zip","binaryName":"LT_Mac.zip","newHttpPath":"https://downloads.lambdatest.com/tunnel/mac/64bit/ltcomponent.zip","newBinaryName":"ltcomponent.zip","hash":"f0650d1d444b7f39df92c5bcc9a898c6"}},"win":{"32bit":{"httpPath":"https://downloads.lambdatest.com/tunnel/windows/32bit/LT_Windows.zip","binaryName":"LT_Windows.zip","newHttpPath":"https://downloads.lambdatest.com/tunnel/windows/32bit/ltcomponent.zip","newBinaryName":"ltcomponent.zip","hash":"ce24f90aa3dfb4d875a28150705f16d1"},"64bit":{"httpPath":"https://downloads.lambdatest.com/tunnel/windows/64bit/LT_Windows.zip","binaryName":"LT_Windows.zip","newHttpPath":"https://downloads.lambdatest.com/tunnel/windows/64bit/ltcomponent.zip","newBinaryName":"ltcomponent.zip","hash":"09d8e29dc1ba5f809b110a14414b52ce"}},"linux":{"32bit":{"httpPath":"https://downloads.lambdatest.com/tunnel/linux/32bit/LT_Linux.zip","binaryName":"LT_Linux.zip","newHttpPath":"https://downloads.lambdatest.com/tunnel/linux/32bit/ltcomponent.zip","newBinaryName":"ltcomponent.zip","hash":"5de336ce0afc3f2987177b18827bdb32"},"64bit":{"httpPath":"https://downloads.lambdatest.com/tunnel/linux/64bit/LT_Linux.zip","binaryName":"LT_Linux.zip","newHttpPath":"https://downloads.lambdatest.com/tunnel/linux/64bit/ltcomponent.zip","newBinaryName":"ltcomponent.zip","hash":"3c5e5938475ca6a51fafecf18a1c9c12"}},"freebsd":{"32bit":{"newHttpPath":"https://downloads.lambdatest.com/tunnel/freebsd/32bit/ltcomponent.zip","newBinaryName":"ltcomponent.zip","hash":"34935e55c36d25bf88c3fd98828be205"},"64bit":{"newHttpPath":"https://downloads.lambdatest.com/tunnel/freebsd/64bit/ltcomponent.zip","newBinaryName":"ltcomponent.zip","hash":"5750dd654c543ba960f468842b641cbd"}}},"AuthUrl":"https://accounts.lambdatest.com/api/user/token/auth","logEnable":true,"latest":"1.1.3","supportedVersions":["1.0.0","1.0.1","1.0.2","1.0.3","1.0.4","1.0.5","1.0.6","1.0.7","1.0.8","1.0.9","1.1.0","1.1.1","1.1.2","1.1.3","1.1.4","2.0.0","3.0.0","4.0.0","5.0.0"]}
1+
{"tunnelBinary":{"mac":{"32bit":{"httpPath":"https://downloads.lambdatest.com/tunnel/mac/32bit/LT_Mac.zip","binaryName":"LT_Mac.zip","newHttpPath":"https://downloads.lambdatest.com/tunnel/mac/32bit/ltcomponent.zip","newBinaryName":"ltcomponent.zip","hash":"34433fb765db9fe993cc51a79a9dc056"},"64bit":{"httpPath":"https://downloads.lambdatest.com/tunnel/mac/64bit/LT_Mac.zip","binaryName":"LT_Mac.zip","newHttpPath":"https://downloads.lambdatest.com/tunnel/mac/64bit/ltcomponent.zip","newBinaryName":"ltcomponent.zip","hash":"6ca43777f406f8d658320f2bf0e57169"}},"win":{"32bit":{"httpPath":"https://downloads.lambdatest.com/tunnel/windows/32bit/LT_Windows.zip","binaryName":"LT_Windows.zip","newHttpPath":"https://downloads.lambdatest.com/tunnel/windows/32bit/ltcomponent.zip","newBinaryName":"ltcomponent.zip","hash":"479633a1aa44065814c792b7ddcbe02a"},"64bit":{"httpPath":"https://downloads.lambdatest.com/tunnel/windows/64bit/LT_Windows.zip","binaryName":"LT_Windows.zip","newHttpPath":"https://downloads.lambdatest.com/tunnel/windows/64bit/ltcomponent.zip","newBinaryName":"ltcomponent.zip","hash":"2019aeadb57594dca15d9b95fdbbcc69"}},"linux":{"32bit":{"httpPath":"https://downloads.lambdatest.com/tunnel/linux/32bit/LT_Linux.zip","binaryName":"LT_Linux.zip","newHttpPath":"https://downloads.lambdatest.com/tunnel/linux/32bit/ltcomponent.zip","newBinaryName":"ltcomponent.zip","hash":"6aebc2fd59120aeb81b8041509713a73"},"64bit":{"httpPath":"https://downloads.lambdatest.com/tunnel/linux/64bit/LT_Linux.zip","binaryName":"LT_Linux.zip","newHttpPath":"https://downloads.lambdatest.com/tunnel/linux/64bit/ltcomponent.zip","newBinaryName":"ltcomponent.zip","hash":"af49cab379849f774978fcccb9cb4e33"}},"freebsd":{"32bit":{"newHttpPath":"https://downloads.lambdatest.com/tunnel/freebsd/32bit/ltcomponent.zip","newBinaryName":"ltcomponent.zip","hash":"8a6dddd85d37576de4f5dc1bd0e54b4d"},"64bit":{"newHttpPath":"https://downloads.lambdatest.com/tunnel/freebsd/64bit/ltcomponent.zip","newBinaryName":"ltcomponent.zip","hash":"c75bae7743d743d0c265118005cb5d6a"}}},"AuthUrl":"https://accounts.lambdatest.com/api/user/token/auth","logEnable":true,"latest":"1.1.4","supportedVersions":["1.0.0","1.0.1","1.0.2","1.0.3","1.0.4","1.0.5","1.0.6","1.0.7","1.0.8","1.0.9","1.1.0","1.1.1","1.1.2","1.1.3","1.1.4","2.0.0","3.0.0","4.0.0","5.0.0"]}

lib/config.js

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,32 @@
11
var httpTunnelConfigPath =
22
'https://s3.amazonaws.com/downloads.lambdatest.com/tunnel/node-tunnel-config.json',
3-
httpTunnelLogUrl = 'https://oinwgsy681.execute-api.us-east-1.amazonaws.com/prod/addLog';
4-
var https = require('https');
5-
var urlParse = require('url');
6-
module.exports = function(fnCallback) {
3+
httpTunnelLogUrl = 'https://oinwgsy681.execute-api.us-east-1.amazonaws.com/prod/addLog',
4+
https = require('https'),
5+
urlParse = require('url'),
6+
HttpsProxyAgent = require('https-proxy-agent');
7+
module.exports = function(options, fnCallback) {
8+
var reqOptions = urlParse.parse(httpTunnelConfigPath);
9+
var proxyOpts = {};
10+
if (options.proxyHost && options.proxyPort) {
11+
proxyOpts = {
12+
host: options.proxyHost,
13+
port: options.proxyPort
14+
};
15+
} else if (process.env.http_proxy) {
16+
proxyOpts = urlParse.parse(process.env.http_proxy);
17+
}
18+
if ((options.proxyUser && !options.proxyPass) || (!options.proxyUser && options.proxyPass)) {
19+
throw Error('proxyUser and proxyPass must be both or none');
20+
} else if (options.proxyUser && options.proxyPass) {
21+
if (Object.keys(proxyOpts).length) {
22+
proxyOpts.auth = options.proxyUser + ':' + options.proxyPass;
23+
}
24+
}
25+
if (Object.keys(proxyOpts).length) {
26+
reqOptions.agent = new HttpsProxyAgent(proxyOpts);
27+
}
728
https
8-
.get(httpTunnelConfigPath, resp => {
29+
.get(reqOptions, resp => {
930
let json = '';
1031
resp.on('data', chunk => {
1132
json += chunk;
@@ -16,7 +37,7 @@ module.exports = function(fnCallback) {
1637
}
1738
return fnCallback(false, {
1839
jsonResponse: json,
19-
logger: setupLogger_(json)
40+
logger: setupLogger_(options, json)
2041
});
2142
});
2243
})
@@ -30,7 +51,7 @@ module.exports = function(fnCallback) {
3051
* @param {Object} jsonResponse path of downloaded binary.
3152
* @return {Object|Error} Return log method or Error is any
3253
*/
33-
function setupLogger_(jsonResponse) {
54+
function setupLogger_(options, jsonResponse) {
3455
try {
3556
var logger;
3657
if (jsonResponse.logEnable) {
@@ -59,7 +80,7 @@ function setupLogger_(jsonResponse) {
5980
}
6081
});
6182
var _httpTunnelLogUrl = urlParse.parse(httpTunnelLogUrl);
62-
var options = {
83+
var reqOptions = {
6384
hostname: _httpTunnelLogUrl.hostname,
6485
port: _httpTunnelLogUrl.port,
6586
path: _httpTunnelLogUrl.path,
@@ -70,7 +91,30 @@ function setupLogger_(jsonResponse) {
7091
'Content-Length': data.length
7192
}
7293
};
73-
var req = https.request(options, res => {
94+
95+
var proxyOpts = {};
96+
if (options.proxyHost && options.proxyPort) {
97+
proxyOpts = {
98+
host: options.proxyHost,
99+
port: options.proxyPort
100+
};
101+
} else if (process.env.http_proxy) {
102+
proxyOpts = urlParse.parse(process.env.http_proxy);
103+
}
104+
if (
105+
(options.proxyUser && !options.proxyPass) ||
106+
(!options.proxyUser && options.proxyPass)
107+
) {
108+
throw Error('proxyUser and proxyPass must be both or none');
109+
} else if (options.proxyUser && options.proxyPass) {
110+
if (Object.keys(proxyOpts).length) {
111+
proxyOpts.auth = options.proxyUser + ':' + options.proxyPass;
112+
}
113+
}
114+
if (Object.keys(proxyOpts).length) {
115+
reqOptions.agent = new HttpsProxyAgent(proxyOpts);
116+
}
117+
var req = https.request(reqOptions, res => {
74118
res.on('data', d => {
75119
process.stdout.write(d);
76120
});

lib/tunnel.js

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var childProcess = require('child_process'),
44
https = require('https'),
55
http = require('http'),
66
urlParse = require('url'),
7+
HttpsProxyAgent = require('https-proxy-agent'),
78
getPort = require('get-port'),
89
os = require('os'),
910
logger,
@@ -43,7 +44,7 @@ function Tunnel() {
4344
return reject({ message: 'user and key is required' });
4445
}
4546
// Configure logger
46-
Config_(function(error, response) {
47+
Config_(options, function(error, response) {
4748
if (error) {
4849
throw new Error(error);
4950
}
@@ -389,7 +390,7 @@ function verifyToken_(options, fnCallback) {
389390
});
390391

391392
var _httpAuthUrl = urlParse.parse(httpTunnelConfig.jsonResponse.AuthUrl);
392-
var options = {
393+
var reqOptions = {
393394
hostname: _httpAuthUrl.hostname,
394395
port: _httpAuthUrl.port,
395396
path: _httpAuthUrl.path,
@@ -403,7 +404,26 @@ function verifyToken_(options, fnCallback) {
403404
}
404405
};
405406

406-
var req = https.request(options, resp => {
407+
var proxyOpts = {};
408+
if (options.proxyHost && options.proxyPort) {
409+
proxyOpts = {
410+
host: options.proxyHost,
411+
port: options.proxyPort
412+
};
413+
} else if (process.env.http_proxy) {
414+
proxyOpts = urlParse.parse(process.env.http_proxy);
415+
}
416+
if ((options.proxyUser && !options.proxyPass) || (!options.proxyUser && options.proxyPass)) {
417+
throw Error('proxyUser and proxyPass must be both or none');
418+
} else if (options.proxyUser && options.proxyPass) {
419+
if (Object.keys(proxyOpts).length) {
420+
proxyOpts.auth = options.proxyUser + ':' + options.proxyPass;
421+
}
422+
}
423+
if (Object.keys(proxyOpts).length) {
424+
reqOptions.agent = new HttpsProxyAgent(proxyOpts);
425+
}
426+
var req = https.request(reqOptions, resp => {
407427
let json = '';
408428
resp.on('data', chunk => {
409429
json += chunk;
@@ -756,6 +776,13 @@ function getBinaryPath_(that, options, fnCallback) {
756776
conf.proxyHost = options['proxyHost'] || options['proxyhost'];
757777
conf.proxyPort = options['proxyPort'] || options['proxyport'];
758778
}
779+
if (
780+
(options['proxyUser'] || options['proxyuser']) &&
781+
(options['proxyPass'] || options['proxypass'])
782+
) {
783+
conf.proxyUser = options['proxyUser'] || options['proxyuser'];
784+
conf.proxyPass = options['proxyPass'] || options['proxypass'];
785+
}
759786
that.binary.binaryPath_(conf, fnCallback);
760787
} else {
761788
return fnCallback(that.binaryPath);
@@ -778,8 +805,9 @@ function retryTunnelName_(self, infoAPIPort, retries, fnCallback) {
778805
if (retries >= 0) {
779806
// local Server path for getting tunnelName
780807
var url = 'http://127.0.0.1:' + infoAPIPort + '/api/v1.0/info';
808+
var reqOptions = urlParse.parse(url);
781809
http
782-
.get(url, response => {
810+
.get(reqOptions, response => {
783811
let json = '';
784812
response.on('data', chunk => {
785813
json += chunk;
@@ -847,4 +875,4 @@ function clearTimeout_(timeoutId) {
847875
}
848876
}
849877
module.exports = Tunnel;
850-
module.exports.Tunnel = Tunnel;
878+
module.exports.Tunnel = Tunnel;

lib/tunnel_binary.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,24 @@ function TunnelBinary(httpTunnelConfig) {
9191
var self = this;
9292
// Set Proxy If User passed this to in arguments.
9393
var options = urlParse.parse(this.httpPath);
94+
var proxyOpts = {};
9495
if (conf.proxyHost && conf.proxyPort) {
95-
options.agent = new HttpsProxyAgent({
96+
proxyOpts = {
9697
host: conf.proxyHost,
9798
port: conf.proxyPort
98-
});
99+
};
100+
} else if (process.env.http_proxy) {
101+
proxyOpts = urlParse.parse(process.env.http_proxy);
102+
}
103+
if ((conf.proxyUser && !conf.proxyPass) || (!conf.proxyUser && conf.proxyPass)) {
104+
throw Error('proxyUser and proxyPass must be both or none');
105+
} else if (conf.proxyUser && conf.proxyPass) {
106+
if (Object.keys(proxyOpts).length) {
107+
proxyOpts.auth = conf.proxyUser + ':' + conf.proxyPass;
108+
}
109+
}
110+
if (Object.keys(proxyOpts).length) {
111+
options.agent = new HttpsProxyAgent(proxyOpts);
99112
}
100113
// Get binary as zip File from https Server and put this to local folder.
101114
// After fully download, unzip and change mode to excutable.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lambdatest/node-tunnel",
3-
"version": "1.1.3",
3+
"version": "1.1.4",
44
"description": "Nodejs bindings for LambdaTest Tunnel",
55
"main": "index.js",
66
"repository": {

0 commit comments

Comments
 (0)