Added custom server host ability

This commit is contained in:
Marcel Pociot
2021-06-01 21:19:12 +02:00
parent 5e54d0a80f
commit 44b100b340
13 changed files with 116 additions and 44 deletions

View File

@@ -284,11 +284,11 @@ class ApiTest extends TestCase
$connection = \Mockery::mock(IoConnection::class);
$connection->httpRequest = new Request('GET', '/?authToken='.$createdUser->auth_token);
$connectionManager->storeConnection('some-host.test', 'fixed-subdomain', $connection);
$connectionManager->storeConnection('some-host.test', 'fixed-subdomain', 'localhost', $connection);
$connection = \Mockery::mock(IoConnection::class);
$connection->httpRequest = new Request('GET', '/?authToken=some-other-token');
$connectionManager->storeConnection('some-different-host.test', 'different-subdomain', $connection);
$connectionManager->storeConnection('some-different-host.test', 'different-subdomain', 'localhost', $connection);
$connection = \Mockery::mock(IoConnection::class);
$connection->httpRequest = new Request('GET', '/?authToken='.$createdUser->auth_token);
@@ -307,6 +307,7 @@ class ApiTest extends TestCase
$this->assertCount(1, $users[0]->sites);
$this->assertCount(1, $users[0]->tcp_connections);
$this->assertSame('some-host.test', $users[0]->sites[0]->host);
$this->assertSame('localhost', $users[0]->sites[0]->server_host);
$this->assertSame('fixed-subdomain', $users[0]->sites[0]->subdomain);
}
@@ -319,7 +320,7 @@ class ApiTest extends TestCase
$connection = \Mockery::mock(IoConnection::class);
$connection->httpRequest = new Request('GET', '/?authToken=some-token');
$connectionManager->storeConnection('some-host.test', 'fixed-subdomain', $connection);
$connectionManager->storeConnection('some-host.test', 'fixed-subdomain', 'localhost', $connection);
/** @var Response $response */
$response = $this->await($this->browser->get('http://127.0.0.1:8080/api/sites', [
@@ -346,7 +347,7 @@ class ApiTest extends TestCase
$connection = \Mockery::mock(IoConnection::class);
$connection->httpRequest = new Request('GET', '/');
$connectionManager->storeConnection('some-host.test', 'fixed-subdomain', $connection);
$connectionManager->storeConnection('some-host.test', 'fixed-subdomain', 'localhost', $connection);
/** @var Response $response */
$response = $this->await($this->browser->get('http://127.0.0.1:8080/api/sites', [

View File

@@ -213,7 +213,7 @@ class TunnelTest extends TestCase
* the created test HTTP server.
*/
$client = $this->createClient();
$response = $this->await($client->connectToServer('127.0.0.1:8085', 'tunnel', $user->auth_token));
$response = $this->await($client->connectToServer('127.0.0.1:8085', 'tunnel', null, $user->auth_token));
$this->assertSame('tunnel', $response->subdomain);
}
@@ -235,7 +235,7 @@ class TunnelTest extends TestCase
* the created test HTTP server.
*/
$client = $this->createClient();
$response = $this->await($client->connectToServer('127.0.0.1:8085', 'tunnel', $user->auth_token));
$response = $this->await($client->connectToServer('127.0.0.1:8085', 'tunnel', null, $user->auth_token));
$this->assertNotSame('tunnel', $response->subdomain);
}
@@ -272,11 +272,56 @@ class TunnelTest extends TestCase
* the created test HTTP server.
*/
$client = $this->createClient();
$response = $this->await($client->connectToServer('127.0.0.1:8085', 'reserved', $user->auth_token));
$response = $this->await($client->connectToServer('127.0.0.1:8085', 'reserved', null, $user->auth_token));
$this->assertSame('reserved', $response->subdomain);
}
/** @test */
public function it_rejects_users_that_want_to_use_a_subdomain_that_is_already_in_use()
{
$this->app['config']['expose.admin.validate_auth_tokens'] = true;
$user = $this->createUser([
'name' => 'Marcel',
'can_specify_subdomains' => 1,
]);
$this->createTestHttpServer();
$this->expectException(\UnexpectedValueException::class);
$client = $this->createClient();
$response = $this->await($client->connectToServer('127.0.0.1:8085', 'taken', null, $user->auth_token));
$this->assertSame('taken', $response->subdomain);
$response = $this->await($client->connectToServer('127.0.0.1:8085', 'taken', null, $user->auth_token));
$this->assertSame('taken', $response->subdomain);
}
/** @test */
public function it_allows_users_to_use_a_subdomain_that_is_already_in_use_on_a_different_shared_host()
{
$this->app['config']['expose.admin.validate_auth_tokens'] = true;
$user = $this->createUser([
'name' => 'Marcel',
'can_specify_subdomains' => 1,
]);
$this->createTestHttpServer();
$client = $this->createClient();
$response = $this->await($client->connectToServer('127.0.0.1:8085', 'taken', null, $user->auth_token));
$this->assertSame('localhost', $response->server_host);
$this->assertSame('taken', $response->subdomain);
$response = $this->await($client->connectToServer('127.0.0.1:8085', 'taken', 'share.beyondco.de', $user->auth_token));
$this->assertSame('share.beyondco.de', $response->server_host);
$this->assertSame('taken', $response->subdomain);
}
/** @test */
public function it_allows_users_to_use_their_own_reserved_subdomains()
{
@@ -302,7 +347,7 @@ class TunnelTest extends TestCase
* the created test HTTP server.
*/
$client = $this->createClient();
$response = $this->await($client->connectToServer('127.0.0.1:8085', 'reserved', $user->auth_token));
$response = $this->await($client->connectToServer('127.0.0.1:8085', 'reserved', null, $user->auth_token));
$this->assertSame('reserved', $response->subdomain);
}
@@ -363,7 +408,7 @@ class TunnelTest extends TestCase
$this->createTestHttpServer();
$client = $this->createClient();
$response = $this->await($client->connectToServer('127.0.0.1:8085', 'foo', $user->auth_token));
$response = $this->await($client->connectToServer('127.0.0.1:8085', 'foo', null, $user->auth_token));
$this->assertNotSame('foo', $response->subdomain);
}