mirror of
https://github.com/jtesta/ssh-audit.git
synced 2024-12-22 17:15:09 +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
173 lines
5.3 KiB
Python
173 lines
5.3 KiB
Python
import pytest
|
|
|
|
|
|
# pylint: disable=attribute-defined-outside-init
|
|
class TestOutput:
|
|
@pytest.fixture(autouse=True)
|
|
def init(self, ssh_audit):
|
|
self.Output = ssh_audit.Output
|
|
self.OutputBuffer = ssh_audit.OutputBuffer
|
|
|
|
def test_output_buffer_no_lines(self, output_spy):
|
|
output_spy.begin()
|
|
with self.OutputBuffer() as obuf:
|
|
pass
|
|
assert output_spy.flush() == []
|
|
output_spy.begin()
|
|
with self.OutputBuffer() as obuf:
|
|
pass
|
|
obuf.flush()
|
|
assert output_spy.flush() == []
|
|
|
|
def test_output_buffer_no_flush(self, output_spy):
|
|
output_spy.begin()
|
|
with self.OutputBuffer():
|
|
print('abc')
|
|
assert output_spy.flush() == []
|
|
|
|
def test_output_buffer_flush(self, output_spy):
|
|
output_spy.begin()
|
|
with self.OutputBuffer() as obuf:
|
|
print('abc')
|
|
print()
|
|
print('def')
|
|
obuf.flush()
|
|
assert output_spy.flush() == ['abc', '', 'def']
|
|
|
|
def test_output_defaults(self):
|
|
out = self.Output()
|
|
# default: on
|
|
assert out.batch is False
|
|
assert out.use_colors is True
|
|
assert out.level == 'info'
|
|
|
|
def test_output_colors(self, output_spy):
|
|
out = self.Output()
|
|
# test without colors
|
|
out.use_colors = False
|
|
output_spy.begin()
|
|
out.info('info color')
|
|
assert output_spy.flush() == ['info color']
|
|
output_spy.begin()
|
|
out.head('head color')
|
|
assert output_spy.flush() == ['head color']
|
|
output_spy.begin()
|
|
out.good('good color')
|
|
assert output_spy.flush() == ['good color']
|
|
output_spy.begin()
|
|
out.warn('warn color')
|
|
assert output_spy.flush() == ['warn color']
|
|
output_spy.begin()
|
|
out.fail('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() == ['info color']
|
|
output_spy.begin()
|
|
out.head('head color')
|
|
assert output_spy.flush() == ['\x1b[0;36mhead color\x1b[0m']
|
|
output_spy.begin()
|
|
out.good('good color')
|
|
assert output_spy.flush() == ['\x1b[0;32mgood color\x1b[0m']
|
|
output_spy.begin()
|
|
out.warn('warn color')
|
|
assert output_spy.flush() == ['\x1b[0;33mwarn color\x1b[0m']
|
|
output_spy.begin()
|
|
out.fail('fail color')
|
|
assert output_spy.flush() == ['\x1b[0;31mfail color\x1b[0m']
|
|
|
|
def test_output_sep(self, output_spy):
|
|
out = self.Output()
|
|
output_spy.begin()
|
|
out.sep()
|
|
out.sep()
|
|
out.sep()
|
|
assert output_spy.flush() == ['', '', '']
|
|
|
|
def test_output_levels(self):
|
|
out = self.Output()
|
|
assert out.get_level('info') == 0
|
|
assert out.get_level('good') == 0
|
|
assert out.get_level('warn') == 1
|
|
assert out.get_level('fail') == 2
|
|
assert out.get_level('unknown') > 2
|
|
|
|
def test_output_level_property(self):
|
|
out = self.Output()
|
|
out.level = 'info'
|
|
assert out.level == 'info'
|
|
out.level = 'good'
|
|
assert out.level == 'info'
|
|
out.level = 'warn'
|
|
assert out.level == 'warn'
|
|
out.level = 'fail'
|
|
assert out.level == 'fail'
|
|
out.level = 'invalid level'
|
|
assert out.level == 'unknown'
|
|
|
|
def test_output_level(self, output_spy):
|
|
out = self.Output()
|
|
# visible: all
|
|
out.level = 'info'
|
|
output_spy.begin()
|
|
out.info('info color')
|
|
out.head('head color')
|
|
out.good('good color')
|
|
out.warn('warn color')
|
|
out.fail('fail color')
|
|
assert len(output_spy.flush()) == 5
|
|
# visible: head, warn, fail
|
|
out.level = 'warn'
|
|
output_spy.begin()
|
|
out.info('info color')
|
|
out.head('head color')
|
|
out.good('good color')
|
|
out.warn('warn color')
|
|
out.fail('fail color')
|
|
assert len(output_spy.flush()) == 3
|
|
# visible: head, fail
|
|
out.level = 'fail'
|
|
output_spy.begin()
|
|
out.info('info color')
|
|
out.head('head color')
|
|
out.good('good color')
|
|
out.warn('warn color')
|
|
out.fail('fail color')
|
|
assert len(output_spy.flush()) == 2
|
|
# visible: head
|
|
out.level = 'invalid level'
|
|
output_spy.begin()
|
|
out.info('info color')
|
|
out.head('head color')
|
|
out.good('good color')
|
|
out.warn('warn color')
|
|
out.fail('fail color')
|
|
assert len(output_spy.flush()) == 1
|
|
|
|
def test_output_batch(self, output_spy):
|
|
out = self.Output()
|
|
# visible: all
|
|
output_spy.begin()
|
|
out.level = 'info'
|
|
out.batch = False
|
|
out.info('info color')
|
|
out.head('head color')
|
|
out.good('good color')
|
|
out.warn('warn color')
|
|
out.fail('fail color')
|
|
assert len(output_spy.flush()) == 5
|
|
# visible: all except head
|
|
output_spy.begin()
|
|
out.level = 'info'
|
|
out.batch = True
|
|
out.info('info color')
|
|
out.head('head color')
|
|
out.good('good color')
|
|
out.warn('warn color')
|
|
out.fail('fail color')
|
|
assert len(output_spy.flush()) == 4
|