From aa08029fc3ff7e1fb9ffc83633c4c2cdbea47c00 Mon Sep 17 00:00:00 2001 From: Marcel Pociot Date: Mon, 14 Jun 2021 11:50:03 +0200 Subject: [PATCH] Remove subdomain reserve check from server --- app/Client/Client.php | 4 +- .../Admin/StoreSubdomainController.php | 6 -- .../Controllers/TunnelMessageController.php | 2 +- tests/Feature/Server/ApiTest.php | 59 ------------------- 4 files changed, 3 insertions(+), 68 deletions(-) diff --git a/app/Client/Client.php b/app/Client/Client.php index b1a9068..913e186 100644 --- a/app/Client/Client.php +++ b/app/Client/Client.php @@ -107,7 +107,7 @@ class Client $connection->on('authenticated', function ($data) use ($deferred, $sharedUrl) { $httpProtocol = $this->configuration->port() === 443 ? 'https' : 'http'; - $host = $data->server_host; + $host = $data->server_host ?? $this->configuration->host(); $this->logger->info($data->message); $this->logger->info("Local-URL:\t\t{$sharedUrl}"); @@ -116,7 +116,7 @@ class Client $this->logger->info("Expose-URL:\t\thttps://{$data->subdomain}.{$host}"); $this->logger->line(''); - static::$subdomains[] = "{$httpProtocol}://{$data->subdomain}.{$data->server_host}"; + static::$subdomains[] = "{$httpProtocol}://{$data->subdomain}.{$host}"; $deferred->resolve($data); }); diff --git a/app/Server/Http/Controllers/Admin/StoreSubdomainController.php b/app/Server/Http/Controllers/Admin/StoreSubdomainController.php index a590b55..8cac94c 100644 --- a/app/Server/Http/Controllers/Admin/StoreSubdomainController.php +++ b/app/Server/Http/Controllers/Admin/StoreSubdomainController.php @@ -77,12 +77,6 @@ class StoreSubdomainController extends AdminController $this->subdomainRepository ->storeSubdomain($insertData) ->then(function ($subdomain) use ($httpConnection) { - if (is_null($subdomain)) { - $httpConnection->send(respond_json(['error' => 'The subdomain is already taken.'], 422)); - $httpConnection->close(); - - return; - } $httpConnection->send(respond_json(['subdomain' => $subdomain], 200)); $httpConnection->close(); }); diff --git a/app/Server/Http/Controllers/TunnelMessageController.php b/app/Server/Http/Controllers/TunnelMessageController.php index f3e107f..c06648f 100644 --- a/app/Server/Http/Controllers/TunnelMessageController.php +++ b/app/Server/Http/Controllers/TunnelMessageController.php @@ -79,7 +79,7 @@ class TunnelMessageController extends Controller protected function detectServerHost(Request $request): ?string { - return Str::after($request->header('Host'), '.'); + return Str::before(Str::after($request->header('Host'), '.'), ':'); } protected function sendRequestToClient(Request $request, ControlConnection $controlConnection, ConnectionInterface $httpConnection) diff --git a/tests/Feature/Server/ApiTest.php b/tests/Feature/Server/ApiTest.php index 9026bc2..b53111a 100644 --- a/tests/Feature/Server/ApiTest.php +++ b/tests/Feature/Server/ApiTest.php @@ -424,65 +424,6 @@ class ApiTest extends TestCase $this->assertCount(0, $subdomains); } - /** @test */ - public function it_can_not_reserve_an_already_reserved_subdomain() - { - /** @var Response $response */ - $response = $this->await($this->browser->post('http://127.0.0.1:8080/api/users', [ - 'Host' => 'expose.localhost', - 'Authorization' => base64_encode('username:secret'), - 'Content-Type' => 'application/json', - ], json_encode([ - 'name' => 'Marcel', - 'can_specify_subdomains' => 1, - ]))); - - $user = json_decode($response->getBody()->getContents())->user; - - $this->await($this->browser->post('http://127.0.0.1:8080/api/subdomains', [ - 'Host' => 'expose.localhost', - 'Authorization' => base64_encode('username:secret'), - 'Content-Type' => 'application/json', - ], json_encode([ - 'subdomain' => 'reserved', - 'auth_token' => $user->auth_token, - ]))); - - $response = $this->await($this->browser->post('http://127.0.0.1:8080/api/users', [ - 'Host' => 'expose.localhost', - 'Authorization' => base64_encode('username:secret'), - 'Content-Type' => 'application/json', - ], json_encode([ - 'name' => 'Sebastian', - 'can_specify_subdomains' => 1, - ]))); - - $user = json_decode($response->getBody()->getContents())->user; - - $this->expectException(ResponseException::class); - $this->expectExceptionMessage('HTTP status code 422'); - - $this->await($this->browser->post('http://127.0.0.1:8080/api/subdomains', [ - 'Host' => 'expose.localhost', - 'Authorization' => base64_encode('username:secret'), - 'Content-Type' => 'application/json', - ], json_encode([ - 'subdomain' => 'reserved', - 'auth_token' => $user->auth_token, - ]))); - - $response = $this->await($this->browser->get('http://127.0.0.1:8080/api/users/2', [ - 'Host' => 'expose.localhost', - 'Authorization' => base64_encode('username:secret'), - 'Content-Type' => 'application/json', - ])); - - $body = json_decode($response->getBody()->getContents()); - $subdomains = $body->subdomains; - - $this->assertCount(0, $subdomains); - } - /** @test */ public function it_can_list_all_currently_connected_sites_from_all_users() {