示例#1
0
 def test__nmap__yields_ipv4_cidrs(self):
     slow = random.choice([True, False])
     params = yield_nmap_parameters(
         {'eth0': ['2001:db8::/64', '192.168.0.1/24', '192.168.1.1/24']},
         slow=slow)
     self.assertThat(set(params), Equals({
         NmapParameters(interface='eth0', cidr='192.168.0.0/24', slow=slow),
         NmapParameters(interface='eth0', cidr='192.168.1.0/24', slow=slow)
     }))
示例#2
0
 def test_nmap__yields_ipv4_cidrs(self):
     slow = random.choice([True, False])
     params = yield_nmap_parameters(
         {"eth0": ["2001:db8::/64", "192.168.0.1/24", "192.168.1.1/24"]},
         slow=slow,
     )
     self.assertThat(
         set(params),
         Equals({
             NmapParameters(interface="eth0",
                            cidr="192.168.0.0/24",
                            slow=slow),
             NmapParameters(interface="eth0",
                            cidr="192.168.1.0/24",
                            slow=slow),
         }),
     )
示例#3
0
 def test__runs_popen_with_expected_parameters(self):
     popen = self.patch(scan_network_module.subprocess, 'Popen')
     popen.return_value.poll = Mock()
     popen.return_value.poll.return_value = None
     interface = factory.make_name('eth')
     cidr = "192.168.0.0/24"
     params = NmapParameters(interface, cidr, slow=False)
     run_nmap(params)
     self.assertThat(popen, MockCalledOnceWith(
         get_nmap_arguments(params),
         stderr=subprocess.DEVNULL, stdin=subprocess.DEVNULL,
         stdout=subprocess.DEVNULL, env=get_env_with_locale(),
         preexec_fn=os.setsid))
示例#4
0
 def test__runs_nmap_e2e(self):
     ip = factory.make_ip_address(ipv6=False)
     # Force the use of `nmap` by ensuring it is reported as available.
     self.has_command_available_mock.return_value = True
     cidr = '%s/32' % ip
     slow = random.choice([True, False])
     args = ['eth0', cidr]
     if slow is True:
         args.append('--slow')
     self.run_command(*args)
     expected_params = NmapParameters(
         interface='eth0', cidr=cidr, slow=slow)
     self.assertThat(self.popen, MockCalledOnceWith(
         get_nmap_arguments(expected_params),
         stderr=subprocess.DEVNULL, stdin=subprocess.DEVNULL,
         stdout=subprocess.DEVNULL, env=get_env_with_locale(),
         preexec_fn=os.setsid))
示例#5
0
 def test_runs_popen_with_expected_parameters__slow(self):
     popen = self.patch(scan_network_module.subprocess, "Popen")
     popen.return_value.poll = Mock()
     popen.return_value.poll.return_value = None
     interface = factory.make_name("eth")
     cidr = "192.168.0.0/24"
     params = NmapParameters(interface, cidr, slow=True)
     run_nmap(params)
     nmap_args = get_nmap_arguments(params)
     self.assertThat(
         popen,
         MockCalledOnceWith(
             nmap_args,
             stderr=subprocess.DEVNULL,
             stdin=subprocess.DEVNULL,
             stdout=subprocess.DEVNULL,
             env=get_env_with_locale(),
             preexec_fn=os.setsid,
         ),
     )
     self.assertThat(nmap_args, Contains("--max-rate"))