Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc Agent Fixes #761

Merged
merged 4 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions bbot/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@ async def ws(self, rebuild=False):
verbs = ("Rebuilding", "Rebuilt")
url = f"{self.url}/control/"
log.debug(f"{verbs[0]} websocket connection to {url}")
self._ws = await websockets.connect(url, **kwargs)
while 1:
try:
self._ws = await websockets.connect(url, **kwargs)
break
except Exception as e:
log.error(f'Failed to establish websockets connection to URL "{url}": {e}')
log.trace(traceback.format_exc())
await asyncio.sleep(1)
log.debug(f"{verbs[1]} websocket connection to {url}")
return self._ws

Expand All @@ -70,6 +77,7 @@ async def start(self):
if message.command == "ping":
if self.scan is None:
await self.send({"conversation": str(message.conversation), "message_type": "pong"})
continue

command_type = getattr(messages, message.command, None)
if command_type is None:
Expand Down Expand Up @@ -115,11 +123,7 @@ async def start_scan(self, scan_id, name=None, targets=[], modules=[], output_mo
f"Starting scan with targets={targets}, modules={modules}, output_modules={output_modules}"
)
output_module_config = OmegaConf.create(
{
"output_modules": {
"websocket": {"url": f"{self.url}/control/scan/{scan_id}/", "token": self.token}
}
}
{"output_modules": {"websocket": {"url": f"{self.url}/scan/{scan_id}/", "token": self.token}}}
)
config = OmegaConf.create(config)
config = OmegaConf.merge(self.config, config, output_module_config)
Expand Down
5 changes: 4 additions & 1 deletion bbot/test/test_step_1/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ async def test_cli(monkeypatch, bbot_config):
task = asyncio.create_task(cli._main())
await asyncio.sleep(2)
task.cancel()
await task
try:
await task
except asyncio.CancelledError:
pass

# no args
monkeypatch.setattr("sys.argv", ["bbot"])
Expand Down