forked from clue/reactphp-ssh-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntegrationSshProcessConnectorTest.php
More file actions
70 lines (51 loc) · 2.48 KB
/
IntegrationSshProcessConnectorTest.php
File metadata and controls
70 lines (51 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace Clue\Tests\React\SshProxy;
use Clue\React\SshProxy\SshProcessConnector;
use React\EventLoop\Loop;
use React\Socket\ConnectionInterface;
class IntegrationSshProcessConnectorTest extends TestCase
{
public function testConnectWillResolveWithConnectionInterfaceWhenProcessOutputsChannelOpenConfirmMessage()
{
$connector = new SshProcessConnector('host');
$ref = new \ReflectionProperty($connector, 'cmd');
$ref->setAccessible(true);
$ref->setValue($connector, 'echo "debug2: channel 0: open confirm rwindow 2097152 rmax 32768" >&2; #');
$promise = $connector->connect('example.com:80');
$promise->then($this->expectCallableOnceWith($this->isInstanceOf('React\Socket\ConnectionInterface')));
Loop::run();
}
public function testConnectWillRejectWithExceptionWhenProcessOutputsChannelOpenFailedMessage()
{
$connector = new SshProcessConnector('host');
$ref = new \ReflectionProperty($connector, 'cmd');
$ref->setAccessible(true);
$ref->setValue($connector, 'echo "channel 0: open failed: administratively prohibited: open failed" >&2; #');
$promise = $connector->connect('example.com:80');
$promise->then(null, $this->expectCallableOnceWith($this->isInstanceOf('RuntimeException')));
Loop::run();
}
public function testConnectWillRejectWithExceptionWhenProcessOutputsEndsWithoutChannelMessage()
{
$connector = new SshProcessConnector('host');
$ref = new \ReflectionProperty($connector, 'cmd');
$ref->setAccessible(true);
$ref->setValue($connector, 'echo foo >&2; #');
$promise = $connector->connect('example.com:80');
$promise->then(null, $this->expectCallableOnceWith($this->isInstanceOf('RuntimeException')));
Loop::run();
}
public function testConnectWillResolveWithConnectionThatWillEmitImmediateDataFromProcessStdoutAfterChannelOpenConfirmMessage()
{
$connector = new SshProcessConnector('host');
$ref = new \ReflectionProperty($connector, 'cmd');
$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');
$data = $this->expectCallableOnceWith("foo\n");
$promise->then(function (ConnectionInterface $connection) use ($data) {
$connection->on('data', $data);
});
Loop::run();
}
}