Skip to content

Commit 7afecc9

Browse files
authored
Merge pull request #147 from browserstack/LOC_4382
Use caCertificate to download local binary as well.
2 parents be55acb + f0f1f45 commit 7afecc9

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,10 @@ To use a proxy for local testing -
7878
* proxyPort: Port for the proxy, defaults to 3128 when -proxyHost is used
7979
* proxyUser: Username for connecting to proxy (Basic Auth Only)
8080
* proxyPass: Password for USERNAME, will be ignored if USERNAME is empty or not specified
81+
* useCaCertificate: Path to ca cert file, if required
8182

8283
```js
83-
bs_local_args = { 'key': '<browserstack-accesskey>', 'proxyHost': '127.0.0.1', 'proxyPort': '8000', 'proxyUser': 'user', 'proxyPass': 'password' }
84+
bs_local_args = { 'key': '<browserstack-accesskey>', 'proxyHost': '127.0.0.1', 'proxyPort': '8000', 'proxyUser': 'user', 'proxyPass': 'password', 'useCaCertificate': '/Users/test/cert.pem' }
8485
```
8586

8687
#### Local Proxy

lib/Local.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ function Local(){
183183
}
184184
break;
185185

186+
case 'useCaCertificate':
187+
if(value)
188+
this.useCaCertificate = value;
189+
break;
190+
186191
case 'proxyHost':
187192
if(value)
188193
this.proxyHost = value;
@@ -245,6 +250,9 @@ function Local(){
245250
conf.proxyHost = this.proxyHost;
246251
conf.proxyPort = this.proxyPort;
247252
}
253+
if (this.useCaCertificate) {
254+
conf.useCaCertificate = this.useCaCertificate;
255+
}
248256
if(!callback) {
249257
return this.binary.binaryPath(conf);
250258
}
@@ -284,6 +292,10 @@ function Local(){
284292
}
285293
if(this.onlyAutomateFlag)
286294
args.push(this.onlyAutomateFlag);
295+
if (this.useCaCertificate) {
296+
args.push('--use-ca-certificate');
297+
args.push(this.useCaCertificate);
298+
}
287299
if(this.proxyHost){
288300
args.push('--proxy-host');
289301
args.push(this.proxyHost);

lib/LocalBinary.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ function LocalBinary(){
7373
opts = [path.join(__dirname, 'download.js'), binaryPath, this.httpPath];
7474
if(conf.proxyHost && conf.proxyPort) {
7575
opts.push(conf.proxyHost, conf.proxyPort);
76+
if (conf.useCaCertificate) {
77+
opts.push(conf.useCaCertificate);
78+
}
79+
} else if (conf.useCaCertificate) {
80+
opts.push(undefined, undefined, conf.useCaCertificate);
7681
}
7782

7883
try{
@@ -113,6 +118,13 @@ function LocalBinary(){
113118
port: conf.proxyPort
114119
});
115120
}
121+
if (conf.useCaCertificate) {
122+
try {
123+
options.ca = fs.readFileSync(conf.useCaCertificate);
124+
} catch(err) {
125+
console.log("failed to read cert file", err)
126+
}
127+
}
116128

117129
https.get(options, function (response) {
118130
response.pipe(fileStream);

lib/download.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const https = require('https'),
33
HttpsProxyAgent = require('https-proxy-agent'),
44
url = require('url');
55

6-
const binaryPath = process.argv[2],httpPath = process.argv[3], proxyHost = process.argv[4], proxyPort = process.argv[5];
6+
const binaryPath = process.argv[2], httpPath = process.argv[3], proxyHost = process.argv[4], proxyPort = process.argv[5], useCaCertificate = process.argv[6];
77

88
var fileStream = fs.createWriteStream(binaryPath);
99

@@ -13,6 +13,13 @@ if(proxyHost && proxyPort) {
1313
host: proxyHost,
1414
port: proxyPort
1515
});
16+
if (useCaCertificate) {
17+
try {
18+
options.ca = fs.readFileSync(useCaCertificate);
19+
} catch(err) {
20+
console.log("failed to read cert file", err)
21+
}
22+
}
1623
}
1724

1825
https.get(options, function (response) {

0 commit comments

Comments
 (0)