From b3436d660f9f6244f9a768b638c50994b004efc0 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Wed, 1 Sep 2021 12:06:58 -0400 Subject: [PATCH] Tests: Move PowerShell get_credentials() tests Move the tests for the PowerShell exploiter's get_credentials() function to test_credential_generators.py, since get_credentials() is now contained in credential_generators.py --- .../test_credential_generators.py | 45 +++++++++++++++++++ .../exploit/powershell_utils/test_utils.py | 45 ------------------- 2 files changed, 45 insertions(+), 45 deletions(-) create mode 100644 monkey/tests/unit_tests/infection_monkey/exploit/powershell_utils/test_credential_generators.py diff --git a/monkey/tests/unit_tests/infection_monkey/exploit/powershell_utils/test_credential_generators.py b/monkey/tests/unit_tests/infection_monkey/exploit/powershell_utils/test_credential_generators.py new file mode 100644 index 000000000..15595bc84 --- /dev/null +++ b/monkey/tests/unit_tests/infection_monkey/exploit/powershell_utils/test_credential_generators.py @@ -0,0 +1,45 @@ +from infection_monkey.exploit.powershell_utils.auth_options import AuthOptions +from infection_monkey.exploit.powershell_utils.credential_generators import get_credentials + +TEST_USERNAMES = ["user1", "user2"] +TEST_PASSWORDS = ["p1", "p2"] + + +def test_get_credentials__empty_windows_true(): + credentials = get_credentials([], [], True, True) + + assert len(credentials) == 1 + assert credentials[0] == AuthOptions(username=None, password=None, is_https=False) + + +def test_get_credentials__empty_windows_false(): + credentials = get_credentials([], [], False, True) + + assert len(credentials) == 0 + + +def test_get_credentials__username_only_windows_true(): + credentials = get_credentials(TEST_USERNAMES, [], True, True) + + assert len(credentials) == 5 + assert AuthOptions(username=TEST_USERNAMES[0], password="", is_https=False) in credentials + assert AuthOptions(username=TEST_USERNAMES[1], password="", is_https=False) in credentials + assert AuthOptions(username=TEST_USERNAMES[0], password=None, is_https=True) in credentials + assert AuthOptions(username=TEST_USERNAMES[1], password=None, is_https=True) in credentials + + +def test_get_credentials__username_only_windows_false(): + credentials = get_credentials(TEST_USERNAMES, [], False, True) + + assert len(credentials) == 2 + assert AuthOptions(username=TEST_USERNAMES[0], password="", is_https=False) in credentials + assert AuthOptions(username=TEST_USERNAMES[1], password="", is_https=False) in credentials + + +def test_get_credentials__username_password_windows_true(): + credentials = get_credentials(TEST_USERNAMES, TEST_PASSWORDS, True, True) + + assert len(credentials) == 9 + for user in TEST_USERNAMES: + for password in TEST_PASSWORDS: + assert AuthOptions(username=user, password=password, is_https=True) in credentials diff --git a/monkey/tests/unit_tests/infection_monkey/exploit/powershell_utils/test_utils.py b/monkey/tests/unit_tests/infection_monkey/exploit/powershell_utils/test_utils.py index 3ba5388f9..de5ca3b5d 100644 --- a/monkey/tests/unit_tests/infection_monkey/exploit/powershell_utils/test_utils.py +++ b/monkey/tests/unit_tests/infection_monkey/exploit/powershell_utils/test_utils.py @@ -1,51 +1,6 @@ from infection_monkey.exploit.powershell_utils import utils -from infection_monkey.exploit.powershell_utils.auth_options import AuthOptions -from infection_monkey.exploit.powershell_utils.credential_generators import get_credentials from infection_monkey.model.host import VictimHost -TEST_USERNAMES = ["user1", "user2"] -TEST_PASSWORDS = ["p1", "p2"] - - -def test_get_credentials__empty_windows_true(): - credentials = get_credentials([], [], True, True) - - assert len(credentials) == 1 - assert credentials[0] == AuthOptions(username=None, password=None, is_https=False) - - -def test_get_credentials__empty_windows_false(): - credentials = get_credentials([], [], False, True) - - assert len(credentials) == 0 - - -def test_get_credentials__username_only_windows_true(): - credentials = get_credentials(TEST_USERNAMES, [], True, True) - - assert len(credentials) == 5 - assert AuthOptions(username=TEST_USERNAMES[0], password="", is_https=False) in credentials - assert AuthOptions(username=TEST_USERNAMES[1], password="", is_https=False) in credentials - assert AuthOptions(username=TEST_USERNAMES[0], password=None, is_https=True) in credentials - assert AuthOptions(username=TEST_USERNAMES[1], password=None, is_https=True) in credentials - - -def test_get_credentials__username_only_windows_false(): - credentials = get_credentials(TEST_USERNAMES, [], False, True) - - assert len(credentials) == 2 - assert AuthOptions(username=TEST_USERNAMES[0], password="", is_https=False) in credentials - assert AuthOptions(username=TEST_USERNAMES[1], password="", is_https=False) in credentials - - -def test_get_credentials__username_password_windows_true(): - credentials = get_credentials(TEST_USERNAMES, TEST_PASSWORDS, True, True) - - assert len(credentials) == 9 - for user in TEST_USERNAMES: - for password in TEST_PASSWORDS: - assert AuthOptions(username=user, password=password, is_https=True) in credentials - def test_build_monkey_execution_command(): host = VictimHost("127.0.0.1")