2016-11-03 18:10:49 +01:00
|
|
|
import pytest
|
|
|
|
|
2020-10-15 20:34:23 +02:00
|
|
|
from ssh_audit.ssh_socket import SSH_Socket
|
|
|
|
|
2016-11-03 18:10:49 +01:00
|
|
|
|
|
|
|
# pylint: disable=attribute-defined-outside-init
|
2020-06-15 23:05:31 +02:00
|
|
|
class TestSocket:
|
2020-06-13 03:01:10 +02:00
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
def init(self, ssh_audit):
|
2020-10-15 20:34:23 +02:00
|
|
|
self.ssh_socket = SSH_Socket
|
2020-06-09 23:54:07 +02:00
|
|
|
|
2020-06-13 03:01:10 +02:00
|
|
|
def test_invalid_host(self, virtual_socket):
|
|
|
|
with pytest.raises(ValueError):
|
2020-10-15 20:34:23 +02:00
|
|
|
self.ssh_socket(None, 22)
|
2020-06-09 23:54:07 +02:00
|
|
|
|
2020-06-13 03:01:10 +02:00
|
|
|
def test_invalid_port(self, virtual_socket):
|
|
|
|
with pytest.raises(ValueError):
|
2020-10-15 20:34:23 +02:00
|
|
|
self.ssh_socket('localhost', 'abc')
|
2020-06-13 03:01:10 +02:00
|
|
|
with pytest.raises(ValueError):
|
2020-10-15 20:34:23 +02:00
|
|
|
self.ssh_socket('localhost', -1)
|
2020-06-13 03:01:10 +02:00
|
|
|
with pytest.raises(ValueError):
|
2020-10-15 20:34:23 +02:00
|
|
|
self.ssh_socket('localhost', 0)
|
2020-06-13 03:01:10 +02:00
|
|
|
with pytest.raises(ValueError):
|
2020-10-15 20:34:23 +02:00
|
|
|
self.ssh_socket('localhost', 65536)
|
2020-06-09 23:54:07 +02:00
|
|
|
|
2020-06-13 03:01:10 +02:00
|
|
|
def test_not_connected_socket(self, virtual_socket):
|
2020-10-15 20:34:23 +02:00
|
|
|
sock = self.ssh_socket('localhost', 22)
|
2020-06-13 03:01:10 +02:00
|
|
|
banner, header, err = sock.get_banner()
|
|
|
|
assert banner is None
|
|
|
|
assert len(header) == 0
|
|
|
|
assert err == 'not connected'
|
|
|
|
s, e = sock.recv()
|
|
|
|
assert s == -1
|
|
|
|
assert e == 'not connected'
|
|
|
|
s, e = sock.send('nothing')
|
|
|
|
assert s == -1
|
|
|
|
assert e == 'not connected'
|
|
|
|
s, e = sock.send_packet()
|
|
|
|
assert s == -1
|
|
|
|
assert e == 'not connected'
|