-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduces TLS support for secure WebSockets (#43)
* add tls support * refactor away from booleans * docs * remove auto secure * wip * remove method * update tests * formatting * formatting
- Loading branch information
Showing
5 changed files
with
65 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
use Laravel\Reverb\Servers\Reverb\Factory; | ||
use React\Socket\SecureServer; | ||
use React\Socket\TcpServer; | ||
|
||
it('can create a server', function () { | ||
$server = Factory::make(); | ||
|
||
$socket = (new ReflectionProperty($server, 'socket'))->getValue($server); | ||
$socketServer = (new ReflectionProperty($socket, 'server'))->getValue($socket); | ||
|
||
expect($socketServer)->toBeInstanceOf(TcpServer::class); | ||
|
||
$server->stop(); | ||
}); | ||
|
||
it('can create a server with the given host and port', function () { | ||
$server = Factory::make('127.0.0.1', '8001'); | ||
|
||
$socket = (new ReflectionProperty($server, 'socket'))->getValue($server); | ||
$socketServer = (new ReflectionProperty($socket, 'server'))->getValue($socket); | ||
|
||
expect($socketServer)->toBeInstanceOf(TcpServer::class); | ||
expect($socketServer->getAddress())->toBe('tcp://127.0.0.1:8001'); | ||
|
||
$server->stop(); | ||
}); | ||
|
||
it('can create a tls server using a user provided certificate', function () { | ||
$this->app->config->set('reverb.servers.reverb.options.tls.local_cert', '/path/to/cert.pem'); | ||
$this->app->config->set('reverb.servers.reverb.options.tls.verify_peer', false); | ||
$server = Factory::make(options: $this->app->config->get('reverb.servers.reverb.options')); | ||
|
||
$socket = (new ReflectionProperty($server, 'socket'))->getValue($server); | ||
$socketServer = (new ReflectionProperty($socket, 'server'))->getValue($socket); | ||
$context = (new ReflectionProperty($socketServer, 'context'))->getValue($socketServer); | ||
|
||
expect($socketServer)->toBeInstanceOf(SecureServer::class); | ||
expect($context['local_cert'])->toBe('/path/to/cert.pem'); | ||
expect($context['verify_peer'])->toBeFalse(); | ||
|
||
$server->stop(); | ||
}); | ||
|
||
it('can create a server using tls on the given host and port', function () { | ||
$this->app->config->set('reverb.servers.reverb.options.tls.local_cert', '/path/to/cert.pem'); | ||
$server = Factory::make('127.0.0.1', '8002', $this->app->config->get('reverb.servers.reverb.options')); | ||
|
||
$socket = (new ReflectionProperty($server, 'socket'))->getValue($server); | ||
$socketServer = (new ReflectionProperty($socket, 'server'))->getValue($socket); | ||
|
||
expect($socketServer)->toBeInstanceOf(SecureServer::class); | ||
expect($socketServer->getAddress())->toBe('tls://127.0.0.1:8002'); | ||
|
||
$server->stop(); | ||
}); |