예제 #1
0
    async def test_set_proxy(self, loop):
        engine = AioHttpEngine(loop=loop)
        proxy_address = "http://some.proxy.com"

        engine.set_proxy(proxy_address)

        self.assertEqual(engine.proxy, proxy_address)
예제 #2
0
    def test_constructor_create_client_session_with_connector_with_specified_verify_ssl_value(
            self):
        engine_verify_ssl = AioHttpEngine(loop=None, verify_ssl=True)
        engine_dont_verify_ssl = AioHttpEngine(loop=None, verify_ssl=False)

        self.assertTrue(engine_verify_ssl.session.connector.verify_ssl)
        self.assertFalse(engine_dont_verify_ssl.session.connector.verify_ssl)
예제 #3
0
    async def test_set_ssl_parameters_dont_verify_ssl(self, loop):
        engine = AioHttpEngine(loop=loop)
        engine.session.request = make_mocked_coro(return_value=FakeResponse())
        entry = Entry.create("http://www.example.com/")

        engine.set_ssl_parameters(verify_ssl=False)
        await engine.perform(entry, Heuristics())

        engine.session.request.assert_called_once_with(
            method=entry.request.method,
            url=entry.request.url,
            allow_redirects=False,
            timeout=0.2,
            ssl=False)
예제 #4
0
    def initialize_hammertime(self,
                              proxy=None,
                              verify_ssl=True,
                              ca_certificate_file=None,
                              concurrency=0):
        loop = custom_event_loop()
        if proxy is not None and verify_ssl and ca_certificate_file is None:
            self.output_manager.log_message(
                "Verifying SSL authentication of the target over a proxy without providing "
                "a CA certificate. Scan may fail if target is a https website."
            )

        scale_policy = SlowStartPolicy(initial=3)
        if concurrency > 0:
            scale_policy = StaticPolicy(concurrency)

        request_engine = AioHttpEngine(loop=loop,
                                       verify_ssl=verify_ssl,
                                       ca_certificate_file=ca_certificate_file)
        self.hammertime = HammerTime(loop=loop,
                                     retry_count=3,
                                     proxy=proxy,
                                     request_engine=request_engine,
                                     scale_policy=scale_policy)
        self.config_hammertime()
예제 #5
0
    async def test_constructor_do_not_overwrite_aiohttp_engine_proxy_if_constructor_proxy_is_none(
            self, loop):
        engine = AioHttpEngine(loop=loop, proxy="http://some.proxy.com")
        h = HammerTime(loop=loop, request_engine=engine)

        aiohttp_engine = h.request_engine.request_engine

        self.assertEqual(aiohttp_engine.proxy, "http://some.proxy.com")
예제 #6
0
    def test_constructor_load_certification_authority_certificate_in_session_ssl_context(
            self):
        with patch("ssl.SSLContext.load_verify_locations", MagicMock()):
            engine = AioHttpEngine(loop=None,
                                   ca_certificate_file="certificate.cer")

            load_verify_locations = engine.session.connector.ssl_context.load_verify_locations
            load_verify_locations.assert_called_once_with(
                cafile="certificate.cer")
예제 #7
0
    async def test_set_ssl_parameters_set_certification_authority_certificate(
            self, loop):
        ssl_context = "ssl_context"
        with patch(
                "ssl.create_default_context",
                MagicMock(return_value=ssl_context)) as create_default_context:
            engine = AioHttpEngine(loop=loop)
            engine.session.request = make_mocked_coro(
                return_value=FakeResponse())
            entry = Entry.create("http://www.example.com/")

            engine.set_ssl_parameters(ca_certificate_file="certificate.cer")
            await engine.perform(entry, Heuristics())

            engine.session.request.assert_called_once_with(
                method=entry.request.method,
                url=entry.request.url,
                allow_redirects=False,
                timeout=0.2,
                ssl=ssl_context)
            create_default_context.assert_called_once_with(
                cafile="certificate.cer")
예제 #8
0
    async def test_perform_use_proxy_for_request(self, loop):
        asyncio.set_event_loop(loop)
        engine = AioHttpEngine(loop=loop, proxy="http://some.proxy.com/")
        engine.session.request = make_mocked_coro(return_value=FakeResponse())
        entry = Entry.create("http://www.example.com/1")

        await engine.perform(entry, Heuristics())

        engine.session.request.assert_called_once_with(
            method=entry.request.method,
            url="http://www.example.com/1",
            timeout=0.2,
            proxy="http://some.proxy.com/")
예제 #9
0
    async def test_specify_header(self, loop):
        asyncio.set_event_loop(loop)
        engine = AioHttpEngine(loop=loop)
        engine.session.request = make_mocked_coro(return_value=FakeResponse())
        entry = Entry.create("http://www.example.com/1",
                             headers={"User-Agent": "Hammertime 1.2.3"})

        await engine.perform(entry, Heuristics())

        engine.session.request.assert_called_once_with(
            method=entry.request.method,
            url="http://www.example.com/1",
            timeout=ANY,
            allow_redirects=False,
            headers={"User-Agent": "Hammertime 1.2.3"})
예제 #10
0
    async def test_perform_use_timeout_of_entry_if_not_none(self, loop):
        asyncio.set_event_loop(loop)
        engine = AioHttpEngine(loop=loop, proxy="http://some.proxy.com/")
        engine.session.request = make_mocked_coro(return_value=FakeResponse())
        entry = Entry.create("http://www.example.com/1",
                             arguments={"timeout": 10})

        await engine.perform(entry, Heuristics())

        engine.session.request.assert_called_once_with(
            method=entry.request.method,
            url="http://www.example.com/1",
            timeout=10,
            proxy="http://some.proxy.com/",
            allow_redirects=False)