Beispiel #1
0
def test_FromPodHostDiscovery():

    with requests_mock.Mocker() as m:
        e = RunningAsPodEvent()

        config.azure = False
        config.remote = None
        config.cidr = None
        m.get(
            "http://169.254.169.254/metadata/instance?api-version=2017-08-01",
            status_code=404,
        )
        f = FromPodHostDiscovery(e)
        assert not f.is_azure_pod()
        # TODO For now we don't test the traceroute discovery version
        # f.execute()

        # Test that we generate NewHostEvent for the addresses reported by the Azure Metadata API
        config.azure = True
        m.get(
            "http://169.254.169.254/metadata/instance?api-version=2017-08-01",
            text=
            '{"network":{"interface":[{"ipv4":{"subnet":[{"address": "3.4.5.6", "prefix": "255.255.255.252"}]}}]}}',
        )
        assert f.is_azure_pod()
        f.execute()

        # Test that we don't trigger a HostScanEvent unless either config.remote or config.cidr are configured
        config.remote = "1.2.3.4"
        f.execute()

        config.azure = False
        config.remote = None
        config.cidr = "1.2.3.4/24"
        f.execute()
Beispiel #2
0
    def test_is_azure_pod_request_fail(self):
        f = FromPodHostDiscovery(RunningAsPodEvent())

        with requests_mock.Mocker() as m:
            m.get(
                "http://169.254.169.254/metadata/instance?api-version=2017-08-01",
                status_code=404)
            result = f.is_azure_pod()

        assert not result
Beispiel #3
0
    def test_is_azure_pod_success(self):
        f = FromPodHostDiscovery(RunningAsPodEvent())

        with requests_mock.Mocker() as m:
            m.get(
                "http://169.254.169.254/metadata/instance?api-version=2017-08-01",
                text=TestFromPodHostDiscovery._make_response(
                    ("3.4.5.6", "255.255.255.252")),
            )
            result = f.is_azure_pod()

        assert result
Beispiel #4
0
 def test_execute_scan_remote(self):
     set_config(Config(remote="1.2.3.4"))
     f = FromPodHostDiscovery(RunningAsPodEvent())
     f.execute()
Beispiel #5
0
 def test_execute_scan_cidr(self):
     set_config(Config(cidr="1.2.3.4/30"))
     f = FromPodHostDiscovery(RunningAsPodEvent())
     f.execute()