From 46868e9996c2d49d7202c024a6f986dc93506f15 Mon Sep 17 00:00:00 2001
From: Shay Nehmad <shay.nehmad@guardicore.com>
Date: Thu, 3 Oct 2019 18:35:51 +0300
Subject: [PATCH] CR fixes

---
 .../post_breach/actions/communicate_as_new_user.py          | 6 ++----
 monkey/infection_monkey/utils/auto_new_user.py              | 4 ++++
 monkey/infection_monkey/utils/linux/users.py                | 2 +-
 monkey/infection_monkey/utils/windows/users.py              | 6 ++++--
 4 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/monkey/infection_monkey/post_breach/actions/communicate_as_new_user.py b/monkey/infection_monkey/post_breach/actions/communicate_as_new_user.py
index b98361ec9..5c1af693a 100644
--- a/monkey/infection_monkey/post_breach/actions/communicate_as_new_user.py
+++ b/monkey/infection_monkey/post_breach/actions/communicate_as_new_user.py
@@ -49,10 +49,8 @@ class CommunicateAsNewUser(PBA):
 
     @staticmethod
     def get_commandline_for_ping(domain=PING_TEST_DOMAIN, is_windows=is_windows_os()):
-        if is_windows:
-            return "{} {} {} {}".format("PING.exe", domain, "-n", "1")
-        else:
-            return "ping -c 1 {domain}".format(domain=PING_TEST_DOMAIN)
+        format_string = "PING.exe {domain} -n 1" if is_windows else "ping -c 1 {domain}"
+        format_string.format(domain=domain)
 
     def send_ping_result_telemetry(self, exit_status, commandline, username):
         """
diff --git a/monkey/infection_monkey/utils/auto_new_user.py b/monkey/infection_monkey/utils/auto_new_user.py
index c4b8d2f1a..e749020d6 100644
--- a/monkey/infection_monkey/utils/auto_new_user.py
+++ b/monkey/infection_monkey/utils/auto_new_user.py
@@ -35,4 +35,8 @@ class AutoNewUser:
 
     @abc.abstractmethod
     def run_as(self, command):
+        """
+        Run the given command as the new user that was created.
+        :param command: The command to run - give as shell commandline (e.g. "ping google.com -n 1")
+        """
         raise NotImplementedError()
diff --git a/monkey/infection_monkey/utils/linux/users.py b/monkey/infection_monkey/utils/linux/users.py
index e4968c522..34becb8f7 100644
--- a/monkey/infection_monkey/utils/linux/users.py
+++ b/monkey/infection_monkey/utils/linux/users.py
@@ -55,4 +55,4 @@ class AutoNewLinuxUser(AutoNewUser):
         # delete the user.
         commands_to_delete_user = get_linux_commands_to_delete_user(self.username)
         logger.debug("Trying to delete {} with commands {}".format(self.username, str(commands_to_delete_user)))
-        _ = subprocess.check_output(" ".join(commands_to_delete_user), stderr=subprocess.STDOUT, shell=True)
\ No newline at end of file
+        _ = subprocess.check_output(" ".join(commands_to_delete_user), stderr=subprocess.STDOUT, shell=True)
diff --git a/monkey/infection_monkey/utils/windows/users.py b/monkey/infection_monkey/utils/windows/users.py
index 857cddd07..cf6eb73c4 100644
--- a/monkey/infection_monkey/utils/windows/users.py
+++ b/monkey/infection_monkey/utils/windows/users.py
@@ -9,6 +9,7 @@ WAIT_TIMEOUT_IN_MILLISECONDS = 20 * 1000
 
 logger = logging.getLogger(__name__)
 
+
 def get_windows_commands_to_add_user(username, password, should_be_active=False):
     windows_cmds = [
         'net',
@@ -41,6 +42,7 @@ class AutoNewWindowsUser(AutoNewUser):
     """
     See AutoNewUser's documentation for details.
     """
+
     def __init__(self, username, password):
         """
         Creates a user with the username + password.
@@ -64,7 +66,7 @@ class AutoNewWindowsUser(AutoNewUser):
                 ".",  # Use current domain.
                 self.password,
                 win32con.LOGON32_LOGON_INTERACTIVE,  # Logon type - interactive (normal user). Need this to open ping
-                                                     # using a shell.
+                # using a shell.
                 win32con.LOGON32_PROVIDER_DEFAULT)  # Which logon provider to use - whatever Windows offers.
         except Exception as err:
             raise NewUserError("Can't logon as {}. Error: {}".format(self.username, str(err)))
@@ -150,4 +152,4 @@ class AutoNewWindowsUser(AutoNewUser):
             _ = subprocess.check_output(
                 commands_to_delete_user, stderr=subprocess.STDOUT, shell=True)
         except Exception as err:
-            raise NewUserError("Can't delete user {}. Info: {}".format(self.username, err))
\ No newline at end of file
+            raise NewUserError("Can't delete user {}. Info: {}".format(self.username, err))