mirror of
https://github.com/bitinflow/expose.git
synced 2026-03-13 13:35:54 +00:00
wip
This commit is contained in:
@@ -49,6 +49,9 @@ class Factory
|
|||||||
/** @var RouteGenerator */
|
/** @var RouteGenerator */
|
||||||
protected $router;
|
protected $router;
|
||||||
|
|
||||||
|
/** @var Server */
|
||||||
|
protected $socket;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->loop = LoopFactory::create();
|
$this->loop = LoopFactory::create();
|
||||||
@@ -145,7 +148,7 @@ class Factory
|
|||||||
|
|
||||||
public function createServer()
|
public function createServer()
|
||||||
{
|
{
|
||||||
$socket = new Server("{$this->host}:{$this->port}", $this->loop);
|
$this->socket = new Server("{$this->host}:{$this->port}", $this->loop);
|
||||||
|
|
||||||
$this->bindConfiguration()
|
$this->bindConfiguration()
|
||||||
->bindSubdomainGenerator()
|
->bindSubdomainGenerator()
|
||||||
@@ -164,13 +167,18 @@ class Factory
|
|||||||
|
|
||||||
$http = new HttpServer($router);
|
$http = new HttpServer($router);
|
||||||
|
|
||||||
$server = new IoServer($http, $socket, $this->loop);
|
$server = new IoServer($http, $this->socket, $this->loop);
|
||||||
|
|
||||||
$controlConnection->enableKeepAlive($this->loop);
|
$controlConnection->enableKeepAlive($this->loop);
|
||||||
|
|
||||||
return $server;
|
return $server;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getSocket(): Server
|
||||||
|
{
|
||||||
|
return $this->socket;
|
||||||
|
}
|
||||||
|
|
||||||
protected function bindDatabase()
|
protected function bindDatabase()
|
||||||
{
|
{
|
||||||
app()->singleton(DatabaseInterface::class, function() {
|
app()->singleton(DatabaseInterface::class, function() {
|
||||||
|
|||||||
@@ -11,8 +11,14 @@
|
|||||||
},
|
},
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "Nuno Maduro",
|
"name": "Marcel Pociot",
|
||||||
"email": "enunomaduro@gmail.com"
|
"email": "marcel@beyondco.de"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"repositories": [
|
||||||
|
{
|
||||||
|
"type": "vcs",
|
||||||
|
"url": "https://github.com/pestphp/pest"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
@@ -38,7 +44,6 @@
|
|||||||
"ratchet/pawl": "^0.3.4",
|
"ratchet/pawl": "^0.3.4",
|
||||||
"react/socket": "^1.4",
|
"react/socket": "^1.4",
|
||||||
"riverline/multipart-parser": "^2.0",
|
"riverline/multipart-parser": "^2.0",
|
||||||
"seregazhuk/react-promise-testing": "^0.4.0",
|
|
||||||
"symfony/expression-language": "^5.0",
|
"symfony/expression-language": "^5.0",
|
||||||
"symfony/http-kernel": "^4.0|^5.0",
|
"symfony/http-kernel": "^4.0|^5.0",
|
||||||
"symfony/psr-http-message-bridge": "^2.0",
|
"symfony/psr-http-message-bridge": "^2.0",
|
||||||
|
|||||||
@@ -2,7 +2,70 @@
|
|||||||
|
|
||||||
namespace Tests\Feature\Server;
|
namespace Tests\Feature\Server;
|
||||||
|
|
||||||
class AdminTest
|
use App\Http\Server;
|
||||||
{
|
use App\Server\Factory;
|
||||||
|
use Clue\React\Buzz\Browser;
|
||||||
|
use Clue\React\Buzz\Message\ResponseException;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use React\Socket\Connector;
|
||||||
|
use Tests\Feature\TestCase;
|
||||||
|
|
||||||
|
class AdminTest extends TestCase
|
||||||
|
{
|
||||||
|
/** @var Browser */
|
||||||
|
protected $browser;
|
||||||
|
|
||||||
|
/** @var Factory */
|
||||||
|
protected $serverFactory;
|
||||||
|
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->browser = new Browser($this->loop);
|
||||||
|
|
||||||
|
$this->startServer();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tearDown(): void
|
||||||
|
{
|
||||||
|
$this->serverFactory->getSocket()->close();
|
||||||
|
|
||||||
|
parent::tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function it_is_protected_using_basic_authentication()
|
||||||
|
{
|
||||||
|
$this->expectException(ResponseException::class);
|
||||||
|
$this->expectExceptionMessage(401);
|
||||||
|
|
||||||
|
/** @var ResponseInterface $response */
|
||||||
|
$this->await($this->browser->get('http://127.0.0.1:8080', [
|
||||||
|
'Host' => 'expose.localhost'
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function it_accepts_valid_credentials()
|
||||||
|
{
|
||||||
|
$this->app['config']['expose.admin.users'] = [
|
||||||
|
'username' => 'secret',
|
||||||
|
];
|
||||||
|
|
||||||
|
/** @var ResponseInterface $response */
|
||||||
|
$response = $this->await($this->browser->get('http://127.0.0.1:8080', [
|
||||||
|
'Host' => 'expose.localhost',
|
||||||
|
'Authorization' => base64_encode("username:secret"),
|
||||||
|
]));
|
||||||
|
$this->assertSame(200, $response->getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function startServer()
|
||||||
|
{
|
||||||
|
$this->serverFactory = new Factory();
|
||||||
|
|
||||||
|
$this->serverFactory->setLoop($this->loop)
|
||||||
|
->createServer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user