| 3 |
liveuser |
1 |
<?php
|
|
|
2 |
namespace Ratchet\Http;
|
|
|
3 |
use Ratchet\AbstractMessageComponentTestCase;
|
|
|
4 |
|
|
|
5 |
/**
|
|
|
6 |
* @covers Ratchet\Http\OriginCheck
|
|
|
7 |
*/
|
|
|
8 |
class OriginCheckTest extends AbstractMessageComponentTestCase {
|
|
|
9 |
protected $_reqStub;
|
|
|
10 |
|
|
|
11 |
public function setUp() {
|
|
|
12 |
$this->_reqStub = $this->getMock('Psr\Http\Message\RequestInterface');
|
|
|
13 |
$this->_reqStub->expects($this->any())->method('getHeader')->will($this->returnValue(['localhost']));
|
|
|
14 |
|
|
|
15 |
parent::setUp();
|
|
|
16 |
|
|
|
17 |
$this->_serv->allowedOrigins[] = 'localhost';
|
|
|
18 |
}
|
|
|
19 |
|
|
|
20 |
protected function doOpen($conn) {
|
|
|
21 |
$this->_serv->onOpen($conn, $this->_reqStub);
|
|
|
22 |
}
|
|
|
23 |
|
|
|
24 |
public function getConnectionClassString() {
|
|
|
25 |
return '\Ratchet\ConnectionInterface';
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
public function getDecoratorClassString() {
|
|
|
29 |
return '\Ratchet\Http\OriginCheck';
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
public function getComponentClassString() {
|
|
|
33 |
return '\Ratchet\Http\HttpServerInterface';
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
public function testCloseOnNonMatchingOrigin() {
|
|
|
37 |
$this->_serv->allowedOrigins = ['socketo.me'];
|
|
|
38 |
$this->_conn->expects($this->once())->method('close');
|
|
|
39 |
|
|
|
40 |
$this->_serv->onOpen($this->_conn, $this->_reqStub);
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
public function testOnMessage() {
|
|
|
44 |
$this->passthroughMessageTest('Hello World!');
|
|
|
45 |
}
|
|
|
46 |
}
|