mirror of
https://github.com/bitinflow/expose.git
synced 2026-03-13 13:35:54 +00:00
wip
This commit is contained in:
@@ -84,6 +84,25 @@ class AdminTest extends TestCase
|
||||
/** @test */
|
||||
public function it_can_create_users()
|
||||
{
|
||||
/** @var Response $response */
|
||||
$response = $this->await($this->browser->post('http://127.0.0.1:8080/users', [
|
||||
'Host' => 'expose.localhost',
|
||||
'Authorization' => base64_encode("username:secret"),
|
||||
'Content-Type' => 'application/json'
|
||||
], json_encode([
|
||||
'name' => 'Marcel',
|
||||
])));
|
||||
|
||||
$responseData = json_decode($response->getBody()->getContents());
|
||||
$this->assertSame('Marcel', $responseData->user->name);
|
||||
|
||||
$this->assertDatabaseHasResults('SELECT * FROM users WHERE name = "Marcel"');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_delete_users()
|
||||
{
|
||||
/** @var Response $response */
|
||||
$this->await($this->browser->post('http://127.0.0.1:8080/users', [
|
||||
'Host' => 'expose.localhost',
|
||||
'Authorization' => base64_encode("username:secret"),
|
||||
@@ -92,7 +111,38 @@ class AdminTest extends TestCase
|
||||
'name' => 'Marcel',
|
||||
])));
|
||||
|
||||
$this->assertDatabaseHasResults('SELECT * FROM users WHERE name = "Marcel"');
|
||||
|
||||
$this->await($this->browser->delete('http://127.0.0.1:8080/users/1', [
|
||||
'Host' => 'expose.localhost',
|
||||
'Authorization' => base64_encode("username:secret"),
|
||||
'Content-Type' => 'application/json'
|
||||
]));
|
||||
|
||||
$this->assertDatabaseHasNoResults('SELECT * FROM users WHERE name = "Marcel"');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_list_all_users()
|
||||
{
|
||||
/** @var Response $response */
|
||||
$this->await($this->browser->post('http://127.0.0.1:8080/users', [
|
||||
'Host' => 'expose.localhost',
|
||||
'Authorization' => base64_encode("username:secret"),
|
||||
'Content-Type' => 'application/json'
|
||||
], json_encode([
|
||||
'name' => 'Marcel',
|
||||
])));
|
||||
|
||||
/** @var Response $response */
|
||||
$response = $this->await($this->browser->get('http://127.0.0.1:8080/users', [
|
||||
'Host' => 'expose.localhost',
|
||||
'Authorization' => base64_encode("username:secret"),
|
||||
'Content-Type' => 'application/json'
|
||||
]));
|
||||
|
||||
$body = $response->getBody()->getContents();
|
||||
|
||||
$this->assertTrue(Str::contains($body, 'Marcel'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
|
||||
@@ -24,6 +24,9 @@ class TunnelTest extends TestCase
|
||||
/** @var Factory */
|
||||
protected $serverFactory;
|
||||
|
||||
/** @var \React\Socket\Server */
|
||||
protected $testHttpServer;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
@@ -37,6 +40,10 @@ class TunnelTest extends TestCase
|
||||
{
|
||||
$this->serverFactory->getSocket()->close();
|
||||
|
||||
if (isset($this->testHttpServer)) {
|
||||
$this->testHttpServer->close();
|
||||
}
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
@@ -74,6 +81,39 @@ class TunnelTest extends TestCase
|
||||
$this->assertSame('Hello World!', $response->getBody()->getContents());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_rejects_clients_with_invalid_auth_tokens()
|
||||
{
|
||||
$this->app['config']['expose.admin.validate_auth_tokens'] = true;
|
||||
|
||||
$this->createTestHttpServer();
|
||||
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
|
||||
/**
|
||||
* We create an expose client that connects to our server and shares
|
||||
* the created test HTTP server
|
||||
*/
|
||||
$client = $this->createClient();
|
||||
$result = $this->await($client->connectToServer('127.0.0.1:8085', 'tunnel'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_allows_clients_with_valid_auth_tokens()
|
||||
{
|
||||
$this->app['config']['expose.admin.validate_auth_tokens'] = true;
|
||||
|
||||
$this->createTestHttpServer();
|
||||
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
|
||||
/**
|
||||
* 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'));
|
||||
}
|
||||
|
||||
protected function startServer()
|
||||
{
|
||||
@@ -104,7 +144,7 @@ class TunnelTest extends TestCase
|
||||
return new Response(200, ['Content-Type' => 'text/plain'], "Hello World!");
|
||||
});
|
||||
|
||||
$socket = new \React\Socket\Server(8085, $this->loop);
|
||||
$server->listen($socket);
|
||||
$this->testHttpServer = new \React\Socket\Server(8085, $this->loop);
|
||||
$server->listen($this->testHttpServer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,4 +46,13 @@ abstract class TestCase extends \Tests\TestCase
|
||||
|
||||
$this->assertGreaterThanOrEqual(1, count($result->rows));
|
||||
}
|
||||
|
||||
protected function assertDatabaseHasNoResults($query)
|
||||
{
|
||||
$database = app(DatabaseInterface::class);
|
||||
|
||||
$result = $this->await($database->query($query));
|
||||
|
||||
$this->assertEmpty($result->rows);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user