forked from arrester/SubSurfer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_freecampdev_scanner.py
More file actions
81 lines (59 loc) · 1.92 KB
/
Copy pathtest_freecampdev_scanner.py
File metadata and controls
81 lines (59 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import json
import pytest
from subsurfer.core.handler.passive.freecampdev import FreecampDevScanner
class MockResponse:
def __init__(self, status, text):
self.status = status
self._text = text
async def __aenter__(self):
return self
async def __aexit__(self, exc_type, exc, tb):
return None
async def text(self):
return self._text
class MockSession:
def __init__(self, response):
self.response = response
async def __aenter__(self):
return self
async def __aexit__(self, exc_type, exc, tb):
return None
def post(self, *args, **kwargs):
return self.response
@pytest.mark.asyncio
async def test_freecampdev_scanner_returns_valid_results(monkeypatch):
domain = "example.com"
payload = json.dumps(
{
"results": [
{"subdomain": f"www.{domain}"},
{"subdomain": f"api.{domain}"},
{"subdomain": "invalid.test"},
]
}
)
monkeypatch.setattr(
"subsurfer.core.handler.passive.freecampdev.aiohttp.ClientSession",
lambda: MockSession(MockResponse(200, payload)),
)
scanner = FreecampDevScanner(domain, silent=True)
results = await scanner.scan()
assert results == {f"www.{domain}", f"api.{domain}"}
@pytest.mark.asyncio
async def test_freecampdev_scanner_skips_false_positive_over_threshold(monkeypatch):
domain = "example.com"
payload = json.dumps(
{
"results": [
{"subdomain": f"sub{i}.{domain}"}
for i in range(FreecampDevScanner.MAX_SUBDOMAINS + 1)
]
}
)
monkeypatch.setattr(
"subsurfer.core.handler.passive.freecampdev.aiohttp.ClientSession",
lambda: MockSession(MockResponse(200, payload)),
)
scanner = FreecampDevScanner(domain, silent=True)
results = await scanner.scan()
assert results == set()