Fix powershell credential generation tests to use AuthOptions class

This commit is contained in:
VakarisZ 2021-09-01 17:33:27 +03:00
parent aedc666e8f
commit 47393b2d55
1 changed files with 17 additions and 39 deletions

View File

@ -1,72 +1,50 @@
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_generation import get_credentials
from infection_monkey.model.host import VictimHost
TEST_USERS = ["user1", "user2"]
TEST_USERNAMES = ["user1", "user2"]
TEST_PASSWORDS = ["p1", "p2"]
def test_get_credentials__empty_windows_true():
credentials = utils.get_credentials([], [], True)
credentials = get_credentials([], [], True, True)
assert len(credentials) == 1
assert credentials[0] == (None, None)
assert credentials[0] == AuthOptions(username=None, password=None, is_https=False)
def test_get_credentials__empty_windows_false():
credentials = utils.get_credentials([], [], False)
credentials = get_credentials([], [], False, True)
assert len(credentials) == 0
def test_get_credentials__username_only_windows_true():
credentials = utils.get_credentials(TEST_USERS, [], True)
credentials = get_credentials(TEST_USERNAMES, [], True, True)
assert len(credentials) == 5
assert (TEST_USERS[0], "") in credentials
assert (TEST_USERS[1], "") in credentials
assert (TEST_USERS[0], None) in credentials
assert (TEST_USERS[1], None) in credentials
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 = utils.get_credentials(TEST_USERS, [], False)
credentials = get_credentials(TEST_USERNAMES, [], False, True)
assert len(credentials) == 2
assert (TEST_USERS[0], "") in credentials
assert (TEST_USERS[1], "") in credentials
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 = utils.get_credentials(TEST_USERS, TEST_PASSWORDS, True)
credentials = get_credentials(TEST_USERNAMES, TEST_PASSWORDS, True, True)
assert len(credentials) == 9
for user in TEST_USERS:
for user in TEST_USERNAMES:
for password in TEST_PASSWORDS:
assert (user, password) in credentials
def test_get_powershell_client_params__password_none():
(ssl, auth, encryption) = utils.get_powershell_client_params(None)
assert ssl is True
assert auth == utils.AUTH_NEGOTIATE
assert encryption == utils.ENCRYPTION_AUTO
def test_get_powershell_client_params__password_str():
(ssl, auth, encryption) = utils.get_powershell_client_params("1234")
assert ssl is True
assert auth == utils.AUTH_NEGOTIATE
assert encryption == utils.ENCRYPTION_AUTO
def test_get_powershell_client_params__password_empty():
(ssl, auth, encryption) = utils.get_powershell_client_params("")
assert ssl is False
assert auth == utils.AUTH_BASIC
assert encryption == utils.ENCRYPTION_NEVER
assert AuthOptions(username=user, password=password, is_https=True) in credentials
def test_build_monkey_execution_command():