mirror of
https://github.com/jtesta/ssh-audit.git
synced 2024-11-22 02:21:40 +01:00
ec1dda8d7f
* Remove mypy job for Python 2 modified: tox.ini * Remove Python 2 compatibility import modified: ssh-audit.py * Remove compatibility import for BytesIO and StringIO This is no longer necessary, as support for Python 2 was dropped. modified: ssh-audit.py * Remove `text-type` compatibility layer ... as support for Python 2 was dropped already. modified: ssh-audit.py * Remove `binary-type` compatibility layer ... as support for Python 2 was dropped already. modified: ssh-audit.py * Remove try-except block for typing ... as since Python 3.5 it is included in the standard library. modified: ssh-audit.py * Move typing import to top of module modified: ssh-audit.py * Remove obsolete encoding declaration modified: ssh-audit.py * Apply pyupgrade on ssh-audit.py pyupgrade is a tool which updates Python code to modern syntax modified: ssh-audit.py * Remove Python 2 compatibility from conftest.py modified: test/conftest.py * Remove Python 2 compatibility from test_auditconf.py modified: test/test_auditconf.py * Remove Python 2 compatibility from test_banner.py modified: test/test_banner.py * Remove Python 2 compatibility from test_buffer.py modified: test/test_buffer.py * Remove Python 2 compatibility from test_errors.py modified: test/test_errors.py * Remove Python 2 compatibility from test_output.py modified: test/test_output.py * Remove Python 2 compatibility from test_resolve.py modified: test/test_resolve.py * Remove Python 2 compatibility from test_socket.py modified: test/test_socket.py * Remove Python 2 compatibility from test_software.py modified: test/test_software.py * Remove Python 2 compatibility from test_ssh_algorithm.py modified: test/test_ssh_algorithm.py * Remove Python 2 compatibility from test_ssh1.py modified: test/test_ssh1.py * Remove Python 2 compatibility from test_ssh2.py modified: test/test_ssh2.py * Remove Python 2 compatibility and Py2 only tests ... from test_utils.py. modified: test/test_utils.py * Remove Python 2 compatibility from test_version_compare.py modified: test/test_version_compare.py * Remove Python 2 job from appveyor config This was done blindly, as it is unclear whether appveyor runs at all. modified: .appveyor.yml
68 lines
3.3 KiB
Python
68 lines
3.3 KiB
Python
import pytest
|
|
|
|
|
|
# pylint: disable=line-too-long,attribute-defined-outside-init
|
|
class TestBanner:
|
|
@pytest.fixture(autouse=True)
|
|
def init(self, ssh_audit):
|
|
self.ssh = ssh_audit.SSH
|
|
|
|
def test_simple_banners(self):
|
|
banner = lambda x: self.ssh.Banner.parse(x) # noqa
|
|
b = banner('SSH-2.0-OpenSSH_7.3')
|
|
assert b.protocol == (2, 0)
|
|
assert b.software == 'OpenSSH_7.3'
|
|
assert b.comments is None
|
|
assert str(b) == 'SSH-2.0-OpenSSH_7.3'
|
|
b = banner('SSH-1.99-Sun_SSH_1.1.3')
|
|
assert b.protocol == (1, 99)
|
|
assert b.software == 'Sun_SSH_1.1.3'
|
|
assert b.comments is None
|
|
assert str(b) == 'SSH-1.99-Sun_SSH_1.1.3'
|
|
b = banner('SSH-1.5-Cisco-1.25')
|
|
assert b.protocol == (1, 5)
|
|
assert b.software == 'Cisco-1.25'
|
|
assert b.comments is None
|
|
assert str(b) == 'SSH-1.5-Cisco-1.25'
|
|
|
|
def test_invalid_banners(self):
|
|
b = lambda x: self.ssh.Banner.parse(x) # noqa
|
|
assert b('Something') is None
|
|
assert b('SSH-XXX-OpenSSH_7.3') is None
|
|
|
|
def test_banners_with_spaces(self):
|
|
b = lambda x: self.ssh.Banner.parse(x) # noqa
|
|
s = 'SSH-2.0-OpenSSH_4.3p2'
|
|
assert str(b('SSH-2.0-OpenSSH_4.3p2 ')) == s
|
|
assert str(b('SSH-2.0- OpenSSH_4.3p2')) == s
|
|
assert str(b('SSH-2.0- OpenSSH_4.3p2 ')) == s
|
|
s = 'SSH-2.0-OpenSSH_4.3p2 Debian-9etch3 on i686-pc-linux-gnu'
|
|
assert str(b('SSH-2.0- OpenSSH_4.3p2 Debian-9etch3 on i686-pc-linux-gnu')) == s
|
|
assert str(b('SSH-2.0-OpenSSH_4.3p2 Debian-9etch3 on i686-pc-linux-gnu ')) == s
|
|
assert str(b('SSH-2.0- OpenSSH_4.3p2 Debian-9etch3 on i686-pc-linux-gnu ')) == s
|
|
|
|
def test_banners_without_software(self):
|
|
b = lambda x: self.ssh.Banner.parse(x) # noqa
|
|
assert b('SSH-2.0').protocol == (2, 0)
|
|
assert b('SSH-2.0').software is None
|
|
assert b('SSH-2.0').comments is None
|
|
assert str(b('SSH-2.0')) == 'SSH-2.0'
|
|
assert b('SSH-2.0-').protocol == (2, 0)
|
|
assert b('SSH-2.0-').software == ''
|
|
assert b('SSH-2.0-').comments is None
|
|
assert str(b('SSH-2.0-')) == 'SSH-2.0-'
|
|
|
|
def test_banners_with_comments(self):
|
|
b = lambda x: self.ssh.Banner.parse(x) # noqa
|
|
assert repr(b('SSH-2.0-OpenSSH_7.2p2 Ubuntu-1')) == '<Banner(protocol=2.0, software=OpenSSH_7.2p2, comments=Ubuntu-1)>'
|
|
assert repr(b('SSH-1.99-OpenSSH_3.4p1 Debian 1:3.4p1-1.woody.3')) == '<Banner(protocol=1.99, software=OpenSSH_3.4p1, comments=Debian 1:3.4p1-1.woody.3)>'
|
|
assert repr(b('SSH-1.5-1.3.7 F-SECURE SSH')) == '<Banner(protocol=1.5, software=1.3.7, comments=F-SECURE SSH)>'
|
|
|
|
def test_banners_with_multiple_protocols(self):
|
|
b = lambda x: self.ssh.Banner.parse(x) # noqa
|
|
assert str(b('SSH-1.99-SSH-1.99-OpenSSH_3.6.1p2')) == 'SSH-1.99-OpenSSH_3.6.1p2'
|
|
assert str(b('SSH-2.0-SSH-2.0-OpenSSH_4.3p2 Debian-9')) == 'SSH-2.0-OpenSSH_4.3p2 Debian-9'
|
|
assert str(b('SSH-1.99-SSH-2.0-dropbear_0.5')) == 'SSH-1.99-dropbear_0.5'
|
|
assert str(b('SSH-2.0-SSH-1.99-OpenSSH_4.2p1 SSH Secure Shell (non-commercial)')) == 'SSH-1.99-OpenSSH_4.2p1 SSH Secure Shell (non-commercial)'
|
|
assert str(b('SSH-1.99-SSH-1.99-SSH-1.99-OpenSSH_3.9p1')) == 'SSH-1.99-OpenSSH_3.9p1'
|