From 353e9844dce11c88c6d25cf1a27d16a83668452f Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 23 Feb 2021 12:57:50 +0530 Subject: [PATCH] Modify unit tests --- .../zerologon_utils/test_vuln_assessment.py | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/monkey/infection_monkey/exploit/tests/zerologon_utils/test_vuln_assessment.py b/monkey/infection_monkey/exploit/tests/zerologon_utils/test_vuln_assessment.py index cddb7522f..7c833a67b 100644 --- a/monkey/infection_monkey/exploit/tests/zerologon_utils/test_vuln_assessment.py +++ b/monkey/infection_monkey/exploit/tests/zerologon_utils/test_vuln_assessment.py @@ -15,13 +15,18 @@ def host(): return VictimHost(IP, DOMAIN_NAME) +def _get_stub_queryIPForName(netbios_names): + def stub_queryIPForName(*args, **kwargs): + return netbios_names + return stub_queryIPForName + + def test_get_dc_details_multiple_netbios_names(host, monkeypatch): - def mock_queryIPForName(*args, **kwargs): - return NETBIOS_NAMES - - monkeypatch.setattr(NetBIOS, "queryIPForName", mock_queryIPForName) - NETBIOS_NAMES = ["Name1", "Name2", "Name3"] + + stub_queryIPForName = _get_stub_queryIPForName(NETBIOS_NAMES) + monkeypatch.setattr(NetBIOS, "queryIPForName", stub_queryIPForName) + dc_ip, dc_name, dc_handle = get_dc_details(host) assert dc_ip == IP assert dc_name == NETBIOS_NAMES[0] @@ -29,12 +34,11 @@ def test_get_dc_details_multiple_netbios_names(host, monkeypatch): def test_get_dc_details_no_netbios_names(host, monkeypatch): - def mock_queryIPForName(*args, **kwargs): - return NETBIOS_NAMES - - monkeypatch.setattr(NetBIOS, "queryIPForName", mock_queryIPForName) - NETBIOS_NAMES = [] + + stub_queryIPForName = _get_stub_queryIPForName(NETBIOS_NAMES) + monkeypatch.setattr(NetBIOS, "queryIPForName", stub_queryIPForName) + dc_ip, dc_name, dc_handle = get_dc_details(host) assert dc_ip == IP assert dc_name == ""