Agent: Reword note in control

Rewrite control set proxy UT, fix typo in httpfinger
This commit is contained in:
Ilija Lazoroski 2021-10-07 16:18:17 +02:00
parent a8182cbb3d
commit cd23eb2909
3 changed files with 10 additions and 11 deletions

View File

@ -121,7 +121,8 @@ class ControlClient(object):
@staticmethod
def set_proxies(proxy_find):
"""
Note: Proxy schema changes which causes the machine to not open a tunnel back.
Note: The proxy schema changes between different versions of requests and urllib3,
which causes the machine to not open a tunnel back.
If we get "ValueError: check_hostname requires server_hostname" or
"Proxy URL had not schema, should start with http:// or https://" errors,
the proxy schema needs to be changed.

View File

@ -44,7 +44,7 @@ class HTTPFinger(HostFinger):
logger.info("Port %d is open on host %s " % (port[0], host))
break # https will be the same on the same port
except Timeout:
logger.debug(f"Timout while requesting headers from {url}")
logger.debug(f"Timeout while requesting headers from {url}")
except ConnectionError: # Someone doesn't like us
logger.debug(f"Connection error while requesting headers from {url}")

View File

@ -2,17 +2,15 @@ import pytest
from monkey.infection_monkey.control import ControlClient
PROXY_FOUND = ("8.8.8.8", "45455")
@pytest.mark.parametrize("is_windows_os", [True, False])
def test_control_set_proxies(monkeypatch, is_windows_os):
@pytest.mark.parametrize(
"is_windows_os,expected_proxy_string",
[(True, "http://8.8.8.8:45455"), (False, "8.8.8.8:45455")],
)
def test_control_set_proxies(monkeypatch, is_windows_os, expected_proxy_string):
monkeypatch.setattr("monkey.infection_monkey.control.is_windows_os", lambda: is_windows_os)
control_client = ControlClient()
control_client.set_proxies(PROXY_FOUND)
control_client.set_proxies(("8.8.8.8", "45455"))
if is_windows_os:
assert control_client.proxies["https"].startswith("http://")
else:
assert control_client.proxies["https"].startswith(PROXY_FOUND[0])
assert control_client.proxies["https"] == expected_proxy_string