Skip to content

Commit

Permalink
Merge pull request reactphp#72 from clue-labs/wrap
Browse files Browse the repository at this point in the history
Replace SecureStream with unlimited read buffer from react/stream v0.4.5
  • Loading branch information
clue authored Dec 19, 2016
2 parents 43993f3 + 12a7eaf commit 223e0a3
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 122 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"php": ">=5.3.0",
"react/dns": "0.4.*|0.3.*",
"react/event-loop": "0.4.*|0.3.*",
"react/stream": "0.4.*|0.3.*",
"react/stream": "^0.4.5",
"react/promise": "^2.1 || ^1.2",
"react/promise-timer": "~1.0"
},
Expand All @@ -17,6 +17,6 @@
}
},
"require-dev": {
"clue/block-react": "~1.0"
"clue/block-react": "^1.1"
}
}
98 changes: 0 additions & 98 deletions src/SecureStream.php

This file was deleted.

6 changes: 1 addition & 5 deletions src/StreamEncryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ public function disable(Stream $stream)

public function toggle(Stream $stream, $toggle)
{
if (__NAMESPACE__ . '\SecureStream' === get_class($stream)) {
$stream = $stream->decorating;
}

// pause actual stream instance to continue operation on raw stream socket
$stream->pause();

Expand Down Expand Up @@ -89,7 +85,7 @@ public function toggle(Stream $stream, $toggle)
$loop->removeReadStream($socket);

if ($wrap) {
return new SecureStream($stream, $loop);
$stream->bufferSize = null;
}

$stream->resume();
Expand Down
10 changes: 6 additions & 4 deletions tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

class IntegrationTest extends TestCase
{
const TIMEOUT = 5.0;

/** @test */
public function gettingStuffFromGoogleShouldWork()
{
Expand All @@ -26,7 +28,7 @@ public function gettingStuffFromGoogleShouldWork()

$conn->write("GET / HTTP/1.0\r\n\r\n");

$response = Block\await(BufferedSink::createPromise($conn), $loop);
$response = Block\await(BufferedSink::createPromise($conn), $loop, self::TIMEOUT);

$this->assertRegExp('#^HTTP/1\.0#', $response);
}
Expand All @@ -52,7 +54,7 @@ public function gettingEncryptedStuffFromGoogleShouldWork()

$conn->write("GET / HTTP/1.0\r\n\r\n");

$response = Block\await(BufferedSink::createPromise($conn), $loop);
$response = Block\await(BufferedSink::createPromise($conn), $loop, self::TIMEOUT);

$this->assertRegExp('#^HTTP/1\.0#', $response);
}
Expand All @@ -78,7 +80,7 @@ public function testSelfSignedRejectsIfVerificationIsEnabled()
);

$this->setExpectedException('RuntimeException');
Block\await($secureConnector->create('self-signed.badssl.com', 443), $loop);
Block\await($secureConnector->create('self-signed.badssl.com', 443), $loop, self::TIMEOUT);
}

/** @test */
Expand All @@ -101,7 +103,7 @@ public function testSelfSignedResolvesIfVerificationIsDisabled()
)
);

$conn = Block\await($secureConnector->create('self-signed.badssl.com', 443), $loop);
$conn = Block\await($secureConnector->create('self-signed.badssl.com', 443), $loop, self::TIMEOUT);
$conn->close();
}

Expand Down
24 changes: 13 additions & 11 deletions tests/SecureIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

class SecureIntegrationTest extends TestCase
{
const TIMEOUT = 0.5;

private $portSecure;
private $portPlain;

Expand Down Expand Up @@ -51,7 +53,7 @@ public function tearDown()

public function testConnectToServer()
{
$client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop);
$client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop, self::TIMEOUT);
/* @var $client Stream */

$client->close();
Expand All @@ -63,7 +65,7 @@ public function testConnectToServerEmitsConnection()

$promiseClient = $this->connector->create('127.0.0.1', $this->portSecure);

list($_, $client) = Block\awaitAll(array($promiseServer, $promiseClient), $this->loop);
list($_, $client) = Block\awaitAll(array($promiseServer, $promiseClient), $this->loop, self::TIMEOUT);
/* @var $client Stream */

$client->close();
Expand All @@ -79,13 +81,13 @@ public function testSendSmallDataToServerReceivesOneChunk()
});
});

$client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop);
$client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop, self::TIMEOUT);
/* @var $client Stream */

$client->write('hello');

// await server to report one "data" event
$data = Block\await($received->promise(), $this->loop);
$data = Block\await($received->promise(), $this->loop, self::TIMEOUT);

$client->close();

Expand All @@ -105,14 +107,14 @@ public function testSendDataWithEndToServerReceivesAllData()
});
});

$client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop);
$client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop, self::TIMEOUT);
/* @var $client Stream */

$data = str_repeat('a', 200000);
$client->end($data);

// await server to report connection "close" event
$received = Block\await($disconnected->promise(), $this->loop);
$received = Block\await($disconnected->promise(), $this->loop, self::TIMEOUT);

$this->assertEquals($data, $received);
}
Expand All @@ -126,7 +128,7 @@ public function testSendDataWithoutEndingToServerReceivesAllData()
});
});

$client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop);
$client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop, self::TIMEOUT);
/* @var $client Stream */

$data = str_repeat('d', 200000);
Expand All @@ -146,12 +148,12 @@ public function testConnectToServerWhichSendsSmallDataReceivesOneChunk()
$peer->write('hello');
});

$client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop);
$client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop, self::TIMEOUT);
/* @var $client Stream */

// await client to report one "data" event
$receive = $this->createPromiseForEvent($client, 'data', $this->expectCallableOnceWith('hello'));
Block\await($receive, $this->loop);
Block\await($receive, $this->loop, self::TIMEOUT);

$client->close();
}
Expand All @@ -163,11 +165,11 @@ public function testConnectToServerWhichSendsDataWithEndReceivesAllData()
$peer->end($data);
});

$client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop);
$client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop, self::TIMEOUT);
/* @var $client Stream */

// await data from client until it closes
$received = Block\await(BufferedSink::createPromise($client), $this->loop);
$received = Block\await(BufferedSink::createPromise($client), $this->loop, self::TIMEOUT);

$this->assertEquals($data, $received);
}
Expand Down
6 changes: 4 additions & 2 deletions tests/TcpConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

class TcpConnectorTest extends TestCase
{
const TIMEOUT = 0.1;

/** @test */
public function connectionToEmptyPortShouldFail()
{
Expand All @@ -35,7 +37,7 @@ public function connectionToTcpServerShouldSucceed()

$connector = new TcpConnector($loop);

$stream = Block\await($connector->create('127.0.0.1', 9999), $loop);
$stream = Block\await($connector->create('127.0.0.1', 9999), $loop, self::TIMEOUT);

$this->assertInstanceOf('React\Stream\Stream', $stream);

Expand Down Expand Up @@ -67,7 +69,7 @@ public function connectionToIp6TcpServerShouldSucceed()

$connector = new TcpConnector($loop);

$stream = Block\await($connector->create('::1', 9999), $loop);
$stream = Block\await($connector->create('::1', 9999), $loop, self::TIMEOUT);

$this->assertInstanceOf('React\Stream\Stream', $stream);

Expand Down

0 comments on commit 223e0a3

Please sign in to comment.