Repository navigation
Expand file tree
/
Copy pathIntegrationSshProcessConnectorTest.php
More file actions
112 lines (84 loc) · 3.89 KB
/
Copy pathIntegrationSshProcessConnectorTest.php
File metadata and controls
112 lines (84 loc) · 3.89 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?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');
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');
$promise->then($this->expectCallableOnceWith($this->isInstanceOf('React\Socket\ConnectionInterface')));
Loop::run();
}
public function testConnectWillRejectWithExceptionWhenProcessOutputsChannelOpenFailedMessage()
{
$connector = new SshProcessConnector('host');
$ref = new \ReflectionProperty($connector, 'cmd');
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');
$promise->then(null, $this->expectCallableOnceWith($this->isInstanceOf('RuntimeException')));
Loop::run();
}
public function testConnectWillRejectWithExceptionWhenProcessOutputsEndsWithoutChannelMessage()
{
$connector = new SshProcessConnector('host');
$ref = new \ReflectionProperty($connector, 'cmd');
if (PHP_VERSION_ID < 80100) {
$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 testConnectCancellationWillRejectWithException()
{
$connector = new SshProcessConnector('host');
$ref = new \ReflectionProperty($connector, 'cmd');
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$ref->setValue($connector, 'exec sleep 10; #');
$promise = $connector->connect('example.com:80');
$promise->cancel();
$promise->then(null, $this->expectCallableOnceWith($this->isInstanceOf('RuntimeException')));
Loop::run();
}
public function testConnectWillRejectWithExceptionAndTerminateProcessWhenProcessOutputsLineExceedingMaximumBufferSize()
{
$connector = new SshProcessConnector('host');
$ref = new \ReflectionProperty($connector, 'cmd');
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$ref->setValue($connector, 'head -c 70000 /dev/zero | tr "\0" a >&2; exec sleep 10; #');
$promise = $connector->connect('example.com:80');
$this->setExpectedException('RuntimeException', 'Connection to example.com:80 failed because SSH client died (Buffer size exceeded)');
\React\Async\await($promise);
}
public function testConnectWillResolveWithConnectionThatWillEmitImmediateDataFromProcessStdoutAfterChannelOpenConfirmMessage()
{
$connector = new SshProcessConnector('host');
$ref = new \ReflectionProperty($connector, 'cmd');
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');
$data = $this->expectCallableOnceWith("foo\n");
$promise->then(function (ConnectionInterface $connection) use ($data) {
$connection->on('data', $data);
});
Loop::run();
}
}