Skip to content

Commit

Permalink
more coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
devl00p committed Jul 30, 2024
1 parent d7562df commit ee08a96
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/attack/test_mod_ldap.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from asyncio import Event
from fnmatch import fnmatch
from hashlib import md5
from unittest.mock import AsyncMock

import pytest
Expand Down Expand Up @@ -183,3 +184,36 @@ async def test_vulnerabilities():
)

assert module.network_errors == 0


@pytest.mark.asyncio
@respx.mock
async def test_is_page_dynamic():
respx.get("http://perdu.com/").mock(side_effect=httpx.RequestError("error"))
respx.get("http://perdu.com/hello").mock(return_value=httpx.Response(200, text="Hello there"))

persister = AsyncMock()

crawler_configuration = CrawlerConfiguration(Request("http://perdu.com/"), timeout=1)
async with AsyncCrawler.with_configuration(crawler_configuration) as crawler:
options = {"timeout": 10, "level": 2}

module = ModuleLdap(crawler, persister, options, Event(), crawler_configuration)
assert not await module.is_page_dynamic(
Request("http://perdu.com/"),
PayloadInfo("", "", True),
"hash"
)
assert module.network_errors == 1

assert not await module.is_page_dynamic(
Request("http://perdu.com/hello"),
PayloadInfo("", "", True),
md5(b"Hello there").hexdigest(),
)

assert await module.is_page_dynamic(
Request("http://perdu.com/hello"),
PayloadInfo("", "", True),
"yolo",
)

0 comments on commit ee08a96

Please sign in to comment.