Tests/SSH2: add more expansive unit test

This commit is contained in:
terrafrost 2023-04-14 19:11:32 -05:00
parent 184a984e97
commit 06f45881f9

View File

@ -542,4 +542,21 @@ class SSH2Test extends PhpseclibFunctionalTestCase
'Failed asserting that exec channel identifier is maintained as last opened channel.'
);
}
public function testReadingOfClosedChannel()
{
$ssh = $this->getSSH2Login();
$this->assertSame(0, $ssh->getOpenChannelCount());
$ssh->enablePTY();
$ssh->exec('ping -c 3 127.0.0.1; exit');
$ssh->write("ping 127.0.0.2\n", SSH2::CHANNEL_SHELL);
$ssh->setTimeout(3);
$output = $ssh->read('', SSH2::READ_SIMPLE, SSH2::CHANNEL_SHELL);
$this->assertStringContainsString('PING 127.0.0.2', $output);
$output = $ssh->read('', SSH2::READ_SIMPLE, SSH2::CHANNEL_EXEC);
$this->assertStringContainsString('PING 127.0.0.1', $output);
$this->assertSame(1, $ssh->getOpenChannelCount());
$ssh->reset(SSH2::CHANNEL_SHELL);
$this->assertSame(0, $ssh->getOpenChannelCount());
}
}