Skip to content

Commit 48351fc

Browse files
committed
Fix SecureServer to return null URI if server socket is already closed
1 parent 7b5319c commit 48351fc

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

src/SecureServer.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function __construct(ServerInterface $tcp, LoopInterface $loop, array $co
121121
throw new \BadMethodCallException('Encryption not supported on your platform (HHVM < 3.8?)'); // @codeCoverageIgnore
122122
}
123123

124-
// default to empty passphrase to surpress blocking passphrase prompt
124+
// default to empty passphrase to suppress blocking passphrase prompt
125125
$context += array(
126126
'passphrase' => ''
127127
);
@@ -141,7 +141,12 @@ public function __construct(ServerInterface $tcp, LoopInterface $loop, array $co
141141

142142
public function getAddress()
143143
{
144-
return str_replace('tcp://' , 'tls://', $this->tcp->getAddress());
144+
$address = $this->tcp->getAddress();
145+
if ($address === null) {
146+
return null;
147+
}
148+
149+
return str_replace('tcp://' , 'tls://', $address);
145150
}
146151

147152
public function pause()

tests/SecureServerTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ public function testGetAddressWillBePassedThroughToTcpServer()
2626
$this->assertEquals('127.0.0.1:1234', $server->getAddress());
2727
}
2828

29+
public function testGetAddressWillReturnNullIfTcpServerReturnsNull()
30+
{
31+
$tcp = $this->getMockBuilder('React\Socket\ServerInterface')->getMock();
32+
$tcp->expects($this->once())->method('getAddress')->willReturn(null);
33+
34+
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
35+
36+
$server = new SecureServer($tcp, $loop, array());
37+
38+
$this->assertNull($server->getAddress());
39+
}
40+
2941
public function testPauseWillBePassedThroughToTcpServer()
3042
{
3143
$tcp = $this->getMockBuilder('React\Socket\ServerInterface')->getMock();

0 commit comments

Comments
 (0)