Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Ratchet/Http/OriginCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(MessageComponentInterface $component, array $allowed
*/
#[HackSupportForPHP8] public function onOpen(ConnectionInterface $conn, ?RequestInterface $request = null) { /*
public function onOpen(ConnectionInterface $conn, RequestInterface $request = null) { /**/
$header = (string)$request->getHeader('Origin')[0];
$header = $request->getHeaderLine('Origin');
$origin = parse_url($header, PHP_URL_HOST) ?: $header;

if (!in_array($origin, $this->allowedOrigins)) {
Expand Down
20 changes: 19 additions & 1 deletion tests/unit/Http/OriginCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class OriginCheckTest extends AbstractMessageComponentTestCase {
*/
public function setUpConnection() {
$this->_reqStub = $this->getMockBuilder('Psr\Http\Message\RequestInterface')->getMock();
$this->_reqStub->expects($this->any())->method('getHeader')->will($this->returnValue(['localhost']));
$this->_reqStub->expects($this->any())->method('getHeaderLine')->with('Origin')->willReturn('localhost');

parent::setUpConnection();

Expand Down Expand Up @@ -44,6 +44,24 @@ public function testCloseOnNonMatchingOrigin() {
$this->_serv->onOpen($this->_conn, $this->_reqStub);
}

public function testCloseOnMissingOrigin() {
$this->_serv->allowedOrigins = ['socketo.me'];
$this->_conn->expects($this->once())->method('close');

$this->_reqStub->expects($this->once())->method('getHeaderLine')->with('Origin')->willReturn('');

$this->_serv->onOpen($this->_conn, $this->_reqStub);
}

public function testCloseOnDuplicateOrigin() {
$this->_serv->allowedOrigins = ['socketo.me'];
$this->_conn->expects($this->once())->method('close');

$this->_reqStub->expects($this->once())->method('getHeaderLine')->with('Origin')->willReturn('http://socketo.me,https://socketo.me');

$this->_serv->onOpen($this->_conn, $this->_reqStub);
}

public function testOnMessage() {
$this->passthroughMessageTest('Hello World!');
}
Expand Down