mirror of
https://github.com/bitinflow/expose.git
synced 2026-03-13 13:35:54 +00:00
Improve subdomain detection
This commit is contained in:
@@ -70,11 +70,9 @@ class TunnelMessageController extends Controller
|
|||||||
|
|
||||||
protected function detectSubdomain(Request $request): ?string
|
protected function detectSubdomain(Request $request): ?string
|
||||||
{
|
{
|
||||||
if (substr_count($request->header('Host'), '.') === 1) {
|
$serverHost = $this->detectServerHost($request);
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$subdomain = Str::before($request->header('Host'), '.');
|
$subdomain = Str::before($request->header('Host'), '.' . $serverHost);
|
||||||
|
|
||||||
return $subdomain === $request->header('Host') ? null : $subdomain;
|
return $subdomain === $request->header('Host') ? null : $subdomain;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,6 +64,17 @@ class TunnelTest extends TestCase
|
|||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function it_returns_404_for_non_existing_clients_on_custom_hosts()
|
||||||
|
{
|
||||||
|
$this->expectException(ResponseException::class);
|
||||||
|
$this->expectExceptionMessage(404);
|
||||||
|
|
||||||
|
$this->await($this->browser->get('http://127.0.0.1:8080/', [
|
||||||
|
'Host' => 'tunnel.share.beyondco.de',
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
public function it_sends_incoming_requests_to_the_connected_client()
|
public function it_sends_incoming_requests_to_the_connected_client()
|
||||||
{
|
{
|
||||||
@@ -91,6 +102,33 @@ class TunnelTest extends TestCase
|
|||||||
$this->assertSame('Hello World!', $response->getBody()->getContents());
|
$this->assertSame('Hello World!', $response->getBody()->getContents());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function it_sends_incoming_requests_to_the_connected_client_on_custom_hosts()
|
||||||
|
{
|
||||||
|
$this->app['config']['expose.admin.validate_auth_tokens'] = false;
|
||||||
|
|
||||||
|
$this->createTestHttpServer();
|
||||||
|
|
||||||
|
$this->app['config']['expose.admin.validate_auth_tokens'] = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We create an expose client that connects to our server and shares
|
||||||
|
* the created test HTTP server.
|
||||||
|
*/
|
||||||
|
$client = $this->createClient();
|
||||||
|
$this->await($client->connectToServer('127.0.0.1:8085', 'tunnel', 'share.beyondco.de'));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Once the client is connected, we perform a GET request on the
|
||||||
|
* created tunnel.
|
||||||
|
*/
|
||||||
|
$response = $this->await($this->browser->get('http://127.0.0.1:8080/', [
|
||||||
|
'Host' => 'tunnel.share.beyondco.de',
|
||||||
|
]));
|
||||||
|
|
||||||
|
$this->assertSame('Hello World!', $response->getBody()->getContents());
|
||||||
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
public function it_sends_incoming_requests_to_the_connected_client_via_tcp()
|
public function it_sends_incoming_requests_to_the_connected_client_via_tcp()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user