Skip to content

Commit e5963f3

Browse files
fixed filedownload tests
1 parent 8171cad commit e5963f3

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

bbot/modules/filedownload.py

+7-11
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,24 @@ class filedownload(BaseModule):
2323
"bashrc", # Bash Script or Configuration
2424
"conf", # Configuration File
2525
"cfg", # Configuration File
26-
"cr2", # Canon RAW Image
2726
"crt", # Certificate File
28-
"crw", # Canon RAW Image (Older Format)
2927
"csv", # Comma Separated Values File
3028
"db", # SQLite Database File
3129
"sqlite", # SQLite Database File
3230
"doc", # Microsoft Word Document (Old Format)
3331
"docx", # Microsoft Word Document
32+
"exe", # Windows PE executable
3433
"ica", # Citrix Independent Computing Architecture File
3534
"indd", # Adobe InDesign Document
3635
"ini", # Initialization File
3736
"jar", # Java Archive
38-
"jpg", # JPEG Image
39-
"jpeg", # JPEG Image
40-
"js", # JavaScript File
4137
"json", # JavaScript Object Notation File
4238
"key", # Private Key File
4339
"pub", # Public Key File
4440
"log", # Log File
45-
"md", # Markdown File
4641
"markdown", # Markdown File
42+
"md", # Markdown File
43+
"msi", # Windows setup file
4744
"odg", # OpenDocument Graphics (LibreOffice, OpenOffice)
4845
"odp", # OpenDocument Presentation (LibreOffice, OpenOffice)
4946
"ods", # OpenDocument Spreadsheet (LibreOffice, OpenOffice)
@@ -60,8 +57,6 @@ class filedownload(BaseModule):
6057
"rdp", # Remote Desktop Protocol File
6158
"sh", # Shell Script
6259
"sql", # SQL Database Dump
63-
"svg", # Scalable Vector Graphics
64-
"svgz", # Compressed SVG
6560
"swp", # Swap File (temporary file, often Vim)
6661
"sxw", # OpenOffice.org Writer document
6762
"tar", # Tar Archive
@@ -154,9 +149,10 @@ def make_filename(self, url, content_type=None):
154149
if not extension:
155150
if content_type and content_type in self.mime_db:
156151
extension = self.mime_db[content_type]
157-
else:
158-
self.debug(f'Extension "{extension}" at url "{url}" not in list of watched extensions.')
159-
return None, None, None
152+
153+
if (not extension) or (extension not in self.extensions):
154+
self.debug(f'Extension "{extension}" at url "{url}" not in list of watched extensions.')
155+
return None, None, None
160156

161157
orig_filename = Path(url_path).stem
162158
if extension:

bbot/test/test_step_2/module_tests/test_module_filedownload.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33

44
class TestFileDownload(ModuleTestBase):
5-
targets = ["http://127.0.0.1:8888/Test_PDF"]
5+
targets = ["http://127.0.0.1:8888"]
66
modules_overrides = ["filedownload", "httpx", "excavate", "speculate"]
7+
config_overrides = {"web_spider_distance": 2, "web_spider_depth": 2}
78

89
pdf_data = """%PDF-1.
910
1 0 obj<</Pages 2 0 R>>endobj
@@ -21,7 +22,10 @@ async def setup_before_prep(self, module_test):
2122

2223
async def setup_after_prep(self, module_test):
2324
module_test.set_expect_requests(
24-
dict(uri="/"), dict(response_data='<a href="/Test_File.txt"/><a href="/Test_PDF"/>')
25+
dict(uri="/"),
26+
dict(
27+
response_data='<a href="/Test_File.txt"/><a href="/Test_PDF"/><a href="/test.html"/><a href="/test2"/>'
28+
),
2529
)
2630
module_test.set_expect_requests(
2731
dict(uri="/Test_File.txt"),
@@ -33,6 +37,14 @@ async def setup_after_prep(self, module_test):
3337
dict(uri="/Test_PDF"),
3438
dict(response_data=self.pdf_data, headers={"Content-Type": "application/pdf"}),
3539
)
40+
module_test.set_expect_requests(
41+
dict(uri="/test.html"),
42+
dict(response_data="<!DOCTYPE html>", headers={"Content-Type": "text/html"}),
43+
)
44+
module_test.set_expect_requests(
45+
dict(uri="/test2"),
46+
dict(response_data="<!DOCTYPE html>", headers={"Content-Type": "text/html"}),
47+
)
3648

3749
def check(self, module_test, events):
3850
download_dir = module_test.scan.home / "filedownload"
@@ -50,3 +62,7 @@ def check(self, module_test, events):
5062
file = pdf_files[0]
5163
assert file.is_file(), f"File not found at {file}"
5264
assert open(file).read() == self.pdf_data, f"File at {file} does not contain the correct content"
65+
66+
# we don't want html files
67+
html_files = list(download_dir.glob("*.html"))
68+
assert len(html_files) == 0, "HTML files were erroneously downloaded"

0 commit comments

Comments
 (0)