mirror of
https://github.com/jtesta/ssh-audit.git
synced 2025-07-05 05:22:48 -05:00
Remove some more Python 2 leftovers (#37)
* 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
This commit is contained in:
@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
import io
|
||||
import sys
|
||||
@ -7,13 +5,6 @@ import socket
|
||||
import pytest
|
||||
|
||||
|
||||
if sys.version_info[0] == 2:
|
||||
import StringIO # pylint: disable=import-error
|
||||
StringIO = StringIO.StringIO
|
||||
else:
|
||||
StringIO = io.StringIO
|
||||
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
def ssh_audit():
|
||||
__rdir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')
|
||||
@ -24,7 +15,7 @@ def ssh_audit():
|
||||
# pylint: disable=attribute-defined-outside-init
|
||||
class _OutputSpy(list):
|
||||
def begin(self):
|
||||
self.__out = StringIO()
|
||||
self.__out = io.StringIO()
|
||||
self.__old_stdout = sys.stdout
|
||||
sys.stdout = self.__out
|
||||
|
||||
@ -40,7 +31,7 @@ def output_spy():
|
||||
return _OutputSpy()
|
||||
|
||||
|
||||
class _VirtualGlobalSocket(object):
|
||||
class _VirtualGlobalSocket:
|
||||
def __init__(self, vsocket):
|
||||
self.vsocket = vsocket
|
||||
self.addrinfodata = {}
|
||||
@ -59,7 +50,7 @@ class _VirtualGlobalSocket(object):
|
||||
return self.vsocket
|
||||
|
||||
def getaddrinfo(self, host, port, family=0, socktype=0, proto=0, flags=0):
|
||||
key = '{0}#{1}'.format(host, port)
|
||||
key = '{}#{}'.format(host, port)
|
||||
if key in self.addrinfodata:
|
||||
data = self.addrinfodata[key]
|
||||
if isinstance(data, Exception):
|
||||
@ -75,7 +66,7 @@ class _VirtualGlobalSocket(object):
|
||||
return []
|
||||
|
||||
|
||||
class _VirtualSocket(object):
|
||||
class _VirtualSocket:
|
||||
def __init__(self):
|
||||
self.sock_address = ('127.0.0.1', 0)
|
||||
self.peer_address = None
|
||||
@ -108,7 +99,7 @@ class _VirtualSocket(object):
|
||||
|
||||
def getpeername(self):
|
||||
if self.peer_address is None or not self._connected:
|
||||
raise socket.error(57, 'Socket is not connected')
|
||||
raise OSError(57, 'Socket is not connected')
|
||||
return self.peer_address
|
||||
|
||||
def getsockname(self):
|
||||
@ -131,7 +122,7 @@ class _VirtualSocket(object):
|
||||
def recv(self, bufsize, flags=0):
|
||||
# pylint: disable=unused-argument
|
||||
if not self._connected:
|
||||
raise socket.error(54, 'Connection reset by peer')
|
||||
raise OSError(54, 'Connection reset by peer')
|
||||
if not len(self.rdata) > 0:
|
||||
return b''
|
||||
data = self.rdata.pop(0)
|
||||
@ -141,7 +132,7 @@ class _VirtualSocket(object):
|
||||
|
||||
def send(self, data):
|
||||
if self.peer_address is None or not self._connected:
|
||||
raise socket.error(32, 'Broken pipe')
|
||||
raise OSError(32, 'Broken pipe')
|
||||
self._check_err('send')
|
||||
self.sdata.append(data)
|
||||
|
||||
|
@ -1,10 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
import pytest
|
||||
|
||||
|
||||
# pylint: disable=attribute-defined-outside-init
|
||||
class TestAuditConf(object):
|
||||
class TestAuditConf:
|
||||
@pytest.fixture(autouse=True)
|
||||
def init(self, ssh_audit):
|
||||
self.AuditConf = ssh_audit.AuditConf
|
||||
|
@ -1,10 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
import pytest
|
||||
|
||||
|
||||
# pylint: disable=line-too-long,attribute-defined-outside-init
|
||||
class TestBanner(object):
|
||||
class TestBanner:
|
||||
@pytest.fixture(autouse=True)
|
||||
def init(self, ssh_audit):
|
||||
self.ssh = ssh_audit.SSH
|
||||
|
@ -1,11 +1,9 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
import re
|
||||
import pytest
|
||||
|
||||
|
||||
# pylint: disable=attribute-defined-outside-init,bad-whitespace
|
||||
class TestBuffer(object):
|
||||
class TestBuffer:
|
||||
@pytest.fixture(autouse=True)
|
||||
def init(self, ssh_audit):
|
||||
self.rbuf = ssh_audit.ReadBuf
|
||||
@ -61,7 +59,7 @@ class TestBuffer(object):
|
||||
def test_string(self):
|
||||
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'),
|
||||
tc = [('abc1', '00 00 00 04 61 62 63 31'),
|
||||
(b'abc2', '00 00 00 04 61 62 63 32')]
|
||||
for p in tc:
|
||||
v = p[0]
|
||||
@ -87,7 +85,7 @@ class TestBuffer(object):
|
||||
def test_line(self):
|
||||
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')]
|
||||
tc = [('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]
|
||||
|
@ -1,12 +1,10 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
import socket
|
||||
import errno
|
||||
import pytest
|
||||
|
||||
|
||||
# pylint: disable=attribute-defined-outside-init
|
||||
class TestErrors(object):
|
||||
class TestErrors:
|
||||
@pytest.fixture(autouse=True)
|
||||
def init(self, ssh_audit):
|
||||
self.AuditConf = ssh_audit.AuditConf
|
||||
|
@ -1,11 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import print_function
|
||||
import pytest
|
||||
|
||||
|
||||
# pylint: disable=attribute-defined-outside-init
|
||||
class TestOutput(object):
|
||||
class TestOutput:
|
||||
@pytest.fixture(autouse=True)
|
||||
def init(self, ssh_audit):
|
||||
self.Output = ssh_audit.Output
|
||||
@ -25,17 +22,17 @@ class TestOutput(object):
|
||||
def test_output_buffer_no_flush(self, output_spy):
|
||||
output_spy.begin()
|
||||
with self.OutputBuffer():
|
||||
print(u'abc')
|
||||
print('abc')
|
||||
assert output_spy.flush() == []
|
||||
|
||||
def test_output_buffer_flush(self, output_spy):
|
||||
output_spy.begin()
|
||||
with self.OutputBuffer() as obuf:
|
||||
print(u'abc')
|
||||
print('abc')
|
||||
print()
|
||||
print(u'def')
|
||||
print('def')
|
||||
obuf.flush()
|
||||
assert output_spy.flush() == [u'abc', u'', u'def']
|
||||
assert output_spy.flush() == ['abc', '', 'def']
|
||||
|
||||
def test_output_defaults(self):
|
||||
out = self.Output()
|
||||
@ -50,38 +47,38 @@ class TestOutput(object):
|
||||
out.use_colors = False
|
||||
output_spy.begin()
|
||||
out.info('info color')
|
||||
assert output_spy.flush() == [u'info color']
|
||||
assert output_spy.flush() == ['info color']
|
||||
output_spy.begin()
|
||||
out.head('head color')
|
||||
assert output_spy.flush() == [u'head color']
|
||||
assert output_spy.flush() == ['head color']
|
||||
output_spy.begin()
|
||||
out.good('good color')
|
||||
assert output_spy.flush() == [u'good color']
|
||||
assert output_spy.flush() == ['good color']
|
||||
output_spy.begin()
|
||||
out.warn('warn color')
|
||||
assert output_spy.flush() == [u'warn color']
|
||||
assert output_spy.flush() == ['warn color']
|
||||
output_spy.begin()
|
||||
out.fail('fail color')
|
||||
assert output_spy.flush() == [u'fail color']
|
||||
assert output_spy.flush() == ['fail color']
|
||||
if not out.colors_supported:
|
||||
return
|
||||
# test with colors
|
||||
out.use_colors = True
|
||||
output_spy.begin()
|
||||
out.info('info color')
|
||||
assert output_spy.flush() == [u'info color']
|
||||
assert output_spy.flush() == ['info color']
|
||||
output_spy.begin()
|
||||
out.head('head color')
|
||||
assert output_spy.flush() == [u'\x1b[0;36mhead color\x1b[0m']
|
||||
assert output_spy.flush() == ['\x1b[0;36mhead color\x1b[0m']
|
||||
output_spy.begin()
|
||||
out.good('good color')
|
||||
assert output_spy.flush() == [u'\x1b[0;32mgood color\x1b[0m']
|
||||
assert output_spy.flush() == ['\x1b[0;32mgood color\x1b[0m']
|
||||
output_spy.begin()
|
||||
out.warn('warn color')
|
||||
assert output_spy.flush() == [u'\x1b[0;33mwarn color\x1b[0m']
|
||||
assert output_spy.flush() == ['\x1b[0;33mwarn color\x1b[0m']
|
||||
output_spy.begin()
|
||||
out.fail('fail color')
|
||||
assert output_spy.flush() == [u'\x1b[0;31mfail color\x1b[0m']
|
||||
assert output_spy.flush() == ['\x1b[0;31mfail color\x1b[0m']
|
||||
|
||||
def test_output_sep(self, output_spy):
|
||||
out = self.Output()
|
||||
@ -89,7 +86,7 @@ class TestOutput(object):
|
||||
out.sep()
|
||||
out.sep()
|
||||
out.sep()
|
||||
assert output_spy.flush() == [u'', u'', u'']
|
||||
assert output_spy.flush() == ['', '', '']
|
||||
|
||||
def test_output_levels(self):
|
||||
out = self.Output()
|
||||
|
@ -1,11 +1,9 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
import socket
|
||||
import pytest
|
||||
|
||||
|
||||
# pylint: disable=attribute-defined-outside-init,protected-access
|
||||
class TestResolve(object):
|
||||
class TestResolve:
|
||||
@pytest.fixture(autouse=True)
|
||||
def init(self, ssh_audit):
|
||||
self.AuditConf = ssh_audit.AuditConf
|
||||
|
@ -1,10 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
import pytest
|
||||
|
||||
|
||||
# pylint: disable=attribute-defined-outside-init
|
||||
class TestSocket(object):
|
||||
class TestSocket:
|
||||
@pytest.fixture(autouse=True)
|
||||
def init(self, ssh_audit):
|
||||
self.ssh = ssh_audit.SSH
|
||||
|
@ -1,10 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
import pytest
|
||||
|
||||
|
||||
# pylint: disable=line-too-long,attribute-defined-outside-init
|
||||
class TestSoftware(object):
|
||||
class TestSoftware:
|
||||
@pytest.fixture(autouse=True)
|
||||
def init(self, ssh_audit):
|
||||
self.ssh = ssh_audit.SSH
|
||||
|
@ -1,11 +1,9 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
import struct
|
||||
import pytest
|
||||
|
||||
|
||||
# pylint: disable=line-too-long,attribute-defined-outside-init
|
||||
class TestSSH1(object):
|
||||
class TestSSH1:
|
||||
@pytest.fixture(autouse=True)
|
||||
def init(self, ssh_audit):
|
||||
self.ssh = ssh_audit.SSH
|
||||
|
@ -1,12 +1,10 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
import struct
|
||||
import pytest
|
||||
|
||||
|
||||
# pylint: disable=line-too-long,attribute-defined-outside-init
|
||||
class TestSSH2(object):
|
||||
class TestSSH2:
|
||||
@pytest.fixture(autouse=True)
|
||||
def init(self, ssh_audit):
|
||||
self.ssh = ssh_audit.SSH
|
||||
@ -38,16 +36,16 @@ class TestSSH2(object):
|
||||
def _kex_payload(self):
|
||||
w = self.wbuf()
|
||||
w.write(b'\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff')
|
||||
w.write_list([u'bogus_kex1', u'bogus_kex2']) # We use a bogus kex, otherwise the host key tests will kick off and fail.
|
||||
w.write_list([u'ssh-rsa', u'rsa-sha2-512', u'rsa-sha2-256', u'ssh-ed25519'])
|
||||
w.write_list([u'chacha20-poly1305@openssh.com', u'aes128-ctr', u'aes192-ctr', u'aes256-ctr', u'aes128-gcm@openssh.com', u'aes256-gcm@openssh.com', u'aes128-cbc', u'aes192-cbc', u'aes256-cbc'])
|
||||
w.write_list([u'chacha20-poly1305@openssh.com', u'aes128-ctr', u'aes192-ctr', u'aes256-ctr', u'aes128-gcm@openssh.com', u'aes256-gcm@openssh.com', u'aes128-cbc', u'aes192-cbc', u'aes256-cbc'])
|
||||
w.write_list([u'umac-64-etm@openssh.com', u'umac-128-etm@openssh.com', u'hmac-sha2-256-etm@openssh.com', u'hmac-sha2-512-etm@openssh.com', u'hmac-sha1-etm@openssh.com', u'umac-64@openssh.com', u'umac-128@openssh.com', u'hmac-sha2-256', u'hmac-sha2-512', u'hmac-sha1'])
|
||||
w.write_list([u'umac-64-etm@openssh.com', u'umac-128-etm@openssh.com', u'hmac-sha2-256-etm@openssh.com', u'hmac-sha2-512-etm@openssh.com', u'hmac-sha1-etm@openssh.com', u'umac-64@openssh.com', u'umac-128@openssh.com', u'hmac-sha2-256', u'hmac-sha2-512', u'hmac-sha1'])
|
||||
w.write_list([u'none', u'zlib@openssh.com'])
|
||||
w.write_list([u'none', u'zlib@openssh.com'])
|
||||
w.write_list([u''])
|
||||
w.write_list([u''])
|
||||
w.write_list(['bogus_kex1', 'bogus_kex2']) # We use a bogus kex, otherwise the host key tests will kick off and fail.
|
||||
w.write_list(['ssh-rsa', 'rsa-sha2-512', 'rsa-sha2-256', 'ssh-ed25519'])
|
||||
w.write_list(['chacha20-poly1305@openssh.com', 'aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'aes128-gcm@openssh.com', 'aes256-gcm@openssh.com', 'aes128-cbc', 'aes192-cbc', 'aes256-cbc'])
|
||||
w.write_list(['chacha20-poly1305@openssh.com', 'aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'aes128-gcm@openssh.com', 'aes256-gcm@openssh.com', 'aes128-cbc', 'aes192-cbc', 'aes256-cbc'])
|
||||
w.write_list(['umac-64-etm@openssh.com', 'umac-128-etm@openssh.com', 'hmac-sha2-256-etm@openssh.com', 'hmac-sha2-512-etm@openssh.com', 'hmac-sha1-etm@openssh.com', 'umac-64@openssh.com', 'umac-128@openssh.com', 'hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1'])
|
||||
w.write_list(['umac-64-etm@openssh.com', 'umac-128-etm@openssh.com', 'hmac-sha2-256-etm@openssh.com', 'hmac-sha2-512-etm@openssh.com', 'hmac-sha1-etm@openssh.com', 'umac-64@openssh.com', 'umac-128@openssh.com', 'hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1'])
|
||||
w.write_list(['none', 'zlib@openssh.com'])
|
||||
w.write_list(['none', 'zlib@openssh.com'])
|
||||
w.write_list([''])
|
||||
w.write_list([''])
|
||||
w.write_byte(False)
|
||||
w.write_int(0)
|
||||
return w.write_flush()
|
||||
@ -56,18 +54,18 @@ class TestSSH2(object):
|
||||
kex = self.ssh2.Kex.parse(self._kex_payload())
|
||||
assert kex is not None
|
||||
assert kex.cookie == b'\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff'
|
||||
assert kex.kex_algorithms == [u'bogus_kex1', u'bogus_kex2']
|
||||
assert kex.key_algorithms == [u'ssh-rsa', u'rsa-sha2-512', u'rsa-sha2-256', u'ssh-ed25519']
|
||||
assert kex.kex_algorithms == ['bogus_kex1', 'bogus_kex2']
|
||||
assert kex.key_algorithms == ['ssh-rsa', 'rsa-sha2-512', 'rsa-sha2-256', 'ssh-ed25519']
|
||||
assert kex.client is not None
|
||||
assert kex.server is not None
|
||||
assert kex.client.encryption == [u'chacha20-poly1305@openssh.com', u'aes128-ctr', u'aes192-ctr', u'aes256-ctr', u'aes128-gcm@openssh.com', u'aes256-gcm@openssh.com', u'aes128-cbc', u'aes192-cbc', u'aes256-cbc']
|
||||
assert kex.server.encryption == [u'chacha20-poly1305@openssh.com', u'aes128-ctr', u'aes192-ctr', u'aes256-ctr', u'aes128-gcm@openssh.com', u'aes256-gcm@openssh.com', u'aes128-cbc', u'aes192-cbc', u'aes256-cbc']
|
||||
assert kex.client.mac == [u'umac-64-etm@openssh.com', u'umac-128-etm@openssh.com', u'hmac-sha2-256-etm@openssh.com', u'hmac-sha2-512-etm@openssh.com', u'hmac-sha1-etm@openssh.com', u'umac-64@openssh.com', u'umac-128@openssh.com', u'hmac-sha2-256', u'hmac-sha2-512', u'hmac-sha1']
|
||||
assert kex.server.mac == [u'umac-64-etm@openssh.com', u'umac-128-etm@openssh.com', u'hmac-sha2-256-etm@openssh.com', u'hmac-sha2-512-etm@openssh.com', u'hmac-sha1-etm@openssh.com', u'umac-64@openssh.com', u'umac-128@openssh.com', u'hmac-sha2-256', u'hmac-sha2-512', u'hmac-sha1']
|
||||
assert kex.client.compression == [u'none', u'zlib@openssh.com']
|
||||
assert kex.server.compression == [u'none', u'zlib@openssh.com']
|
||||
assert kex.client.languages == [u'']
|
||||
assert kex.server.languages == [u'']
|
||||
assert kex.client.encryption == ['chacha20-poly1305@openssh.com', 'aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'aes128-gcm@openssh.com', 'aes256-gcm@openssh.com', 'aes128-cbc', 'aes192-cbc', 'aes256-cbc']
|
||||
assert kex.server.encryption == ['chacha20-poly1305@openssh.com', 'aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'aes128-gcm@openssh.com', 'aes256-gcm@openssh.com', 'aes128-cbc', 'aes192-cbc', 'aes256-cbc']
|
||||
assert kex.client.mac == ['umac-64-etm@openssh.com', 'umac-128-etm@openssh.com', 'hmac-sha2-256-etm@openssh.com', 'hmac-sha2-512-etm@openssh.com', 'hmac-sha1-etm@openssh.com', 'umac-64@openssh.com', 'umac-128@openssh.com', 'hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1']
|
||||
assert kex.server.mac == ['umac-64-etm@openssh.com', 'umac-128-etm@openssh.com', 'hmac-sha2-256-etm@openssh.com', 'hmac-sha2-512-etm@openssh.com', 'hmac-sha1-etm@openssh.com', 'umac-64@openssh.com', 'umac-128@openssh.com', 'hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1']
|
||||
assert kex.client.compression == ['none', 'zlib@openssh.com']
|
||||
assert kex.server.compression == ['none', 'zlib@openssh.com']
|
||||
assert kex.client.languages == ['']
|
||||
assert kex.server.languages == ['']
|
||||
assert kex.follows is False
|
||||
assert kex.unused == 0
|
||||
|
||||
|
@ -1,10 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
import pytest
|
||||
|
||||
|
||||
# pylint: disable=attribute-defined-outside-init
|
||||
class TestSSHAlgorithm(object):
|
||||
class TestSSHAlgorithm:
|
||||
@pytest.fixture(autouse=True)
|
||||
def init(self, ssh_audit):
|
||||
self.ssh = ssh_audit.SSH
|
||||
|
@ -1,202 +1,60 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
import sys
|
||||
import pytest
|
||||
|
||||
|
||||
# pylint: disable=attribute-defined-outside-init
|
||||
class TestUtils(object):
|
||||
class TestUtils:
|
||||
@pytest.fixture(autouse=True)
|
||||
def init(self, ssh_audit):
|
||||
self.utils = ssh_audit.Utils
|
||||
self.PY3 = sys.version_info >= (3,)
|
||||
|
||||
def test_to_bytes_py2(self):
|
||||
if self.PY3:
|
||||
return
|
||||
# binary_type (native str, bytes as str)
|
||||
assert self.utils.to_bytes('fran\xc3\xa7ais') == 'fran\xc3\xa7ais'
|
||||
assert self.utils.to_bytes(b'fran\xc3\xa7ais') == 'fran\xc3\xa7ais'
|
||||
# text_type (unicode)
|
||||
assert self.utils.to_bytes(u'fran\xe7ais') == 'fran\xc3\xa7ais'
|
||||
# other
|
||||
with pytest.raises(TypeError):
|
||||
self.utils.to_bytes(123)
|
||||
|
||||
def test_to_bytes_py3(self):
|
||||
if not self.PY3:
|
||||
return
|
||||
# binary_type (bytes)
|
||||
def test_to_bytes(self):
|
||||
assert self.utils.to_bytes(b'fran\xc3\xa7ais') == b'fran\xc3\xa7ais'
|
||||
# text_type (native str as unicode, unicode)
|
||||
assert self.utils.to_bytes('fran\xe7ais') == b'fran\xc3\xa7ais'
|
||||
assert self.utils.to_bytes(u'fran\xe7ais') == b'fran\xc3\xa7ais'
|
||||
# other
|
||||
with pytest.raises(TypeError):
|
||||
self.utils.to_bytes(123)
|
||||
|
||||
def test_to_utext_py2(self):
|
||||
if self.PY3:
|
||||
return
|
||||
# binary_type (native str, bytes as str)
|
||||
assert self.utils.to_utext('fran\xc3\xa7ais') == u'fran\xe7ais'
|
||||
assert self.utils.to_utext(b'fran\xc3\xa7ais') == u'fran\xe7ais'
|
||||
# text_type (unicode)
|
||||
assert self.utils.to_utext(u'fran\xe7ais') == u'fran\xe7ais'
|
||||
# other
|
||||
with pytest.raises(TypeError):
|
||||
self.utils.to_utext(123)
|
||||
|
||||
def test_to_utext_py3(self):
|
||||
if not self.PY3:
|
||||
return
|
||||
# binary_type (bytes)
|
||||
assert self.utils.to_utext(b'fran\xc3\xa7ais') == u'fran\xe7ais'
|
||||
# text_type (native str as unicode, unicode)
|
||||
def test_to_utext(self):
|
||||
assert self.utils.to_utext(b'fran\xc3\xa7ais') == 'fran\xe7ais'
|
||||
assert self.utils.to_utext('fran\xe7ais') == 'fran\xe7ais'
|
||||
assert self.utils.to_utext(u'fran\xe7ais') == u'fran\xe7ais'
|
||||
# other
|
||||
with pytest.raises(TypeError):
|
||||
self.utils.to_utext(123)
|
||||
|
||||
def test_to_ntext_py2(self):
|
||||
if self.PY3:
|
||||
return
|
||||
# str (native str, bytes as str)
|
||||
def test_to_ntext(self):
|
||||
assert self.utils.to_ntext('fran\xc3\xa7ais') == 'fran\xc3\xa7ais'
|
||||
assert self.utils.to_ntext(b'fran\xc3\xa7ais') == 'fran\xc3\xa7ais'
|
||||
# text_type (unicode)
|
||||
assert self.utils.to_ntext(u'fran\xe7ais') == 'fran\xc3\xa7ais'
|
||||
# other
|
||||
with pytest.raises(TypeError):
|
||||
self.utils.to_ntext(123)
|
||||
|
||||
def test_to_ntext_py3(self):
|
||||
if not self.PY3:
|
||||
return
|
||||
# str (native str)
|
||||
assert self.utils.to_ntext('fran\xc3\xa7ais') == 'fran\xc3\xa7ais'
|
||||
assert self.utils.to_ntext(u'fran\xe7ais') == 'fran\xe7ais'
|
||||
# binary_type (bytes)
|
||||
assert self.utils.to_ntext(b'fran\xc3\xa7ais') == 'fran\xe7ais'
|
||||
# other
|
||||
with pytest.raises(TypeError):
|
||||
self.utils.to_ntext(123)
|
||||
|
||||
def test_is_ascii_py2(self):
|
||||
if self.PY3:
|
||||
return
|
||||
# text_type (unicode)
|
||||
assert self.utils.is_ascii(u'francais') is True
|
||||
assert self.utils.is_ascii(u'fran\xe7ais') is False
|
||||
# str
|
||||
def test_is_ascii(self):
|
||||
assert self.utils.is_ascii('francais') is True
|
||||
assert self.utils.is_ascii('fran\xc3\xa7ais') is False
|
||||
# other
|
||||
assert self.utils.is_ascii(123) is False
|
||||
|
||||
def test_is_ascii_py3(self):
|
||||
if not self.PY3:
|
||||
return
|
||||
# text_type (str)
|
||||
assert self.utils.is_ascii('francais') is True
|
||||
assert self.utils.is_ascii(u'francais') is True
|
||||
assert self.utils.is_ascii('fran\xe7ais') is False
|
||||
assert self.utils.is_ascii(u'fran\xe7ais') is False
|
||||
# other
|
||||
assert self.utils.is_ascii(123) is False
|
||||
|
||||
def test_to_ascii_py2(self):
|
||||
if self.PY3:
|
||||
return
|
||||
# text_type (unicode)
|
||||
assert self.utils.to_ascii(u'francais') == 'francais'
|
||||
assert self.utils.to_ascii(u'fran\xe7ais') == 'fran?ais'
|
||||
assert self.utils.to_ascii(u'fran\xe7ais', 'ignore') == 'franais'
|
||||
# str
|
||||
def test_to_ascii(self):
|
||||
assert self.utils.to_ascii('francais') == 'francais'
|
||||
assert self.utils.to_ascii('fran\xc3\xa7ais') == 'fran??ais'
|
||||
assert self.utils.to_ascii('fran\xc3\xa7ais', 'ignore') == 'franais'
|
||||
with pytest.raises(TypeError):
|
||||
self.utils.to_ascii(123)
|
||||
|
||||
def test_to_ascii_py3(self):
|
||||
if not self.PY3:
|
||||
return
|
||||
# text_type (str)
|
||||
assert self.utils.to_ascii('francais') == 'francais'
|
||||
assert self.utils.to_ascii(u'francais') == 'francais'
|
||||
assert self.utils.to_ascii('fran\xe7ais') == 'fran?ais'
|
||||
assert self.utils.to_ascii('fran\xe7ais', 'ignore') == 'franais'
|
||||
assert self.utils.to_ascii(u'fran\xe7ais') == 'fran?ais'
|
||||
assert self.utils.to_ascii(u'fran\xe7ais', 'ignore') == 'franais'
|
||||
with pytest.raises(TypeError):
|
||||
self.utils.to_ascii(123)
|
||||
|
||||
def test_is_print_ascii_py2(self):
|
||||
if self.PY3:
|
||||
return
|
||||
# text_type (unicode)
|
||||
assert self.utils.is_print_ascii(u'francais') is True
|
||||
assert self.utils.is_print_ascii(u'francais\n') is False
|
||||
assert self.utils.is_print_ascii(u'fran\xe7ais') is False
|
||||
assert self.utils.is_print_ascii(u'fran\xe7ais\n') is False
|
||||
# str
|
||||
def test_is_print_ascii(self):
|
||||
assert self.utils.is_print_ascii('francais') is True
|
||||
assert self.utils.is_print_ascii('francais\n') is False
|
||||
assert self.utils.is_print_ascii('fran\xc3\xa7ais') is False
|
||||
# other
|
||||
assert self.utils.is_print_ascii(123) is False
|
||||
|
||||
def test_is_print_ascii_py3(self):
|
||||
if not self.PY3:
|
||||
return
|
||||
# text_type (str)
|
||||
assert self.utils.is_print_ascii('francais') is True
|
||||
assert self.utils.is_print_ascii('francais\n') is False
|
||||
assert self.utils.is_print_ascii(u'francais') is True
|
||||
assert self.utils.is_print_ascii(u'francais\n') is False
|
||||
assert self.utils.is_print_ascii('fran\xe7ais') is False
|
||||
assert self.utils.is_print_ascii(u'fran\xe7ais') is False
|
||||
# other
|
||||
assert self.utils.is_print_ascii(123) is False
|
||||
|
||||
def test_to_print_ascii_py2(self):
|
||||
if self.PY3:
|
||||
return
|
||||
# text_type (unicode)
|
||||
assert self.utils.to_print_ascii(u'francais') == 'francais'
|
||||
assert self.utils.to_print_ascii(u'francais\n') == 'francais?'
|
||||
assert self.utils.to_print_ascii(u'fran\xe7ais') == 'fran?ais'
|
||||
assert self.utils.to_print_ascii(u'fran\xe7ais\n') == 'fran?ais?'
|
||||
assert self.utils.to_print_ascii(u'fran\xe7ais', 'ignore') == 'franais'
|
||||
assert self.utils.to_print_ascii(u'fran\xe7ais\n', 'ignore') == 'franais'
|
||||
# str
|
||||
def test_to_print_ascii(self):
|
||||
assert self.utils.to_print_ascii('francais') == 'francais'
|
||||
assert self.utils.to_print_ascii('francais\n') == 'francais?'
|
||||
assert self.utils.to_print_ascii('fran\xc3\xa7ais') == 'fran??ais'
|
||||
assert self.utils.to_print_ascii('fran\xc3\xa7ais\n') == 'fran??ais?'
|
||||
assert self.utils.to_print_ascii('fran\xc3\xa7ais', 'ignore') == 'franais'
|
||||
assert self.utils.to_print_ascii('fran\xc3\xa7ais\n', 'ignore') == 'franais'
|
||||
with pytest.raises(TypeError):
|
||||
self.utils.to_print_ascii(123)
|
||||
|
||||
def test_to_print_ascii_py3(self):
|
||||
if not self.PY3:
|
||||
return
|
||||
# text_type (str)
|
||||
assert self.utils.to_print_ascii('francais') == 'francais'
|
||||
assert self.utils.to_print_ascii('francais\n') == 'francais?'
|
||||
assert self.utils.to_print_ascii(u'francais') == 'francais'
|
||||
assert self.utils.to_print_ascii(u'francais\n') == 'francais?'
|
||||
assert self.utils.to_print_ascii('fran\xe7ais') == 'fran?ais'
|
||||
assert self.utils.to_print_ascii('fran\xe7ais\n') == 'fran?ais?'
|
||||
assert self.utils.to_print_ascii('fran\xe7ais', 'ignore') == 'franais'
|
||||
assert self.utils.to_print_ascii('fran\xe7ais\n', 'ignore') == 'franais'
|
||||
assert self.utils.to_print_ascii(u'fran\xe7ais') == 'fran?ais'
|
||||
assert self.utils.to_print_ascii(u'fran\xe7ais\n') == 'fran?ais?'
|
||||
assert self.utils.to_print_ascii(u'fran\xe7ais', 'ignore') == 'franais'
|
||||
assert self.utils.to_print_ascii(u'fran\xe7ais\n', 'ignore') == 'franais'
|
||||
with pytest.raises(TypeError):
|
||||
self.utils.to_print_ascii(123)
|
||||
|
||||
|
@ -1,24 +1,22 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
import pytest
|
||||
|
||||
|
||||
# pylint: disable=attribute-defined-outside-init
|
||||
class TestVersionCompare(object):
|
||||
class TestVersionCompare:
|
||||
@pytest.fixture(autouse=True)
|
||||
def init(self, ssh_audit):
|
||||
self.ssh = ssh_audit.SSH
|
||||
|
||||
def get_dropbear_software(self, v):
|
||||
b = self.ssh.Banner.parse('SSH-2.0-dropbear_{0}'.format(v))
|
||||
b = self.ssh.Banner.parse('SSH-2.0-dropbear_{}'.format(v))
|
||||
return self.ssh.Software.parse(b)
|
||||
|
||||
def get_openssh_software(self, v):
|
||||
b = self.ssh.Banner.parse('SSH-2.0-OpenSSH_{0}'.format(v))
|
||||
b = self.ssh.Banner.parse('SSH-2.0-OpenSSH_{}'.format(v))
|
||||
return self.ssh.Software.parse(b)
|
||||
|
||||
def get_libssh_software(self, v):
|
||||
b = self.ssh.Banner.parse('SSH-2.0-libssh-{0}'.format(v))
|
||||
b = self.ssh.Banner.parse('SSH-2.0-libssh-{}'.format(v))
|
||||
return self.ssh.Software.parse(b)
|
||||
|
||||
def test_dropbear_compare_version_pre_years(self):
|
||||
@ -84,27 +82,27 @@ class TestVersionCompare(object):
|
||||
def test_dropbear_compare_version_sequential(self):
|
||||
versions = []
|
||||
for i in range(28, 44):
|
||||
versions.append('0.{0}'.format(i))
|
||||
versions.append('0.{}'.format(i))
|
||||
for i in range(1, 5):
|
||||
versions.append('0.44test{0}'.format(i))
|
||||
versions.append('0.44test{}'.format(i))
|
||||
for i in range(44, 49):
|
||||
versions.append('0.{0}'.format(i))
|
||||
versions.append('0.{}'.format(i))
|
||||
versions.append('0.48.1')
|
||||
for i in range(49, 54):
|
||||
versions.append('0.{0}'.format(i))
|
||||
versions.append('0.{}'.format(i))
|
||||
versions.append('0.53.1')
|
||||
for v in ['2011.54', '2012.55']:
|
||||
versions.append(v)
|
||||
for i in range(56, 61):
|
||||
versions.append('2013.{0}'.format(i))
|
||||
versions.append('2013.{}'.format(i))
|
||||
for v in ['2013.61test', '2013.62']:
|
||||
versions.append(v)
|
||||
for i in range(63, 67):
|
||||
versions.append('2014.{0}'.format(i))
|
||||
versions.append('2014.{}'.format(i))
|
||||
for i in range(67, 72):
|
||||
versions.append('2015.{0}'.format(i))
|
||||
versions.append('2015.{}'.format(i))
|
||||
for i in range(72, 75):
|
||||
versions.append('2016.{0}'.format(i))
|
||||
versions.append('2016.{}'.format(i))
|
||||
length = len(versions)
|
||||
for i in range(length):
|
||||
v = versions[i]
|
||||
@ -151,19 +149,19 @@ class TestVersionCompare(object):
|
||||
for v in ['3.0', '3.0.1', '3.0.2', '3.1', '3.2.2', '3.2.3']:
|
||||
versions.append(v)
|
||||
for i in range(3, 7):
|
||||
versions.append('3.{0}'.format(i))
|
||||
versions.append('3.{}'.format(i))
|
||||
for v in ['3.6.1', '3.7.0', '3.7.1']:
|
||||
versions.append(v)
|
||||
for i in range(8, 10):
|
||||
versions.append('3.{0}'.format(i))
|
||||
versions.append('3.{}'.format(i))
|
||||
for i in range(0, 10):
|
||||
versions.append('4.{0}'.format(i))
|
||||
versions.append('4.{}'.format(i))
|
||||
for i in range(0, 10):
|
||||
versions.append('5.{0}'.format(i))
|
||||
versions.append('5.{}'.format(i))
|
||||
for i in range(0, 10):
|
||||
versions.append('6.{0}'.format(i))
|
||||
versions.append('6.{}'.format(i))
|
||||
for i in range(0, 4):
|
||||
versions.append('7.{0}'.format(i))
|
||||
versions.append('7.{}'.format(i))
|
||||
length = len(versions)
|
||||
for i in range(length):
|
||||
v = versions[i]
|
||||
@ -193,15 +191,15 @@ class TestVersionCompare(object):
|
||||
for v in ['0.2', '0.3']:
|
||||
versions.append(v)
|
||||
for i in range(1, 5):
|
||||
versions.append('0.3.{0}'.format(i))
|
||||
versions.append('0.3.{}'.format(i))
|
||||
for i in range(0, 9):
|
||||
versions.append('0.4.{0}'.format(i))
|
||||
versions.append('0.4.{}'.format(i))
|
||||
for i in range(0, 6):
|
||||
versions.append('0.5.{0}'.format(i))
|
||||
versions.append('0.5.{}'.format(i))
|
||||
for i in range(0, 6):
|
||||
versions.append('0.6.{0}'.format(i))
|
||||
versions.append('0.6.{}'.format(i))
|
||||
for i in range(0, 5):
|
||||
versions.append('0.7.{0}'.format(i))
|
||||
versions.append('0.7.{}'.format(i))
|
||||
length = len(versions)
|
||||
for i in range(length):
|
||||
v = versions[i]
|
||||
|
Reference in New Issue
Block a user