Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Oct 23, 2024
1 parent 51e745a commit 6821a1e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
14 changes: 8 additions & 6 deletions bbot/modules/bufferoverrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@ class BufferOverrun(subdomain_enum_apikey):
base_url = "https://tls.bufferover.run/dns"
commercial_base_url = "https://bufferover-run-tls.p.rapidapi.com/ipv4/dns"

async def setup(self):
self.commercial = self.config.get("commercial", False)
return await super().setup()

def prepare_api_request(self, url, kwargs):
if "x-rapidapi-key" in kwargs["headers"]:
if self.commercial:
kwargs["headers"]["x-rapidapi-host"] = "bufferover-run-tls.p.rapidapi.com"
kwargs["headers"]["x-rapidapi-key"] = self.api_key
else:
kwargs["headers"]["x-api-key"] = self.api_key
return url, kwargs

async def request_url(self, query, commercial=None):
if commercial is None:
commercial = self.options.get("commercial", False)
_, domain = self.helpers.split_domain(query)
url = f"{self.commercial_base_url if commercial else self.base_url}?q=.{domain}"
async def request_url(self, query):
url = f"{self.commercial_base_url if self.commercial else self.base_url}?q=.{query}"
return await self.api_request(url)

def parse_results(self, r, query):
Expand Down
35 changes: 35 additions & 0 deletions bbot/test/test_step_2/module_tests/test_module_bufferoverrun.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from .base import ModuleTestBase


class TestBufferOverrun(ModuleTestBase):
config_overrides = {"modules": {"bufferoverrun": {"api_key": "asdf", "commercial": False}}}

async def setup_before_prep(self, module_test):
# Mock response for non-commercial API
module_test.httpx_mock.add_response(
url="https://tls.bufferover.run/dns?q=.blacklanternsecurity.com",
match_headers={"x-api-key": "asdf"},
json={"Results": ["1.2.3.4,example.com,*,*,sub.blacklanternsecurity.com"]},
)

def check(self, module_test, events):
assert any(e.data == "sub.blacklanternsecurity.com" for e in events), "Failed to detect subdomain for free API"


class TestBufferOverrunCommercial(ModuleTestBase):
modules_overrides = ["bufferoverrun"]
module_name = "bufferoverrun"
config_overrides = {"modules": {"bufferoverrun": {"api_key": "asdf", "commercial": True}}}

async def setup_before_prep(self, module_test):
# Mock response for commercial API
module_test.httpx_mock.add_response(
url="https://bufferover-run-tls.p.rapidapi.com/ipv4/dns?q=.blacklanternsecurity.com",
match_headers={"x-rapidapi-host": "bufferover-run-tls.p.rapidapi.com", "x-rapidapi-key": "asdf"},
json={"Results": ["5.6.7.8,blacklanternsecurity.com,*,*,sub.blacklanternsecurity.com"]},
)

def check(self, module_test, events):
assert any(
e.data == "sub.blacklanternsecurity.com" for e in events
), "Failed to detect subdomain for commercial API"

0 comments on commit 6821a1e

Please sign in to comment.