diff --git a/src/Console/ChromeDriverCommand.php b/src/Console/ChromeDriverCommand.php index f0357c143..ac0d8ac47 100644 --- a/src/Console/ChromeDriverCommand.php +++ b/src/Console/ChromeDriverCommand.php @@ -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. @@ -150,7 +153,7 @@ protected function version() return $this->legacyVersions[$version]; } - return trim(file_get_contents( + return trim($this->getUrl( sprintf($this->versionUrl, $version) )); } @@ -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); @@ -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; @@ -226,4 +229,27 @@ protected function rename($binary, $os) chmod($this->directory.$newName, 0755); } + + /** + * Get URL using the 'proxy' and 'ssl-no-verify' command options. + * + * @param string $url + * @return string|bool + */ + protected function getUrl(string $url) + { + $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); + } } diff --git a/src/Console/InstallCommand.php b/src/Console/InstallCommand.php index 92010ce12..efd1c6736 100644 --- a/src/Console/InstallCommand.php +++ b/src/Console/InstallCommand.php @@ -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. @@ -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'); + } + + if ($this->option('ssl-no-verify')) { + $driverCommandArgs['--ssl-no-verify'] = true; + } + + $this->call('dusk:chrome-driver', $driverCommandArgs); } /**