mirror of
https://github.com/laravel/valet.git
synced 2026-02-04 08:10:07 +01:00
♻️ Refactoring proxy command. Proxy is not secured by default.
This commit is contained in:
@@ -710,10 +710,10 @@ function unsecureAll()
|
||||
*
|
||||
* @param string $url The domain name to serve
|
||||
* @param string $host The URL to proxy to, eg: http://127.0.0.1:8080
|
||||
* @param bool $insecure
|
||||
* @param bool $secure
|
||||
* @return string
|
||||
*/
|
||||
function proxyCreate($url, $host, $insecure = false)
|
||||
function proxyCreate($url, $host, $secure = false)
|
||||
{
|
||||
if (!preg_match('~^https?://.*$~', $host)) {
|
||||
throw new \InvalidArgumentException(sprintf('"%s" is not a valid URL', $host));
|
||||
@@ -726,7 +726,7 @@ function proxyCreate($url, $host, $insecure = false)
|
||||
|
||||
$siteConf = $this->replaceOldLoopbackWithNew(
|
||||
$this->files->get(
|
||||
$insecure ? __DIR__.'/../stubs/insecure.proxy.valet.conf' : __DIR__.'/../stubs/secure.proxy.valet.conf'
|
||||
$secure ? __DIR__.'/../stubs/secure.proxy.valet.conf' : __DIR__.'/../stubs/proxy.valet.conf'
|
||||
),
|
||||
'VALET_LOOPBACK',
|
||||
$this->valetLoopback()
|
||||
@@ -738,13 +738,13 @@ function proxyCreate($url, $host, $insecure = false)
|
||||
$siteConf
|
||||
);
|
||||
|
||||
if ($insecure) {
|
||||
$this->putInsecurely($url, $siteConf);
|
||||
} else {
|
||||
if ($secure) {
|
||||
$this->secure($url, $siteConf);
|
||||
} else {
|
||||
$this->put($url, $siteConf);
|
||||
}
|
||||
|
||||
$protocol = $insecure ? 'http' : 'https';
|
||||
$protocol = $secure ? 'https' : 'http';
|
||||
|
||||
info('Valet will now proxy ['.$protocol.'://'.$url.'] traffic to ['.$host.'].');
|
||||
}
|
||||
@@ -775,7 +775,7 @@ function proxyDelete($url)
|
||||
* @param string $siteConf pregenerated Nginx config file contents
|
||||
* @return void
|
||||
*/
|
||||
function putInsecurely($url, $siteConf)
|
||||
function put($url, $siteConf)
|
||||
{
|
||||
$this->unsecure($url);
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# valet stub: insecure.proxy.valet.conf
|
||||
# valet stub: proxy.valet.conf
|
||||
|
||||
server {
|
||||
listen 127.0.0.1:80;
|
||||
@@ -210,13 +210,13 @@
|
||||
/**
|
||||
* Create an Nginx proxy config for the specified domain
|
||||
*/
|
||||
$app->command('proxy domain host [--insecure]', function ($domain, $host, $insecure) {
|
||||
$app->command('proxy domain host [--secure]', function ($domain, $host, $secure) {
|
||||
|
||||
Site::proxyCreate($domain, $host, $insecure);
|
||||
Site::proxyCreate($domain, $host, $secure);
|
||||
Nginx::restart();
|
||||
|
||||
})->descriptions('Create an Nginx proxy site for the specified host. Useful for docker, mailhog etc.', [
|
||||
'--insecure' => 'Create a proxy without SSL'
|
||||
'--secure' => 'Create a proxy with a trusted TLS certificate'
|
||||
]);
|
||||
|
||||
/**
|
||||
|
||||
@@ -353,7 +353,7 @@ public function test_add_proxy()
|
||||
$site->assertCertificateNotExists('my-new-proxy.com.test');
|
||||
$site->assertNginxNotExists('my-new-proxy.com.test');
|
||||
|
||||
$site->proxyCreate('my-new-proxy.com', 'https://127.0.0.1:9443');
|
||||
$site->proxyCreate('my-new-proxy.com', 'https://127.0.0.1:9443', true);
|
||||
|
||||
$site->assertCertificateExistsWithCounterValue('my-new-proxy.com.test', 0);
|
||||
$site->assertNginxExists('my-new-proxy.com.test');
|
||||
@@ -387,7 +387,7 @@ public function test_add_non_secure_proxy()
|
||||
$site->assertCertificateNotExists('my-new-proxy.com.test');
|
||||
$site->assertNginxNotExists('my-new-proxy.com.test');
|
||||
|
||||
$site->proxyCreate('my-new-proxy.com', 'http://127.0.0.1:9443', true);
|
||||
$site->proxyCreate('my-new-proxy.com', 'http://127.0.0.1:9443', false);
|
||||
|
||||
$site->assertCertificateNotExists('my-new-proxy.com.test');
|
||||
$site->assertNginxExists('my-new-proxy.com.test');
|
||||
@@ -418,7 +418,7 @@ public function test_add_proxy_clears_previous_proxy_certificate()
|
||||
|
||||
$site->useOutput();
|
||||
|
||||
$site->proxyCreate('my-new-proxy.com', 'https://127.0.0.1:7443');
|
||||
$site->proxyCreate('my-new-proxy.com', 'https://127.0.0.1:7443', true);
|
||||
|
||||
$site->assertCertificateExistsWithCounterValue('my-new-proxy.com.test', 0);
|
||||
|
||||
@@ -432,7 +432,7 @@ public function test_add_proxy_clears_previous_proxy_certificate()
|
||||
], $site->proxies()->all());
|
||||
|
||||
// Note: different proxy port
|
||||
$site->proxyCreate('my-new-proxy.com', 'https://127.0.0.1:9443');
|
||||
$site->proxyCreate('my-new-proxy.com', 'https://127.0.0.1:9443', true);
|
||||
|
||||
// This shows we created a new certificate.
|
||||
$site->assertCertificateExistsWithCounterValue('my-new-proxy.com.test', 1);
|
||||
@@ -470,7 +470,7 @@ public function test_add_proxy_clears_previous_non_proxy_certificate()
|
||||
$site->assertCertificateExistsWithCounterValue('my-new-proxy.com.test', 0);
|
||||
$site->assertNginxNotExists('my-new-proxy.com.test');
|
||||
|
||||
$site->proxyCreate('my-new-proxy.com', 'https://127.0.0.1:9443');
|
||||
$site->proxyCreate('my-new-proxy.com', 'https://127.0.0.1:9443', true);
|
||||
|
||||
// This shows we created a new certificate.
|
||||
$site->assertCertificateExistsWithCounterValue('my-new-proxy.com.test', 1);
|
||||
@@ -507,7 +507,7 @@ public function test_remove_proxy()
|
||||
|
||||
$this->assertEquals([], $site->proxies()->all());
|
||||
|
||||
$site->proxyCreate('my-new-proxy.com', 'https://127.0.0.1:9443');
|
||||
$site->proxyCreate('my-new-proxy.com', 'https://127.0.0.1:9443', true);
|
||||
|
||||
$this->assertEquals([
|
||||
'my-new-proxy.com' => [
|
||||
|
||||
Reference in New Issue
Block a user