From 32ff04c2ccf4e8682199e83f3d451d562730f49e Mon Sep 17 00:00:00 2001 From: Joe Testa Date: Wed, 1 Feb 2023 17:56:54 -0500 Subject: [PATCH] Added Tox testing for Python 3.11. Fixed flake8 & pylint errors. --- .github/workflows/tox.yaml | 2 +- src/ssh_audit/kexdh.py | 10 ++++++---- src/ssh_audit/ssh_audit.py | 2 +- src/ssh_audit/ssh_socket.py | 2 +- tox.ini | 28 ++++++++++++++-------------- 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/.github/workflows/tox.yaml b/.github/workflows/tox.yaml index 316cc3e..6c40f0c 100644 --- a/.github/workflows/tox.yaml +++ b/.github/workflows/tox.yaml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.7, 3.8, 3.9, "3.10"] + python-version: [3.7, 3.8, 3.9, "3.10", 3.11] steps: - uses: actions/checkout@v2 diff --git a/src/ssh_audit/kexdh.py b/src/ssh_audit/kexdh.py index 536f0a8..12edc9e 100644 --- a/src/ssh_audit/kexdh.py +++ b/src/ssh_audit/kexdh.py @@ -35,6 +35,10 @@ from ssh_audit.protocol import Protocol from ssh_audit.ssh_socket import SSH_Socket +class KexDHException(Exception): + pass + + class KexDH: # pragma: nocover def __init__(self, kex_name: str, hash_alg: str, g: int, p: int) -> None: self.__kex_name = kex_name # pylint: disable=unused-private-member @@ -79,8 +83,7 @@ class KexDH: # pragma: nocover packet_type, payload = s.read_packet(2) if packet_type != -1 and packet_type not in [Protocol.MSG_KEXDH_REPLY, Protocol.MSG_KEXDH_GEX_REPLY]: # pylint: disable=no-else-raise - # TODO: change Exception to something more specific. - raise Exception('Expected MSG_KEXDH_REPLY (%d) or MSG_KEXDH_GEX_REPLY (%d), but got %d instead.' % (Protocol.MSG_KEXDH_REPLY, Protocol.MSG_KEXDH_GEX_REPLY, packet_type)) + raise KexDHException('Expected MSG_KEXDH_REPLY (%d) or MSG_KEXDH_GEX_REPLY (%d), but got %d instead.' % (Protocol.MSG_KEXDH_REPLY, Protocol.MSG_KEXDH_GEX_REPLY, packet_type)) elif packet_type == -1: # A connection error occurred. We can't parse anything, so just # return. The host key modulus (and perhaps certificate modulus) @@ -328,8 +331,7 @@ class KexGroupExchange(KexDH): packet_type, payload = s.read_packet(2) if packet_type not in [Protocol.MSG_KEXDH_GEX_GROUP, Protocol.MSG_DEBUG]: - # TODO: replace with a better exception type. - raise Exception('Expected MSG_KEXDH_GEX_REPLY (%d), but got %d instead.' % (Protocol.MSG_KEXDH_GEX_REPLY, packet_type)) + raise KexDHException('Expected MSG_KEXDH_GEX_REPLY (%d), but got %d instead.' % (Protocol.MSG_KEXDH_GEX_REPLY, packet_type)) # Skip any & all MSG_DEBUG messages. while packet_type == Protocol.MSG_DEBUG: diff --git a/src/ssh_audit/ssh_audit.py b/src/ssh_audit/ssh_audit.py index 8be3d3e..ad8a410 100755 --- a/src/ssh_audit/ssh_audit.py +++ b/src/ssh_audit/ssh_audit.py @@ -182,7 +182,7 @@ def output_algorithm(out: OutputBuffer, alg_db: Dict[str, Dict[str, List[List[Op if out.verbose: f(prefix + alg_name + comment) elif text != '': - comment = (padding + ' `- [' + level + '] ' + text) + comment = padding + ' `- [' + level + '] ' + text f(' ' * len(prefix + alg_name) + comment) return program_retval diff --git a/src/ssh_audit/ssh_socket.py b/src/ssh_audit/ssh_socket.py index 566612c..99ccbd2 100644 --- a/src/ssh_audit/ssh_socket.py +++ b/src/ssh_audit/ssh_socket.py @@ -86,7 +86,7 @@ class SSH_Socket(ReadBuf, WriteBuf): # If the user has a preference for using IPv4 over IPv6 (or vice-versa), then sort the list returned by getaddrinfo() so that the preferred address type comes first. if len(self.__ip_version_preference) == 2: - r = sorted(r, key=lambda x: x[0], reverse=(self.__ip_version_preference[0] == 6)) + r = sorted(r, key=lambda x: x[0], reverse=(self.__ip_version_preference[0] == 6)) # pylint: disable=superfluous-parens for af, socktype, _proto, _canonname, addr in r: if socktype == socket.SOCK_STREAM: yield af, addr diff --git a/tox.ini b/tox.ini index 75a7d99..94651f8 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,7 @@ [tox] envlist = py{py3}-{test,pylint,flake8,vulture} - py{36,37,38,39,310}-{test,mypy,pylint,flake8,vulture} + py{37,38,39,310,311}-{test,mypy,pylint,flake8,vulture} cov skip_missing_interpreters = true @@ -9,11 +9,11 @@ skip_missing_interpreters = true deps = test: pytest test,cov: {[testenv:cov]deps} - test,py{36,37,38,39,310}-{type,mypy}: colorama - py{36,37,38,39,310}-{type,mypy}: {[testenv:mypy]deps} - py{py3,36,37,38,39,310}-{lint,pylint},lint: {[testenv:pylint]deps} - py{py3,36,37,38,39,310}-{lint,flake8},lint: {[testenv:flake8]deps} - py{py3,36,37,38,39,310}-{lint,vulture},lint: {[testenv:vulture]deps} + test,py{37,38,39,310,311}-{type,mypy}: colorama + py{37,38,39,310,311}-{type,mypy}: {[testenv:mypy]deps} + py{py3,37,38,39,310,311}-{lint,pylint},lint: {[testenv:pylint]deps} + py{py3,37,38,39,310,311}-{lint,flake8},lint: {[testenv:flake8]deps} + py{py3,37,38,39,310,311}-{lint,vulture},lint: {[testenv:vulture]deps} setenv = SSHAUDIT = {toxinidir}/src test: COVERAGE_FILE = {toxinidir}/.coverage.{envname} @@ -25,10 +25,10 @@ commands = test: coverage combine test: coverage report --show-missing test: coverage html -d {toxinidir}/reports/html/coverage.{envname} - py{36,37,38,39,310}-{type,mypy}: {[testenv:mypy]commands} - py{py3,36,37,38,39,310}-{lint,pylint},lint: {[testenv:pylint]commands} - py{py3,36,37,38,39,310}-{lint,flake8},lint: {[testenv:flake8]commands} - py{py3,36,37,38,39,310}-{lint,vulture},lint: {[testenv:vulture]commands} + py{37,38,39,310,311}-{type,mypy}: {[testenv:mypy]commands} + py{py3,37,38,39,310,311}-{lint,pylint},lint: {[testenv:pylint]commands} + py{py3,37,38,39,310,311}-{lint,flake8},lint: {[testenv:flake8]commands} + py{py3,37,38,39,310,311}-{lint,vulture},lint: {[testenv:vulture]commands} #ignore_outcome = # type: true # lint: true @@ -125,10 +125,10 @@ ignore-long-lines = ^\s*(#\s+type:\s+.*|[A-Z0-9_]+\s+=\s+.*|('.*':\s+)?\[.*\],?| max-module-lines = 2500 [flake8] -ignore = - E241, # multiple spaces after operator; should be kept for tabular data - E303, # too many blank lines - E501, # line too long +# E241 = multiple spaces after operator; should be kept for tabular data +# E303 = too many blank lines +# E501 = line too long +ignore = E241, E303, E501 [pytest] junit_family = xunit1