Пример #1
0
def test_get_open_ports(nmap_fixture, netif_gateways, netif_ifaddresses):
    with mock.patch('agent.security_helper.nmap') as nmap, \
            mock.patch('netifaces.gateways') as gw, \
            mock.patch('netifaces.ifaddresses') as ifaddr:
        nmap.return_value.stdout = nmap_fixture
        gw.return_value = netif_gateways
        ifaddr.return_value = netif_ifaddresses
        result = agent.get_open_ports()
        assert len(result) == 4  # TODO: test keys/values
Пример #2
0
def test_get_open_ports(net_connections_fixture, netstat_result):
    with mock.patch('psutil.net_connections') as net_connections:
        net_connections.return_value = net_connections_fixture
        connections_ports = agent.get_open_ports()
        assert connections_ports == [netstat_result[1]]