def test_tcp_scan_failure2(mocker): statement = test_helpers.O() statement.port = 11223 statement.protocol = 'TCP' statement.reachable = test_helpers.O() statement.reachable.should = 'should' statement.reachable.host = 'localhost' pot = PortOpenTest.PortOpenTest(statement) assert pot.tcp_scan() is False
def test_tcp_scan_success(mocker): statement = test_helpers.O() statement.port = 80 statement.protocol = 'TCP' statement.reachable = test_helpers.O() statement.reachable.should = 'should' statement.reachable.host = 'google.com' pot = PortOpenTest.PortOpenTest(statement) assert pot.tcp_scan() is True
def test_tcp_scan_failure(mocker): statement = test_helpers.O() statement.port = 12345 statement.protocol = 'TCP' statement.reachable = test_helpers.O() statement.reachable.should = 'should' statement.reachable.host = 'google.com' pot = PortOpenTest.PortOpenTest(statement) assert pot.tcp_scan() is False
def test_ctor(): statement = test_helpers.O() statement.port = 100 statement.protocol = 'UDP' statement.reachable = test_helpers.O() statement.reachable.should = 'should not' statement.reachable.host = 'example.com' pot = PortOpenTest.PortOpenTest(statement) assert pot.port == 100 assert pot.protocol == 'UDP' assert pot.host == 'example.com' assert pot.should_pass is False
def test_run_failure(mocker): statement = test_helpers.O() statement.port = 100 statement.protocol = 'UDP' statement.reachable = test_helpers.O() statement.reachable.should = 'should' statement.reachable.host = 'example.com' mocker.patch('PortOpenTest.PortOpenTest.udp_scan') PortOpenTest.PortOpenTest.udp_scan.return_value = False pot = PortOpenTest.PortOpenTest(statement) q = test_helpers.Q() pot.run(q) assert q.what_was_put.passed is False
def test_run_success_tcp(mocker): statement = test_helpers.O() statement.port = 100 statement.protocol = 'TCP' statement.reachable = test_helpers.O() statement.reachable.should = 'should' statement.reachable.host = 'example.com' mocker.patch('PortOpenTest.PortOpenTest.tcp_scan') PortOpenTest.PortOpenTest.tcp_scan.return_value = True pot = PortOpenTest.PortOpenTest(statement) q = test_helpers.Q() pot.run(q) assert q.what_was_put.passed is True
def test_run_http_success(mocker): mocker.patch('requests.get') requests.get.return_value = test_helpers.O() requests.get.return_value.status_code = 200 statement = test_helpers.O() statement.protocol = 'http' statement.target = 'www.google.com' statement.should = 'should' statement.filename = 'index.html' statement.port = 80 fft = FileFetchTest.FileFetchTest(statement) q = test_helpers.Q() fft.run(q) assert q.what_was_put.passed is True
def test_run_success(mocker): mocker.patch('json.loads') mocker.patch('subprocess.Popen') json.loads.return_value = { 'end': { 'streams': [{ 'receiver': { 'bits_per_second': 101 }, 'sender': { 'bits_per_second': 101 } }] } } statement = test_helpers.O() statement.direction = 'download from' statement.comparison = 'least' statement.bitrate = '100bps' statement.server = '10.0.0.1' q = test_helpers.Q() ipt = IperfTest.IperfTest(statement) ipt.run(q) assert q.what_was_put.passed is True
def test_constructor(mocker): s = test_helpers.O() s.host = 'host' s.routers = ['a', 'b', 'c'] t = TraceRouteTest.TraceRouteTest(s) assert t.host == 'host' assert t.routers == ['a', 'b', 'c']
def test_run_success(mocker): s = test_helpers.O() s.host = 'example.com' s.routers = ['a', 'b'] mocker.patch('scapy.all.sr') p1 = test_helpers.O() p2 = test_helpers.O() p1.fields = {'src': 'a'} p2.fields = {'src': 'b'} scapy.all.sr.return_value = [[(None, p1), (None, p2)], None] t = TraceRouteTest.TraceRouteTest(s) q = test_helpers.Q() t.run(q) assert q.what_was_put.passed is True
def test_run_unknown_host(mocker): s = test_helpers.O() s.host = 'notarealdomainname.comxyz' s.routers = ['a', 'b'] mocker.patch('scapy.all.sr') p1 = test_helpers.O() p2 = test_helpers.O() p1.fields = {'src': 'b'} p2.fields = {'src': 'a'} scapy.all.sr.return_value = [[(None, p1), (None, p2)], None] t = TraceRouteTest.TraceRouteTest(s) q = test_helpers.Q() t.run(q) assert q.what_was_put.passed is False
def test_run_success_dns(): statement = test_helpers.O() statement.type = 'dns' statement.value = '8.8.8.8' statement.should = 'should' dt = DHCPTest.DHCPTest(statement) result = dt.run(packets) assert result.passed is True
def test_run_zeropackets(): statement = test_helpers.O() statement.type = 'server' statement.value = '1.1.1.1' statement.should = 'should' dt = DHCPTest.DHCPTest(statement) result = dt.run([]) assert result.passed is False
def test_run_success_gateway(): statement = test_helpers.O() statement.type = 'gateway' statement.value = '10.0.0.1' statement.should = 'should' dt = DHCPTest.DHCPTest(statement) result = dt.run(packets) assert result.passed is True
def test_ctor(): statement = test_helpers.O() statement.should = 'should not' statement.value = '0xFF' ftt = FrameTypeTest.FrameTypeTest(statement) assert ftt.should_pass is False assert ftt.value == 255
def test_run_success_network(): statement = test_helpers.O() statement.type = 'network' statement.value = '10.0.0.0/24' statement.should = 'should' dt = DHCPTest.DHCPTest(statement) result = dt.run(packets) assert result.passed is True
def test_ctor(): statement = test_helpers.O() statement.should = 'should not' statement.value = '0xFF' ptt = PacketTypeTest.PacketTypeTest(statement) assert ptt.should_pass is False assert ptt.value == 255
def test_run_successful_fail(mocker): mocker.patch('dns.resolver.query') ans = th.O() ans.response = th.O() ans.response.answer = [th.O()] ans.response.answer[0].items = ['10.0.0.200'] dns.resolver.query.return_value = ans statement = th.O() statement.should = 'should not' statement.server = 'myserver' statement.resolve_to = '10.0.0.201' statement.domain = 'example.com' t = DNSTest.DNSTest(statement) q = th.Q() t.run(q) dns.resolver.query.assert_called() assert q.what_was_put.passed is True
def test_ctor(): statement = test_helpers.O() statement.type = 'server' statement.value = 'example.com' statement.should = 'should not' dt = DHCPTest.DHCPTest(statement) assert dt.type == 'server' assert dt.value == 'example.com' assert dt.should_pass is False
def test_check_network_successful_fail(): statement = test_helpers.O() statement.type = 'network' statement.value = '10.0.0.0/24' statement.should = 'should not' dt = DHCPTest.DHCPTest(statement) dt.dhcp_info = {} dt.dhcp_info['gateway'] = '12.0.0.2' dt.check_network() assert dt.success is True
def test_check_dns_successful_fail(): statement = test_helpers.O() statement.type = 'dns' statement.value = '10.0.0.1' statement.should = 'should not' dt = DHCPTest.DHCPTest(statement) dt.dhcp_info = {} dt.dhcp_info['dns'] = '10.0.0.2' dt.check_dns() assert dt.success is True
def test_ctor_network(): statement = test_helpers.O() statement.should = 'should not' statement.target = '10.0.0.0/8' statement.type = 'network' pft = PacketFromTest.PacketFromTest(statement) assert pft.should_pass is False assert pft.target == '10.0.0.0/8' assert pft.type == 'network'
def test_ctor_host(): statement = test_helpers.O() statement.should = 'should not' statement.target = '10.0.0.1' statement.type = 'host' pft = PacketFromTest.PacketFromTest(statement) assert pft.should_pass is False assert pft.target == '10.0.0.1' assert pft.type == 'host'
def test_run_found_but_shouldnt(): statement = test_helpers.O() statement.should = 'should not' statement.value = '0xFF' ftt = FrameTypeTest.FrameTypeTest(statement) packets = [{'fields': {'type': 255}}, {'fields': {'type': 253}}] result = ftt.run(packets) assert result.passed is False
def test_run_did_not_find(): statement = test_helpers.O() statement.should = 'should' statement.value = '0xFF' ftt = FrameTypeTest.FrameTypeTest(statement) packets = [{'fields': {'type': 10}}, {'fields': {'type': 253}}] result = ftt.run(packets) assert result.passed is False
def test_run_successful_failure(): statement = test_helpers.O() statement.should = 'should not' statement.value = '0xFF' ftt = FrameTypeTest.FrameTypeTest(statement) packets = [{'fields': {'type': 10}}, {'fields': {'type': 253}}] result = ftt.run(packets) assert result.passed is True
def test_check_gateway_fail(): statement = test_helpers.O() statement.type = 'gateway' statement.value = '10.0.0.1' statement.should = 'should' dt = DHCPTest.DHCPTest(statement) dt.dhcp_info = {} dt.dhcp_info['gateway'] = '10.0.0.2' dt.check_gateway() assert dt.success is False
def test_run_fail2(mocker): mocker.patch('scapy.all.sr') ans = th.O() ans.res = [1, 2, 3] scapy.all.sr.return_value = [ans, 'unans'] pst = PingStatement('should not') pt = PingTest.PingTest(pst) q = th.Q() pt.run(q) scapy.all.sr.assert_called() assert q.what_was_put.passed is False
def test_ctor(mocker): statement = th.O() statement.should = 'should not' statement.server = 'myserver' statement.resolve_to = '10.0.0.200' statement.domain = 'example.com' t = DNSTest.DNSTest(statement) assert t.server == 'myserver' assert t.server == 'myserver' assert t.domain == 'example.com' assert t.resolve_to == '10.0.0.200'
def test_ctor(): statement = test_helpers.O() statement.should = 'should not' statement.protocol = 'TCP' statement.port = 80 statement.direction = 'source' ppt = PacketPortTest.PacketPortTest(statement) assert ppt.should_pass is False assert ppt.port == 80 assert ppt.direction == 'source'