Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.0] Add proxy support to the 'dusk:install' command #659

Merged
merged 12 commits into from
Jul 9, 2019
33 changes: 29 additions & 4 deletions src/Console/ChromeDriverCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ class ChromeDriverCommand extends Command
*
* @var string
*/
protected $signature = 'dusk:chrome-driver {version?} {--all : Install a ChromeDriver binary for every OS}';
protected $signature = 'dusk:chrome-driver {version?}
{--all : Install a ChromeDriver binary for every OS}
{--proxy= : Proxy address e.g. "tcp://127.0.0.1:9000"}
{--ssl-no-verify : Bypass SSL certificate verification}';

/**
* The console command description.
Expand Down Expand Up @@ -150,7 +153,7 @@ protected function version()
return $this->legacyVersions[$version];
}

return trim(file_get_contents(
return trim($this->getUrl(
sprintf($this->versionUrl, $version)
));
}
Expand All @@ -162,7 +165,7 @@ protected function version()
*/
protected function latestVersion()
{
$home = file_get_contents($this->homeUrl);
$home = $this->getUrl($this->homeUrl);

preg_match('/Latest stable release:.*?\?path=([\d.]+)/', $home, $matches);

Expand All @@ -182,7 +185,7 @@ protected function download($version, $slug)

file_put_contents(
$archive = $this->directory.'chromedriver.zip',
fopen($url, 'r')
$this->getUrl($url)
);

return $archive;
Expand Down Expand Up @@ -226,4 +229,26 @@ protected function rename($binary, $os)

chmod($this->directory.$newName, 0755);
}

/**
* Get URL using the 'proxy' and 'ssl-no-verify' command options.
*
* @return false|string
aand18 marked this conversation as resolved.
Show resolved Hide resolved
aand18 marked this conversation as resolved.
Show resolved Hide resolved
*/
protected function get($url)
aand18 marked this conversation as resolved.
Show resolved Hide resolved
{
$contextOptions = [];

if ($this->option('proxy')) {
$contextOptions['http'] = ['proxy' => $this->option('proxy'), 'request_fulluri' => true];
}

if ($this->option('ssl-no-verify')) {
$contextOptions['ssl'] = ['verify_peer' => false];
}

$streamContext = stream_context_create($contextOptions);

return file_get_contents($url, false, $streamContext);
}
}
16 changes: 14 additions & 2 deletions src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ class InstallCommand extends Command
*
* @var string
*/
protected $signature = 'dusk:install';
protected $signature = 'dusk:install
{--proxy= : Proxy address e.g. "tcp://127.0.0.1:9000"}
{--ssl-no-verify : Bypass SSL certificate verification}';

/**
* The console command description.
Expand Down Expand Up @@ -60,7 +62,17 @@ public function handle()

$this->comment('Downloading ChromeDriver binaries...');

$this->call('dusk:chrome-driver', ['--all' => true]);
$driverCommandArgs = ['--all' => true];

if ($this->option('proxy')) {
$driverCommandArgs += ['--proxy' => $this->option('proxy')];
aand18 marked this conversation as resolved.
Show resolved Hide resolved
}

if ($this->option('ssl-no-verify')) {
$driverCommandArgs += ['--ssl-no-verify' => true];
aand18 marked this conversation as resolved.
Show resolved Hide resolved
}

$this->call('dusk:chrome-driver', $driverCommandArgs);
}

/**
Expand Down