Skip to content

Commit

Permalink
Merge pull request #147 from browserstack/LOC_4382
Browse files Browse the repository at this point in the history
Use caCertificate to download local binary as well.
  • Loading branch information
VSood1104 authored Jul 28, 2023
2 parents be55acb + f0f1f45 commit 7afecc9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ To use a proxy for local testing -
* proxyPort: Port for the proxy, defaults to 3128 when -proxyHost is used
* proxyUser: Username for connecting to proxy (Basic Auth Only)
* proxyPass: Password for USERNAME, will be ignored if USERNAME is empty or not specified
* useCaCertificate: Path to ca cert file, if required

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

#### Local Proxy
Expand Down
12 changes: 12 additions & 0 deletions lib/Local.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ function Local(){
}
break;

case 'useCaCertificate':
if(value)
this.useCaCertificate = value;
break;

case 'proxyHost':
if(value)
this.proxyHost = value;
Expand Down Expand Up @@ -245,6 +250,9 @@ function Local(){
conf.proxyHost = this.proxyHost;
conf.proxyPort = this.proxyPort;
}
if (this.useCaCertificate) {
conf.useCaCertificate = this.useCaCertificate;
}
if(!callback) {
return this.binary.binaryPath(conf);
}
Expand Down Expand Up @@ -284,6 +292,10 @@ function Local(){
}
if(this.onlyAutomateFlag)
args.push(this.onlyAutomateFlag);
if (this.useCaCertificate) {
args.push('--use-ca-certificate');
args.push(this.useCaCertificate);
}
if(this.proxyHost){
args.push('--proxy-host');
args.push(this.proxyHost);
Expand Down
12 changes: 12 additions & 0 deletions lib/LocalBinary.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ function LocalBinary(){
opts = [path.join(__dirname, 'download.js'), binaryPath, this.httpPath];
if(conf.proxyHost && conf.proxyPort) {
opts.push(conf.proxyHost, conf.proxyPort);
if (conf.useCaCertificate) {
opts.push(conf.useCaCertificate);
}
} else if (conf.useCaCertificate) {
opts.push(undefined, undefined, conf.useCaCertificate);
}

try{
Expand Down Expand Up @@ -113,6 +118,13 @@ function LocalBinary(){
port: conf.proxyPort
});
}
if (conf.useCaCertificate) {
try {
options.ca = fs.readFileSync(conf.useCaCertificate);
} catch(err) {
console.log("failed to read cert file", err)
}
}

https.get(options, function (response) {
response.pipe(fileStream);
Expand Down
9 changes: 8 additions & 1 deletion lib/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const https = require('https'),
HttpsProxyAgent = require('https-proxy-agent'),
url = require('url');

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

var fileStream = fs.createWriteStream(binaryPath);

Expand All @@ -13,6 +13,13 @@ if(proxyHost && proxyPort) {
host: proxyHost,
port: proxyPort
});
if (useCaCertificate) {
try {
options.ca = fs.readFileSync(useCaCertificate);
} catch(err) {
console.log("failed to read cert file", err)
}
}
}

https.get(options, function (response) {
Expand Down

0 comments on commit 7afecc9

Please sign in to comment.