Skip to content

Commit 9c2ab0a

Browse files
committed
test: fix gowitness hardcoded ports and shared home directory
Caught by CI on this PR, not locally: gowitness needs its binary installed, so both classes error out on my machine and never reached the assertions. Two bugs: The multiport test asserted on bare port substrings ('8888' in url) rather than URL-shaped literals, so the earlier rewrites did not match them. On any worker but the first the ports are 9188/10299 and the assertion could never pass. Both classes also pinned an explicit home directory under /tmp and rmtree'd it at class-definition time, which every worker does to the same path. Workers deleted each other's dependency installs mid-run, which is where the FileNotFoundError on the depsinstaller artifact came from. Now worker-scoped. Worth noting these run with deps.behavior=force_install, so each worker installs its own copy of chrome, ~650MB. That is fine on a runner where /tmp is disk-backed, but it multiplies with worker count.
1 parent 5ce87d9 commit 9c2ab0a

1 file changed

Lines changed: 26 additions & 14 deletions

File tree

bbot/test/test_step_2/module_tests/test_module_gowitness.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
from pathlib import Path
22

33
from .base import ModuleTestBase
4-
from bbot.test.worker import HTTPSERVER_HOSTPORT, HTTPSERVER_SSL_URL, HTTPSERVER_URL
4+
from bbot.test.worker import (
5+
worker_dir,
6+
HTTPSERVER_HOSTPORT,
7+
HTTPSERVER_PORT,
8+
HTTPSERVER_SSL_PORT,
9+
HTTPSERVER_SSL_URL,
10+
HTTPSERVER_URL,
11+
)
512

613

714
class TestGowitness(ModuleTestBase):
@@ -10,7 +17,7 @@ class TestGowitness(ModuleTestBase):
1017
import shutil
1118
from pathlib import Path
1219

13-
home_dir = Path("/tmp/.bbot_gowitness_test")
20+
home_dir = worker_dir("/tmp/.bbot_gowitness_test")
1421
shutil.rmtree(home_dir, ignore_errors=True)
1522
config_overrides = {
1623
"deps": {"behavior": "force_install"},
@@ -139,7 +146,7 @@ def check(self, module_test, events):
139146
class TestGowitness_MultiPort(ModuleTestBase):
140147
"""
141148
Integration test: two URLs on the same host with different ports
142-
(HTTP :8888 and HTTPS :9999) both get correctly correlated screenshots.
149+
(one HTTP, one HTTPS) both get correctly correlated screenshots.
143150
Exercises the real gowitness binary and _resolve_parent tiered lookup.
144151
"""
145152

@@ -148,7 +155,7 @@ class TestGowitness_MultiPort(ModuleTestBase):
148155

149156
import shutil
150157

151-
home_dir = Path("/tmp/.bbot_gowitness_multiport_test")
158+
home_dir = worker_dir("/tmp/.bbot_gowitness_multiport_test")
152159
shutil.rmtree(home_dir, ignore_errors=True)
153160
config_overrides = {
154161
"deps": {"behavior": "force_install"},
@@ -157,16 +164,16 @@ class TestGowitness_MultiPort(ModuleTestBase):
157164
}
158165

159166
async def setup_after_prep(self, module_test):
160-
# HTTP server on port 8888
167+
# plain HTTP server
161168
module_test.set_expect_requests(
162169
respond_args={
163-
"response_data": "<html><head><title>Port 8888</title></head><body>Port 8888</body></html>",
170+
"response_data": f"<html><head><title>Port {HTTPSERVER_PORT}</title></head><body>Port {HTTPSERVER_PORT}</body></html>",
164171
"headers": {"Server": "Apache/2.4.41"},
165172
},
166173
)
167-
# HTTPS server on port 9999
174+
# TLS server
168175
module_test.httpserver_ssl.expect_request("/").respond_with_data(
169-
"<html><head><title>Port 9999</title></head><body>Port 9999</body></html>",
176+
f"<html><head><title>Port {HTTPSERVER_SSL_PORT}</title></head><body>Port {HTTPSERVER_SSL_PORT}</body></html>",
170177
headers={"Server": "nginx/1.18.0"},
171178
)
172179

@@ -175,14 +182,19 @@ def check(self, module_test, events):
175182
assert len(webscreenshots) >= 2, f"Expected at least 2 WEBSCREENSHOT events, got {len(webscreenshots)}"
176183

177184
screenshot_urls = {e.data["url"] for e in webscreenshots}
178-
assert any("8888" in url for url in screenshot_urls), f"No screenshot for port 8888. URLs: {screenshot_urls}"
179-
assert any("9999" in url for url in screenshot_urls), f"No screenshot for port 9999. URLs: {screenshot_urls}"
185+
http_port, ssl_port = str(HTTPSERVER_PORT), str(HTTPSERVER_SSL_PORT)
186+
assert any(http_port in url for url in screenshot_urls), (
187+
f"No screenshot for port {http_port}. URLs: {screenshot_urls}"
188+
)
189+
assert any(ssl_port in url for url in screenshot_urls), (
190+
f"No screenshot for port {ssl_port}. URLs: {screenshot_urls}"
191+
)
180192

181193
# Verify parent events reference the correct port
182194
for ws in webscreenshots:
183195
url = ws.data["url"]
184196
parent = ws.parent
185-
if "8888" in url:
186-
assert "8888" in str(parent.data), f"Screenshot for :8888 has wrong parent: {parent.data}"
187-
elif "9999" in url:
188-
assert "9999" in str(parent.data), f"Screenshot for :9999 has wrong parent: {parent.data}"
197+
if http_port in url:
198+
assert http_port in str(parent.data), f"Screenshot for :{http_port} has wrong parent: {parent.data}"
199+
elif ssl_port in url:
200+
assert ssl_port in str(parent.data), f"Screenshot for :{ssl_port} has wrong parent: {parent.data}"

0 commit comments

Comments
 (0)