forked from p34709852/monkey
Changes in unit test
This commit is contained in:
parent
9240408956
commit
ca460b7348
|
@ -27,60 +27,88 @@ RESULT_STRINGS =\
|
||||||
'only_selected': "Only selected hosts can make connections (SSL or non-SSL).\n"
|
'only_selected': "Only selected hosts can make connections (SSL or non-SSL).\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
EXAMPLE_EXCEPTIONS =\
|
EXAMPLE_EXCEPTIONS_WITH_EXPECTED_RESULTS =\
|
||||||
[
|
{
|
||||||
RELEVANT_EXCEPTION_STRINGS['pwd_auth_failed'], # SSL not configured, all non-SSL allowed
|
# SSL not configured, all non-SSL allowed, # SSL not configured, all non-SSL allowed
|
||||||
|
RELEVANT_EXCEPTION_STRINGS['pwd_auth_failed']: [
|
||||||
|
RESULT_STRINGS['ssl_not_conf'],
|
||||||
|
RESULT_STRINGS['all_non_ssl']
|
||||||
|
],
|
||||||
|
|
||||||
RELEVANT_EXCEPTION_STRINGS['ssl_off_entry_not_found'], # SSL not configured, selected non-SSL allowed
|
# SSL not configured, selected non-SSL allowed
|
||||||
|
RELEVANT_EXCEPTION_STRINGS['ssl_off_entry_not_found']: [
|
||||||
|
RESULT_STRINGS['ssl_not_conf'],
|
||||||
|
RESULT_STRINGS['selected_non_ssl']
|
||||||
|
],
|
||||||
|
|
||||||
|
# all SSL allowed, all non-SSL allowed
|
||||||
'\n'.join([RELEVANT_EXCEPTION_STRINGS['pwd_auth_failed'],
|
'\n'.join([RELEVANT_EXCEPTION_STRINGS['pwd_auth_failed'],
|
||||||
RELEVANT_EXCEPTION_STRINGS['pwd_auth_failed']]), # all SSL allowed, all non-SSL allowed
|
RELEVANT_EXCEPTION_STRINGS['pwd_auth_failed']]): [
|
||||||
|
RESULT_STRINGS['ssl_conf'],
|
||||||
|
RESULT_STRINGS['all_ssl'],
|
||||||
|
RESULT_STRINGS['all_non_ssl']
|
||||||
|
],
|
||||||
|
|
||||||
|
# all SSL allowed, selected non-SSL allowed
|
||||||
'\n'.join([RELEVANT_EXCEPTION_STRINGS['pwd_auth_failed'],
|
'\n'.join([RELEVANT_EXCEPTION_STRINGS['pwd_auth_failed'],
|
||||||
RELEVANT_EXCEPTION_STRINGS['ssl_off_entry_not_found']]), # all SSL allowed, selected non-SSL allowed
|
RELEVANT_EXCEPTION_STRINGS['ssl_off_entry_not_found']]): [
|
||||||
|
RESULT_STRINGS['ssl_conf'],
|
||||||
'\n'.join([RELEVANT_EXCEPTION_STRINGS['ssl_on_entry_not_found'],
|
|
||||||
RELEVANT_EXCEPTION_STRINGS['pwd_auth_failed']]), # selected SSL allowed, all non-SSL allowed
|
|
||||||
|
|
||||||
'\n'.join([RELEVANT_EXCEPTION_STRINGS['ssl_on_entry_not_found'],
|
|
||||||
RELEVANT_EXCEPTION_STRINGS['ssl_off_entry_not_found']]) # selected SSL allowed, selected non-SSL allowed
|
|
||||||
] # don't change order!
|
|
||||||
|
|
||||||
EXPECTED_RESULTS =\
|
|
||||||
[
|
|
||||||
[RESULT_STRINGS['ssl_not_conf'],
|
|
||||||
RESULT_STRINGS['all_non_ssl']], # SSL not configured, all non-SSL allowed
|
|
||||||
|
|
||||||
[RESULT_STRINGS['ssl_not_conf'],
|
|
||||||
RESULT_STRINGS['selected_non_ssl']], # SSL not configured, selected non-SSL allowed
|
|
||||||
|
|
||||||
[RESULT_STRINGS['ssl_conf'],
|
|
||||||
RESULT_STRINGS['all_ssl'],
|
RESULT_STRINGS['all_ssl'],
|
||||||
RESULT_STRINGS['all_non_ssl']], # all SSL allowed, all non-SSL allowed
|
RESULT_STRINGS['selected_non_ssl']
|
||||||
|
],
|
||||||
|
|
||||||
[RESULT_STRINGS['ssl_conf'],
|
# selected SSL allowed, all non-SSL allowed
|
||||||
RESULT_STRINGS['all_ssl'],
|
'\n'.join([RELEVANT_EXCEPTION_STRINGS['ssl_on_entry_not_found'],
|
||||||
RESULT_STRINGS['selected_non_ssl']], # all SSL allowed, selected non-SSL allowed
|
RELEVANT_EXCEPTION_STRINGS['pwd_auth_failed']]): [
|
||||||
|
RESULT_STRINGS['ssl_conf'],
|
||||||
[RESULT_STRINGS['ssl_conf'],
|
|
||||||
RESULT_STRINGS['selected_ssl'],
|
RESULT_STRINGS['selected_ssl'],
|
||||||
RESULT_STRINGS['all_non_ssl']], # selected SSL allowed, all non-SSL allowed
|
RESULT_STRINGS['all_non_ssl']
|
||||||
|
],
|
||||||
|
|
||||||
[RESULT_STRINGS['ssl_conf'],
|
# selected SSL allowed, selected non-SSL allowed
|
||||||
RESULT_STRINGS['only_selected']] # selected SSL allowed, selected non-SSL allowed
|
'\n'.join([RELEVANT_EXCEPTION_STRINGS['ssl_on_entry_not_found'],
|
||||||
] # don't change order!
|
RELEVANT_EXCEPTION_STRINGS['ssl_off_entry_not_found']]): [
|
||||||
|
RESULT_STRINGS['ssl_conf'],
|
||||||
|
RESULT_STRINGS['only_selected']
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
# EXPECTED_RESULTS =\
|
||||||
|
# [
|
||||||
|
# [RESULT_STRINGS['ssl_not_conf'],
|
||||||
|
# RESULT_STRINGS['all_non_ssl']], # SSL not configured, all non-SSL allowed
|
||||||
|
|
||||||
|
# [RESULT_STRINGS['ssl_not_conf'],
|
||||||
|
# RESULT_STRINGS['selected_non_ssl']], # SSL not configured, selected non-SSL allowed
|
||||||
|
|
||||||
|
# [RESULT_STRINGS['ssl_conf'],
|
||||||
|
# RESULT_STRINGS['all_ssl'],
|
||||||
|
# RESULT_STRINGS['all_non_ssl']], # all SSL allowed, all non-SSL allowed
|
||||||
|
|
||||||
|
# [RESULT_STRINGS['ssl_conf'],
|
||||||
|
# RESULT_STRINGS['all_ssl'],
|
||||||
|
# RESULT_STRINGS['selected_non_ssl']], # all SSL allowed, selected non-SSL allowed
|
||||||
|
|
||||||
|
# [RESULT_STRINGS['ssl_conf'],
|
||||||
|
# RESULT_STRINGS['selected_ssl'],
|
||||||
|
# RESULT_STRINGS['all_non_ssl']], # selected SSL allowed, all non-SSL allowed
|
||||||
|
|
||||||
|
# [RESULT_STRINGS['ssl_conf'],
|
||||||
|
# RESULT_STRINGS['only_selected']] # selected SSL allowed, selected non-SSL allowed
|
||||||
|
# ] # don't change order!
|
||||||
|
|
||||||
|
|
||||||
class TestPostgreSQLFinger(TestCase):
|
class TestPostgreSQLFinger(TestCase):
|
||||||
def test_is_relevant_exception(self):
|
def test_is_relevant_exception(self):
|
||||||
assert PostgreSQLFinger().is_relevant_exception(IRRELEVANT_EXCEPTION_STRING) is False
|
assert PostgreSQLFinger().is_relevant_exception(IRRELEVANT_EXCEPTION_STRING) is False
|
||||||
for exception_string in EXAMPLE_EXCEPTIONS:
|
for exception_string in EXAMPLE_EXCEPTIONS_WITH_EXPECTED_RESULTS:
|
||||||
assert PostgreSQLFinger().is_relevant_exception(exception_string) is True
|
assert PostgreSQLFinger().is_relevant_exception(exception_string) is True
|
||||||
|
|
||||||
def test_analyze_operational_error(self):
|
def test_analyze_operational_error(self):
|
||||||
host = Mock(['services'])
|
host = Mock(['services'])
|
||||||
host.services = {}
|
host.services = {}
|
||||||
for idx in range(len(EXAMPLE_EXCEPTIONS)):
|
for exception_string in EXAMPLE_EXCEPTIONS_WITH_EXPECTED_RESULTS:
|
||||||
with self.subTest(msg=f"Checking result for exception: {EXAMPLE_EXCEPTIONS[idx]}"):
|
with self.subTest(msg=f"Checking result for exception: {exception_string}"):
|
||||||
PostgreSQLFinger().analyze_operational_error(host, EXAMPLE_EXCEPTIONS[idx])
|
PostgreSQLFinger().analyze_operational_error(host, exception_string)
|
||||||
assert host.services['PostgreSQL']['communication_encryption_details'] == ''.join(EXPECTED_RESULTS[idx])
|
assert host.services['PostgreSQL']['communication_encryption_details'] ==\
|
||||||
|
''.join(EXAMPLE_EXCEPTIONS_WITH_EXPECTED_RESULTS[exception_string])
|
||||||
|
|
Loading…
Reference in New Issue