Skip to content

Commit f15683a

Browse files
committed
Add tests to exhibit SSL/TLS buffering issues
Test receiving larger buffers without ending the stream
1 parent 72535fc commit f15683a

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

tests/SecureIntegrationTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,29 @@ public function testSendDataWithEndToServerReceivesAllData()
117117
$this->assertEquals($data, $received);
118118
}
119119

120+
public function testSendDataWithoutEndingToServerReceivesAllData()
121+
{
122+
$received = '';
123+
$this->server->on('connection', function (Stream $peer) use (&$received) {
124+
$peer->on('data', function ($chunk) use (&$received) {
125+
$received .= $chunk;
126+
});
127+
});
128+
129+
$client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop);
130+
/* @var $client Stream */
131+
132+
$data = str_repeat('d', 200000);
133+
$client->write($data);
134+
135+
// buffer incoming data for 0.1s (should be plenty of time)
136+
Block\sleep(0.1, $this->loop);
137+
138+
$client->close();
139+
140+
$this->assertEquals($data, $received);
141+
}
142+
120143
public function testConnectToServerWhichSendsSmallDataReceivesOneChunk()
121144
{
122145
$this->server->on('connection', function (Stream $peer) {
@@ -149,6 +172,28 @@ public function testConnectToServerWhichSendsDataWithEndReceivesAllData()
149172
$this->assertEquals($data, $received);
150173
}
151174

175+
public function testConnectToServerWhichSendsDataWithoutEndingReceivesAllData()
176+
{
177+
$data = str_repeat('c', 100000);
178+
$this->server->on('connection', function (Stream $peer) use ($data) {
179+
$peer->write($data);
180+
});
181+
182+
$client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop);
183+
/* @var $client Stream */
184+
185+
// buffer incoming data for 0.1s (should be plenty of time)
186+
$received = '';
187+
$client->on('data', function ($chunk) use (&$received) {
188+
$received .= $chunk;
189+
});
190+
Block\sleep(0.1, $this->loop);
191+
192+
$client->close();
193+
194+
$this->assertEquals($data, $received);
195+
}
196+
152197
private function createPromiseForEvent(EventEmitterInterface $emitter, $event, $fn)
153198
{
154199
return new Promise(function ($resolve) use ($emitter, $event, $fn) {

0 commit comments

Comments
 (0)