diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 17:07:52 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 17:07:52 +0000 |
commit | f0f453c916e279980df981c1e1dee0d167dc124e (patch) | |
tree | d09973c9f173820ade2dc814467d3e57df8a042d /test/test_socket.py | |
parent | Initial commit. (diff) | |
download | ssh-audit-f0f453c916e279980df981c1e1dee0d167dc124e.tar.xz ssh-audit-f0f453c916e279980df981c1e1dee0d167dc124e.zip |
Adding upstream version 3.1.0.upstream/3.1.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | test/test_socket.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/test/test_socket.py b/test/test_socket.py new file mode 100644 index 0000000..9569768 --- /dev/null +++ b/test/test_socket.py @@ -0,0 +1,42 @@ +import pytest + +from ssh_audit.outputbuffer import OutputBuffer +from ssh_audit.ssh_socket import SSH_Socket + + +# pylint: disable=attribute-defined-outside-init +class TestSocket: + @pytest.fixture(autouse=True) + def init(self, ssh_audit): + self.OutputBuffer = OutputBuffer + self.ssh_socket = SSH_Socket + + def test_invalid_host(self, virtual_socket): + with pytest.raises(ValueError): + self.ssh_socket(self.OutputBuffer(), None, 22) + + def test_invalid_port(self, virtual_socket): + with pytest.raises(ValueError): + self.ssh_socket(self.OutputBuffer(), 'localhost', 'abc') + with pytest.raises(ValueError): + self.ssh_socket(self.OutputBuffer(), 'localhost', -1) + with pytest.raises(ValueError): + self.ssh_socket(self.OutputBuffer(), 'localhost', 0) + with pytest.raises(ValueError): + self.ssh_socket(self.OutputBuffer(), 'localhost', 65536) + + def test_not_connected_socket(self, virtual_socket): + sock = self.ssh_socket(self.OutputBuffer(), 'localhost', 22) + 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' |