mirror of
https://github.com/bitinflow/expose.git
synced 2026-03-13 13:35:54 +00:00
Custom domain support
This commit is contained in:
@@ -65,6 +65,60 @@ class ApiTest extends TestCase
|
||||
$this->assertSame([], $users[0]->sites);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_does_not_allow_domain_reservation_for_users_without_the_right_flag()
|
||||
{
|
||||
/** @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',
|
||||
])));
|
||||
|
||||
$user = json_decode($response->getBody()->getContents())->user;
|
||||
|
||||
$this->expectException(ResponseException::class);
|
||||
$this->expectExceptionMessage('HTTP status code 401');
|
||||
|
||||
$this->await($this->browser->post('http://127.0.0.1:8080/api/domains', [
|
||||
'Host' => 'expose.localhost',
|
||||
'Authorization' => base64_encode('username:secret'),
|
||||
'Content-Type' => 'application/json',
|
||||
], json_encode([
|
||||
'auth_token' => $user->auth_token,
|
||||
'domain' => 'reserved',
|
||||
])));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_allows_domain_reservation_for_users_with_the_right_flag()
|
||||
{
|
||||
/** @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_domains' => 1,
|
||||
])));
|
||||
|
||||
$user = json_decode($response->getBody()->getContents())->user;
|
||||
|
||||
$response = $this->await($this->browser->post('http://127.0.0.1:8080/api/domains', [
|
||||
'Host' => 'expose.localhost',
|
||||
'Authorization' => base64_encode('username:secret'),
|
||||
'Content-Type' => 'application/json',
|
||||
], json_encode([
|
||||
'auth_token' => $user->auth_token,
|
||||
'domain' => 'reserved',
|
||||
])));
|
||||
|
||||
$this->assertSame(200, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_does_not_allow_subdomain_reservation_for_users_without_the_right_flag()
|
||||
{
|
||||
|
||||
@@ -277,6 +277,53 @@ class TunnelTest extends TestCase
|
||||
$this->assertSame('reserved', $response->subdomain);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_rejects_users_that_want_to_use_a_reserved_subdomain_on_a_custom_domain()
|
||||
{
|
||||
$this->app['config']['expose.admin.validate_auth_tokens'] = true;
|
||||
|
||||
$user = $this->createUser([
|
||||
'name' => 'Marcel',
|
||||
'can_specify_domains' => 1,
|
||||
'can_specify_subdomains' => 1,
|
||||
]);
|
||||
|
||||
$this->await($this->browser->post('http://127.0.0.1:8080/api/domains', [
|
||||
'Host' => 'expose.localhost',
|
||||
'Authorization' => base64_encode('username:secret'),
|
||||
'Content-Type' => 'application/json',
|
||||
], json_encode([
|
||||
'domain' => 'share.beyondco.de',
|
||||
'auth_token' => $user->auth_token,
|
||||
])));
|
||||
|
||||
$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',
|
||||
'domain' => 'share.beyondco.de',
|
||||
'auth_token' => $user->auth_token,
|
||||
])));
|
||||
|
||||
$user = $this->createUser([
|
||||
'name' => 'Test-User',
|
||||
'can_specify_subdomains' => 1,
|
||||
]);
|
||||
|
||||
$this->createTestHttpServer();
|
||||
|
||||
/**
|
||||
* We create an expose client that connects to our server and shares
|
||||
* the created test HTTP server.
|
||||
*/
|
||||
$client = $this->createClient();
|
||||
$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()
|
||||
{
|
||||
@@ -306,9 +353,19 @@ class TunnelTest extends TestCase
|
||||
|
||||
$user = $this->createUser([
|
||||
'name' => 'Marcel',
|
||||
'can_specify_domains' => 1,
|
||||
'can_specify_subdomains' => 1,
|
||||
]);
|
||||
|
||||
$this->await($this->browser->post('http://127.0.0.1:8080/api/domains', [
|
||||
'Host' => 'expose.localhost',
|
||||
'Authorization' => base64_encode('username:secret'),
|
||||
'Content-Type' => 'application/json',
|
||||
], json_encode([
|
||||
'domain' => 'share.beyondco.de',
|
||||
'auth_token' => $user->auth_token,
|
||||
])));
|
||||
|
||||
$this->createTestHttpServer();
|
||||
|
||||
$client = $this->createClient();
|
||||
@@ -322,6 +379,93 @@ class TunnelTest extends TestCase
|
||||
$this->assertSame('taken', $response->subdomain);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_allows_users_that_want_to_use_a_reserved_subdomain_on_a_custom_domain()
|
||||
{
|
||||
$this->app['config']['expose.admin.validate_auth_tokens'] = true;
|
||||
|
||||
$user = $this->createUser([
|
||||
'name' => 'Marcel',
|
||||
'can_specify_subdomains' => 1,
|
||||
]);
|
||||
|
||||
$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,
|
||||
])));
|
||||
|
||||
$user = $this->createUser([
|
||||
'name' => 'Test-User',
|
||||
'can_specify_subdomains' => 1,
|
||||
'can_specify_domains' => 1,
|
||||
]);
|
||||
|
||||
$this->await($this->browser->post('http://127.0.0.1:8080/api/domains', [
|
||||
'Host' => 'expose.localhost',
|
||||
'Authorization' => base64_encode('username:secret'),
|
||||
'Content-Type' => 'application/json',
|
||||
], json_encode([
|
||||
'domain' => 'beyondco.de',
|
||||
'auth_token' => $user->auth_token,
|
||||
])));
|
||||
|
||||
$this->createTestHttpServer();
|
||||
|
||||
$client = $this->createClient();
|
||||
$response = $this->await($client->connectToServer('127.0.0.1:8085', 'reserved', 'beyondco.de', $user->auth_token));
|
||||
|
||||
$this->assertSame('reserved', $response->subdomain);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_rejects_users_that_want_to_use_a_reserved_subdomain_on_a_custom_domain_that_does_not_belong_them()
|
||||
{
|
||||
$this->app['config']['expose.admin.validate_auth_tokens'] = true;
|
||||
|
||||
$user = $this->createUser([
|
||||
'name' => 'Marcel',
|
||||
'can_specify_subdomains' => 1,
|
||||
'can_specify_domains' => 1,
|
||||
]);
|
||||
|
||||
$this->await($this->browser->post('http://127.0.0.1:8080/api/domains', [
|
||||
'Host' => 'expose.localhost',
|
||||
'Authorization' => base64_encode('username:secret'),
|
||||
'Content-Type' => 'application/json',
|
||||
], json_encode([
|
||||
'domain' => 'beyondco.de',
|
||||
'auth_token' => $user->auth_token,
|
||||
])));
|
||||
|
||||
$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',
|
||||
'domain' => 'beyondco.de',
|
||||
'auth_token' => $user->auth_token,
|
||||
])));
|
||||
|
||||
$user = $this->createUser([
|
||||
'name' => 'Test-User',
|
||||
'can_specify_subdomains' => 1,
|
||||
]);
|
||||
|
||||
$this->createTestHttpServer();
|
||||
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
|
||||
$client = $this->createClient();
|
||||
$response = $this->await($client->connectToServer('127.0.0.1:8085', 'reserved', 'beyondco.de', $user->auth_token));
|
||||
|
||||
$this->assertSame('reserved', $response->subdomain);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_allows_users_to_use_their_own_reserved_subdomains()
|
||||
{
|
||||
@@ -352,6 +496,47 @@ class TunnelTest extends TestCase
|
||||
$this->assertSame('reserved', $response->subdomain);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_allows_users_to_use_their_own_reserved_subdomains_on_custom_domains()
|
||||
{
|
||||
$this->app['config']['expose.admin.validate_auth_tokens'] = true;
|
||||
|
||||
$user = $this->createUser([
|
||||
'name' => 'Marcel',
|
||||
'can_specify_domains' => 1,
|
||||
'can_specify_subdomains' => 1,
|
||||
]);
|
||||
|
||||
$response = $this->await($this->browser->post('http://127.0.0.1:8080/api/domains', [
|
||||
'Host' => 'expose.localhost',
|
||||
'Authorization' => base64_encode('username:secret'),
|
||||
'Content-Type' => 'application/json',
|
||||
], json_encode([
|
||||
'domain' => 'share.beyondco.de',
|
||||
'auth_token' => $user->auth_token,
|
||||
])));
|
||||
|
||||
$response = $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',
|
||||
'domain' => 'share.beyondco.de',
|
||||
'auth_token' => $user->auth_token,
|
||||
])));
|
||||
|
||||
$this->createTestHttpServer();
|
||||
/**
|
||||
* We create an expose client that connects to our server and shares
|
||||
* the created test HTTP server.
|
||||
*/
|
||||
$client = $this->createClient();
|
||||
$response = $this->await($client->connectToServer('127.0.0.1:8085', 'reserved', 'share.beyondco.de', $user->auth_token));
|
||||
|
||||
$this->assertSame('reserved', $response->subdomain);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_rejects_clients_with_too_many_connections()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user