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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
strategy:
matrix:
php:
- 8.5
- 8.4
- 8.3
- 8.2
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
"require": {
"php": ">=5.3",
"clue/socks-react": "^1.5",
"react/child-process": "^0.6.6",
"react/event-loop": "^1.2",
"react/promise": "^3.2 || ^2.11 || ^1.3",
"react/socket": "^1.16",
"react/child-process": "^0.6.7",
"react/event-loop": "^1.6",
"react/promise": "^3.3 || ^2.11 || ^1.3",
"react/socket": "^1.17",
"react/stream": "^1.4"
},
"require-dev": {
Expand Down
16 changes: 12 additions & 4 deletions tests/IntegrationSshProcessConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public function testConnectWillResolveWithConnectionInterfaceWhenProcessOutputsC
$connector = new SshProcessConnector('host');

$ref = new \ReflectionProperty($connector, 'cmd');
$ref->setAccessible(true);
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$ref->setValue($connector, 'echo "debug2: channel 0: open confirm rwindow 2097152 rmax 32768" >&2; #');

$promise = $connector->connect('example.com:80');
Expand All @@ -27,7 +29,9 @@ public function testConnectWillRejectWithExceptionWhenProcessOutputsChannelOpenF
$connector = new SshProcessConnector('host');

$ref = new \ReflectionProperty($connector, 'cmd');
$ref->setAccessible(true);
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$ref->setValue($connector, 'echo "channel 0: open failed: administratively prohibited: open failed" >&2; #');

$promise = $connector->connect('example.com:80');
Expand All @@ -41,7 +45,9 @@ public function testConnectWillRejectWithExceptionWhenProcessOutputsEndsWithoutC
$connector = new SshProcessConnector('host');

$ref = new \ReflectionProperty($connector, 'cmd');
$ref->setAccessible(true);
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$ref->setValue($connector, 'echo foo >&2; #');

$promise = $connector->connect('example.com:80');
Expand All @@ -55,7 +61,9 @@ public function testConnectWillResolveWithConnectionThatWillEmitImmediateDataFro
$connector = new SshProcessConnector('host');

$ref = new \ReflectionProperty($connector, 'cmd');
$ref->setAccessible(true);
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$ref->setValue($connector, 'echo "debug2: channel 0: open confirm rwindow 2097152 rmax 32768" >&2; echo foo #');

$promise = $connector->connect('example.com:80');
Expand Down
20 changes: 15 additions & 5 deletions tests/SshProcessConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ public function testConstructWithoutLoopAssignsLoopAutomatically()
$connector = new SshProcessConnector('host');

$ref = new \ReflectionProperty($connector, 'loop');
$ref->setAccessible(true);
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$loop = $ref->getValue($connector);

$this->assertInstanceOf('React\EventLoop\LoopInterface', $loop);
Expand All @@ -23,7 +25,9 @@ public function testConstructorAcceptsUri()
$connector = new SshProcessConnector('host', $loop);

$ref = new \ReflectionProperty($connector, 'cmd');
$ref->setAccessible(true);
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}

$this->assertEquals('exec ssh -vv -o BatchMode=yes \'host\'', $ref->getValue($connector));
}
Expand All @@ -34,7 +38,9 @@ public function testConstructorAcceptsUriWithDefaultPortWillNotBeAddedToCommand(
$connector = new SshProcessConnector('host:22', $loop);

$ref = new \ReflectionProperty($connector, 'cmd');
$ref->setAccessible(true);
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}

$this->assertEquals('exec ssh -vv -o BatchMode=yes \'host\'', $ref->getValue($connector));
}
Expand All @@ -45,7 +51,9 @@ public function testConstructorAcceptsUriWithUserAndCustomPort()
$connector = new SshProcessConnector('user@host:2222', $loop);

$ref = new \ReflectionProperty($connector, 'cmd');
$ref->setAccessible(true);
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}

$this->assertEquals('exec ssh -vv -o BatchMode=yes -p 2222 \'user@host\'', $ref->getValue($connector));
}
Expand All @@ -56,7 +64,9 @@ public function testConstructorAcceptsUriWithPasswordWillPrefixSshCommandWithSsh
$connector = new SshProcessConnector('user:pass@host', $loop);

$ref = new \ReflectionProperty($connector, 'cmd');
$ref->setAccessible(true);
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}

$this->assertEquals('exec sshpass -p \'pass\' ssh -vv \'user@host\'', $ref->getValue($connector));
}
Expand Down
84 changes: 63 additions & 21 deletions tests/SshSocksConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public function testConstructWithoutLoopAssignsLoopAutomatically()
$connector = new SshSocksConnector('host');

$ref = new \ReflectionProperty($connector, 'loop');
$ref->setAccessible(true);
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$loop = $ref->getValue($connector);

$this->assertInstanceOf('React\EventLoop\LoopInterface', $loop);
Expand All @@ -24,7 +26,9 @@ public function testConstructorAcceptsUri()
$connector = new SshSocksConnector('host', $loop);

$ref = new \ReflectionProperty($connector, 'cmd');
$ref->setAccessible(true);
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}

$this->assertEquals('exec ssh -v -o ExitOnForwardFailure=yes -N -o BatchMode=yes -D \'127.0.0.1:1080\' \'host\'', $ref->getValue($connector));
}
Expand All @@ -35,7 +39,9 @@ public function testConstructorAcceptsUriWithDefaultPortWillNotBeAddedToCommand(
$connector = new SshSocksConnector('host:22', $loop);

$ref = new \ReflectionProperty($connector, 'cmd');
$ref->setAccessible(true);
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}

$this->assertEquals('exec ssh -v -o ExitOnForwardFailure=yes -N -o BatchMode=yes -D \'127.0.0.1:1080\' \'host\'', $ref->getValue($connector));
}
Expand All @@ -46,7 +52,9 @@ public function testConstructorAcceptsUriWithUserAndCustomPort()
$connector = new SshSocksConnector('user@host:2222', $loop);

$ref = new \ReflectionProperty($connector, 'cmd');
$ref->setAccessible(true);
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}

$this->assertEquals('exec ssh -v -o ExitOnForwardFailure=yes -N -o BatchMode=yes -p 2222 -D \'127.0.0.1:1080\' \'user@host\'', $ref->getValue($connector));
}
Expand All @@ -57,7 +65,9 @@ public function testConstructorAcceptsUriWithPasswordWillPrefixSshCommandWithSsh
$connector = new SshSocksConnector('user:pass@host', $loop);

$ref = new \ReflectionProperty($connector, 'cmd');
$ref->setAccessible(true);
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}

$this->assertEquals('exec sshpass -p \'pass\' ssh -v -o ExitOnForwardFailure=yes -N -D \'127.0.0.1:1080\' \'user@host\'', $ref->getValue($connector));
}
Expand All @@ -68,7 +78,9 @@ public function testConstructorAcceptsUriWithCustomBindUrl()
$connector = new SshSocksConnector('host?bind=127.1.0.1:2711', $loop);

$ref = new \ReflectionProperty($connector, 'cmd');
$ref->setAccessible(true);
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}

$this->assertEquals('exec ssh -v -o ExitOnForwardFailure=yes -N -o BatchMode=yes -D \'127.1.0.1:2711\' \'host\'', $ref->getValue($connector));
}
Expand All @@ -79,7 +91,9 @@ public function testConstructorAcceptsUriWithCustomBindUrlIpv6()
$connector = new SshSocksConnector('host?bind=[::1]:2711', $loop);

$ref = new \ReflectionProperty($connector, 'cmd');
$ref->setAccessible(true);
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}

$this->assertEquals('exec ssh -v -o ExitOnForwardFailure=yes -N -o BatchMode=yes -D \'[::1]:2711\' \'host\'', $ref->getValue($connector));
}
Expand Down Expand Up @@ -200,7 +214,9 @@ public function testConnectWillCancelPendingIdleTimerAndWaitForSshListener()

$timer = $this->getMockBuilder('React\EventLoop\TimerInterface')->getMock();
$ref = new \ReflectionProperty($connector, 'idleTimer');
$ref->setAccessible(true);
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$ref->setValue($connector, $timer);

$connector->connect('google.com:80');
Expand All @@ -214,7 +230,9 @@ public function testConnectWithFailingSshListenerShouldReturnRejectedPromise()

$deferred = new Deferred();
$ref = new \ReflectionProperty($connector, 'listen');
$ref->setAccessible(true);
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$ref->setValue($connector, $deferred->promise());

$promise = $connector->connect('google.com:80');
Expand All @@ -238,7 +256,9 @@ public function testConnectTwiceWithFailingSshListenerShouldRejectBothPromises()

$deferred = new Deferred();
$ref = new \ReflectionProperty($connector, 'listen');
$ref->setAccessible(true);
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$ref->setValue($connector, $deferred->promise());

$first = $connector->connect('google.com:80');
Expand All @@ -259,7 +279,9 @@ public function testConnectCancellationWithFailingSshListenerShouldAddTimerOnce(

$deferred = new Deferred();
$ref = new \ReflectionProperty($connector, 'listen');
$ref->setAccessible(true);
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$ref->setValue($connector, $deferred->promise());

$promise = $connector->connect('google.com:80');
Expand All @@ -275,15 +297,19 @@ public function testConnectWithSuccessfulSshListenerWillInvokeSocksConnector()
$connector = new SshSocksConnector('host', $loop);

$ref = new \ReflectionProperty($connector, 'listen');
$ref->setAccessible(true);
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$ref->setValue($connector, \React\Promise\resolve(null));

$deferred = new Deferred();
$socks = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$socks->expects($this->once())->method('connect')->with('google.com:80')->willReturn($deferred->promise());

$ref = new \ReflectionProperty($connector, 'socks');
$ref->setAccessible(true);
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$ref->setValue($connector, $socks);

$promise = $connector->connect('google.com:80');
Expand All @@ -297,7 +323,9 @@ public function testConnectCancellationWithSuccessfulSshListenerWillCancelSocksC
$connector = new SshSocksConnector('host', $loop);

$ref = new \ReflectionProperty($connector, 'listen');
$ref->setAccessible(true);
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$ref->setValue($connector, \React\Promise\resolve(null));

$deferred = new Deferred(function () {
Expand All @@ -307,7 +335,9 @@ public function testConnectCancellationWithSuccessfulSshListenerWillCancelSocksC
$socks->expects($this->once())->method('connect')->willReturn($deferred->promise());

$ref = new \ReflectionProperty($connector, 'socks');
$ref->setAccessible(true);
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$ref->setValue($connector, $socks);

$promise = $connector->connect('google.com:80');
Expand All @@ -330,15 +360,19 @@ public function testConnectWithSuccessfulSshListenerButFailingSocksConnectorShou
$connector = new SshSocksConnector('host', $loop);

$ref = new \ReflectionProperty($connector, 'listen');
$ref->setAccessible(true);
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$ref->setValue($connector, \React\Promise\resolve(null));

$deferred = new Deferred();
$socks = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$socks->expects($this->once())->method('connect')->willReturn($deferred->promise());

$ref = new \ReflectionProperty($connector, 'socks');
$ref->setAccessible(true);
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$ref->setValue($connector, $socks);

$promise = $connector->connect('google.com:80');
Expand All @@ -361,7 +395,9 @@ public function testConnectWithSuccessfulSshListenerAndSuccessfulSocksConnectorS
$connector = new SshSocksConnector('host', $loop);

$ref = new \ReflectionProperty($connector, 'listen');
$ref->setAccessible(true);
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$ref->setValue($connector, \React\Promise\resolve(null));

$connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock();
Expand All @@ -372,7 +408,9 @@ public function testConnectWithSuccessfulSshListenerAndSuccessfulSocksConnectorS
$socks->expects($this->once())->method('connect')->willReturn($deferred->promise());

$ref = new \ReflectionProperty($connector, 'socks');
$ref->setAccessible(true);
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$ref->setValue($connector, $socks);

$promise = $connector->connect('google.com:80');
Expand All @@ -388,7 +426,9 @@ public function testConnectWithSuccessfulSshListenerAndSuccessfulSocksConnectorW
$connector = new SshSocksConnector('host', $loop);

$ref = new \ReflectionProperty($connector, 'listen');
$ref->setAccessible(true);
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$ref->setValue($connector, \React\Promise\resolve(null));

$connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(array('close'))->getMock();
Expand All @@ -399,7 +439,9 @@ public function testConnectWithSuccessfulSshListenerAndSuccessfulSocksConnectorW
$socks->expects($this->once())->method('connect')->willReturn($deferred->promise());

$ref = new \ReflectionProperty($connector, 'socks');
$ref->setAccessible(true);
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$ref->setValue($connector, $socks);

$promise = $connector->connect('google.com:80');
Expand Down