1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-05 08:30:07 +01:00

Update Ngrok (valet share) to lowercase domains before matching

This commit is contained in:
Matt Stauffer
2022-05-18 11:47:30 -04:00
parent b084a8dfdd
commit e69d448245
3 changed files with 70 additions and 1 deletions

View File

@@ -51,7 +51,7 @@ public function findHttpTunnelUrl($tunnels, $domain)
// find the one responding on HTTP. Each tunnel has an HTTP and a HTTPS address
// but for local dev purposes we just desire the plain HTTP URL endpoint.
foreach ($tunnels as $tunnel) {
if ($tunnel->proto === 'http' && strpos($tunnel->config->addr, $domain)) {
if ($tunnel->proto === 'http' && strpos($tunnel->config->addr, strtolower($domain))) {
return $tunnel->public_url;
}
}

66
tests/NgrokTest.php Normal file
View File

@@ -0,0 +1,66 @@
<?php
use Illuminate\Container\Container;
use Valet\Ngrok;
use function Valet\user;
class NgrokTest extends Yoast\PHPUnitPolyfills\TestCases\TestCase
{
public function set_up()
{
$_SERVER['SUDO_USER'] = user();
Container::setInstance(new Container);
}
public function tear_down()
{
Mockery::close();
}
public function test_it_matches_correct_share_tunnel()
{
$tunnels = [
(object) [
'proto' => 'https',
'config' => (object) [
'addr' => 'http://mysite.test:80',
],
'public_url' => 'http://bad-proto.ngrok.io/',
],
(object) [
'proto' => 'http',
'config' => (object) [
'addr' => 'http://nottherightone.test:80',
],
'public_url' => 'http://bad-site.ngrok.io/',
],
(object) [
'proto' => 'http',
'config' => (object) [
'addr' => 'http://mysite.test:80',
],
'public_url' => 'http://right-one.ngrok.io/',
],
];
$ngrok = new Ngrok;
$this->assertEquals('http://right-one.ngrok.io/', $ngrok->findHttpTunnelUrl($tunnels, 'mysite'));
}
public function test_it_checks_against_lowercased_domain()
{
$tunnels = [
(object) [
'proto' => 'http',
'config' => (object) [
'addr' => 'http://mysite.test:80',
],
'public_url' => 'http://right-one.ngrok.io/',
],
];
$ngrok = new Ngrok;
$this->assertEquals('http://right-one.ngrok.io/', $ngrok->findHttpTunnelUrl($tunnels, 'MySite'));
}
}

3
valet
View File

@@ -69,6 +69,9 @@ then
PORT=80
fi
# Lowercase the host to match how the rest of our domains are looked up
HOST=$(echo "$HOST" | tr '[:upper:]' '[:lower:]')
# Fetch Ngrok URL In Background...
bash "$DIR/cli/scripts/fetch-share-url.sh" "$HOST" &