diff --git a/ssh-audit.py b/ssh-audit.py index 2b52ad7..c1dfaf2 100755 --- a/ssh-audit.py +++ b/ssh-audit.py @@ -1905,6 +1905,6 @@ def audit(aconf, sshv=None): utils = Utils() out = Output() -if __name__ == '__main__': +if __name__ == '__main__': # pragma: nocover conf = AuditConf.from_cmdline(sys.argv[1:], usage) audit(conf) diff --git a/test/test_auditconf.py b/test/test_auditconf.py index b4f42f4..6c23c2a 100644 --- a/test/test_auditconf.py +++ b/test/test_auditconf.py @@ -3,13 +3,15 @@ import pytest +# pylint: disable=attribute-defined-outside-init class TestAuditConf(object): @pytest.fixture(autouse=True) def init(self, ssh_audit): self.AuditConf = ssh_audit.AuditConf self.usage = ssh_audit.usage - def _test_conf(self, conf, **kwargs): + @classmethod + def _test_conf(cls, conf, **kwargs): options = { 'host': None, 'port': 22, @@ -66,7 +68,7 @@ class TestAuditConf(object): excinfo.match(r'.*invalid level.*') def test_audit_conf_cmdline(self): - c = lambda x: self.AuditConf.from_cmdline(x.split(), self.usage) + c = lambda x: self.AuditConf.from_cmdline(x.split(), self.usage) # noqa with pytest.raises(SystemExit): conf = c('') with pytest.raises(SystemExit): diff --git a/test/test_banner.py b/test/test_banner.py index b2d9991..ca93a53 100644 --- a/test/test_banner.py +++ b/test/test_banner.py @@ -3,13 +3,14 @@ import pytest +# pylint: disable=line-too-long,attribute-defined-outside-init class TestBanner(object): @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) + 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' @@ -27,12 +28,12 @@ class TestBanner(object): assert str(b) == 'SSH-1.5-Cisco-1.25' def test_invalid_banners(self): - b = lambda x: self.ssh.Banner.parse(x) + 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) + 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 @@ -43,7 +44,7 @@ class TestBanner(object): 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) + 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 @@ -54,13 +55,13 @@ class TestBanner(object): assert str(b('SSH-2.0-')) == 'SSH-2.0-' def test_banners_with_comments(self): - b = lambda x: self.ssh.Banner.parse(x) + b = lambda x: self.ssh.Banner.parse(x) # noqa assert repr(b('SSH-2.0-OpenSSH_7.2p2 Ubuntu-1')) == '' assert repr(b('SSH-1.99-OpenSSH_3.4p1 Debian 1:3.4p1-1.woody.3')) == '' assert repr(b('SSH-1.5-1.3.7 F-SECURE SSH')) == '' def test_banners_with_multiple_protocols(self): - b = lambda x: self.ssh.Banner.parse(x) + 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' diff --git a/test/test_buffer.py b/test/test_buffer.py index e0be311..1e457bc 100644 --- a/test/test_buffer.py +++ b/test/test_buffer.py @@ -1,9 +1,10 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -import pytest import re +import pytest +# pylint: disable=attribute-defined-outside-init,bad-whitespace class TestBuffer(object): @pytest.fixture(autouse=True) def init(self, ssh_audit): @@ -11,7 +12,8 @@ class TestBuffer(object): self.wbuf = ssh_audit.WriteBuf self.utf8rchar = b'\xef\xbf\xbd' - def _b(self, v): + @classmethod + def _b(cls, v): v = re.sub(r'\s', '', v) data = [int(v[i * 2:i * 2 + 2], 16) for i in range(len(v) // 2)] return bytes(bytearray(data)) @@ -26,8 +28,8 @@ class TestBuffer(object): assert r.unread_len == 0 def test_byte(self): - w = lambda x: self.wbuf().write_byte(x).write_flush() - r = lambda x: self.rbuf(x).read_byte() + w = lambda x: self.wbuf().write_byte(x).write_flush() # noqa + r = lambda x: self.rbuf(x).read_byte() # noqa tc = [(0x00, '00'), (0x01, '01'), (0x10, '10'), @@ -37,8 +39,8 @@ class TestBuffer(object): assert r(self._b(p[1])) == p[0] def test_bool(self): - w = lambda x: self.wbuf().write_bool(x).write_flush() - r = lambda x: self.rbuf(x).read_bool() + w = lambda x: self.wbuf().write_bool(x).write_flush() # noqa + r = lambda x: self.rbuf(x).read_bool() # noqa tc = [(True, '01'), (False, '00')] for p in tc: @@ -46,8 +48,8 @@ class TestBuffer(object): assert r(self._b(p[1])) == p[0] def test_int(self): - w = lambda x: self.wbuf().write_int(x).write_flush() - r = lambda x: self.rbuf(x).read_int() + w = lambda x: self.wbuf().write_int(x).write_flush() # noqa + r = lambda x: self.rbuf(x).read_int() # noqa tc = [(0x00, '00 00 00 00'), (0x01, '00 00 00 01'), (0xabcd, '00 00 ab cd'), @@ -57,8 +59,8 @@ class TestBuffer(object): assert r(self._b(p[1])) == p[0] def test_string(self): - w = lambda x: self.wbuf().write_string(x).write_flush() - r = lambda x: self.rbuf(x).read_string() + w = lambda x: self.wbuf().write_string(x).write_flush() # noqa + r = lambda x: self.rbuf(x).read_string() # noqa tc = [(u'abc1', '00 00 00 04 61 62 63 31'), (b'abc2', '00 00 00 04 61 62 63 32')] for p in tc: @@ -69,34 +71,35 @@ class TestBuffer(object): assert r(self._b(p[1])) == v def test_list(self): - w = lambda x: self.wbuf().write_list(x).write_flush() - r = lambda x: self.rbuf(x).read_list() + w = lambda x: self.wbuf().write_list(x).write_flush() # noqa + r = lambda x: self.rbuf(x).read_list() # noqa tc = [(['d', 'ef', 'ault'], '00 00 00 09 64 2c 65 66 2c 61 75 6c 74')] for p in tc: assert w(p[0]) == self._b(p[1]) assert r(self._b(p[1])) == p[0] def test_list_nonutf8(self): - r = lambda x: self.rbuf(x).read_list() + r = lambda x: self.rbuf(x).read_list() # noqa src = self._b('00 00 00 04 de ad be ef') dst = [(b'\xde\xad' + self.utf8rchar + self.utf8rchar).decode('utf-8')] assert r(src) == dst def test_line(self): - w = lambda x: self.wbuf().write_line(x).write_flush() - r = lambda x: self.rbuf(x).read_line() + w = lambda x: self.wbuf().write_line(x).write_flush() # noqa + r = lambda x: self.rbuf(x).read_line() # noqa tc = [(u'example line', '65 78 61 6d 70 6c 65 20 6c 69 6e 65 0d 0a')] for p in tc: assert w(p[0]) == self._b(p[1]) assert r(self._b(p[1])) == p[0] def test_line_nonutf8(self): - r = lambda x: self.rbuf(x).read_line() + r = lambda x: self.rbuf(x).read_line() # noqa src = self._b('de ad be af') dst = (b'\xde\xad' + self.utf8rchar + self.utf8rchar).decode('utf-8') assert r(src) == dst def test_bitlen(self): + # pylint: disable=protected-access class Py26Int(int): def bit_length(self): raise AttributeError @@ -104,8 +107,8 @@ class TestBuffer(object): assert self.wbuf._bitlength(Py26Int(42)) == 6 def test_mpint1(self): - mpint1w = lambda x: self.wbuf().write_mpint1(x).write_flush() - mpint1r = lambda x: self.rbuf(x).read_mpint1() + mpint1w = lambda x: self.wbuf().write_mpint1(x).write_flush() # noqa + mpint1r = lambda x: self.rbuf(x).read_mpint1() # noqa tc = [(0x0, '00 00'), (0x1234, '00 0d 12 34'), (0x12345, '00 11 01 23 45'), @@ -115,8 +118,8 @@ class TestBuffer(object): assert mpint1r(self._b(p[1])) == p[0] def test_mpint2(self): - mpint2w = lambda x: self.wbuf().write_mpint2(x).write_flush() - mpint2r = lambda x: self.rbuf(x).read_mpint2() + mpint2w = lambda x: self.wbuf().write_mpint2(x).write_flush() # noqa + mpint2r = lambda x: self.rbuf(x).read_mpint2() # noqa tc = [(0x0, '00 00 00 00'), (0x80, '00 00 00 02 00 80'), (0x9a378f9b2e332a7, '00 00 00 08 09 a3 78 f9 b2 e3 32 a7'), diff --git a/test/test_errors.py b/test/test_errors.py index abdbebe..ad35a54 100644 --- a/test/test_errors.py +++ b/test/test_errors.py @@ -1,8 +1,10 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -import pytest, socket +import socket +import pytest +# pylint: disable=attribute-defined-outside-init class TestErrors(object): @pytest.fixture(autouse=True) def init(self, ssh_audit): diff --git a/test/test_output.py b/test/test_output.py index a50de38..74b2c19 100644 --- a/test/test_output.py +++ b/test/test_output.py @@ -1,9 +1,10 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import print_function -import pytest, io, sys +import pytest +# pylint: disable=attribute-defined-outside-init class TestOutput(object): @pytest.fixture(autouse=True) def init(self, ssh_audit): @@ -23,7 +24,7 @@ class TestOutput(object): def test_output_buffer_no_flush(self, output_spy): output_spy.begin() - with self.OutputBuffer() as obuf: + with self.OutputBuffer(): print(u'abc') assert output_spy.flush() == [] diff --git a/test/test_software.py b/test/test_software.py index 20eca18..4b7ca75 100644 --- a/test/test_software.py +++ b/test/test_software.py @@ -3,19 +3,21 @@ import pytest +# pylint: disable=line-too-long,attribute-defined-outside-init class TestSoftware(object): @pytest.fixture(autouse=True) def init(self, ssh_audit): self.ssh = ssh_audit.SSH def test_unknown_software(self): - ps = lambda x: self.ssh.Software.parse(self.ssh.Banner.parse(x)) + ps = lambda x: self.ssh.Software.parse(self.ssh.Banner.parse(x)) # noqa assert ps('SSH-1.5') is None assert ps('SSH-1.99-AlfaMegaServer') is None assert ps('SSH-2.0-BetaMegaServer 0.0.1') is None def test_openssh_software(self): - ps = lambda x: self.ssh.Software.parse(self.ssh.Banner.parse(x)) + # pylint: disable=too-many-statements + ps = lambda x: self.ssh.Software.parse(self.ssh.Banner.parse(x)) # noqa # common s = ps('SSH-2.0-OpenSSH_7.3') assert s.vendor is None @@ -102,7 +104,7 @@ class TestSoftware(object): assert repr(s) == '' def test_dropbear_software(self): - ps = lambda x: self.ssh.Software.parse(self.ssh.Banner.parse(x)) + ps = lambda x: self.ssh.Software.parse(self.ssh.Banner.parse(x)) # noqa # common s = ps('SSH-2.0-dropbear_2016.74') assert s.vendor is None @@ -153,7 +155,7 @@ class TestSoftware(object): assert repr(s) == '' def test_libssh_software(self): - ps = lambda x: self.ssh.Software.parse(self.ssh.Banner.parse(x)) + ps = lambda x: self.ssh.Software.parse(self.ssh.Banner.parse(x)) # noqa # common s = ps('SSH-2.0-libssh-0.2') assert s.vendor is None @@ -179,7 +181,7 @@ class TestSoftware(object): assert repr(s) == '' def test_romsshell_software(self): - ps = lambda x: self.ssh.Software.parse(self.ssh.Banner.parse(x)) + ps = lambda x: self.ssh.Software.parse(self.ssh.Banner.parse(x)) # noqa # common s = ps('SSH-2.0-RomSShell_5.40') assert s.vendor == 'Allegro Software' @@ -194,7 +196,7 @@ class TestSoftware(object): assert repr(s) == '' def test_hp_ilo_software(self): - ps = lambda x: self.ssh.Software.parse(self.ssh.Banner.parse(x)) + ps = lambda x: self.ssh.Software.parse(self.ssh.Banner.parse(x)) # noqa # common s = ps('SSH-2.0-mpSSH_0.2.1') assert s.vendor == 'HP' @@ -209,7 +211,7 @@ class TestSoftware(object): assert repr(s) == '' def test_cisco_software(self): - ps = lambda x: self.ssh.Software.parse(self.ssh.Banner.parse(x)) + ps = lambda x: self.ssh.Software.parse(self.ssh.Banner.parse(x)) # noqa # common s = ps('SSH-1.5-Cisco-1.25') assert s.vendor == 'Cisco' @@ -224,7 +226,7 @@ class TestSoftware(object): assert repr(s) == '' def test_sofware_os(self): - ps = lambda x: self.ssh.Software.parse(self.ssh.Banner.parse(x)) + ps = lambda x: self.ssh.Software.parse(self.ssh.Banner.parse(x)) # noqa # unknown s = ps('SSH-2.0-OpenSSH_3.7.1 MegaOperatingSystem 123') assert s.os is None diff --git a/test/test_version_compare.py b/test/test_version_compare.py index 2f74310..d3f8554 100644 --- a/test/test_version_compare.py +++ b/test/test_version_compare.py @@ -3,6 +3,7 @@ import pytest +# pylint: disable=attribute-defined-outside-init class TestVersionCompare(object): @pytest.fixture(autouse=True) def init(self, ssh_audit):