Skip to content
Open
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
2 changes: 1 addition & 1 deletion app/emu_svc.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
except Exception as e:
error_msg = 'Server error when processing forwarded beacon: %s' % e
self.log.error(error_msg)
raise web.HTTPBadRequest(error_msg)
raise web.HTTPBadRequest(reason=error_msg)
Comment on lines 59 to +62

async def clone_repo(self, repo_url=None):
"""
Expand All @@ -71,7 +71,7 @@

if not os.path.exists(self.repo_dir) or not os.listdir(self.repo_dir):
self.log.debug('cloning repo %s' % repo_url)
check_call(['git', 'clone', '--depth', '1', repo_url, self.repo_dir], stdout=DEVNULL, stderr=STDOUT)

Check failure on line 74 in app/emu_svc.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use an async subprocess call in this async function instead of a synchronous one.

See more on https://sonarcloud.io/project/issues?id=mitre_emu&issues=AZz0whmSQ_2e5Ninb8P3&open=AZz0whmSQ_2e5Ninb8P3&pullRequest=51
self.log.debug('clone complete')

async def populate_data_directory(self, library_path=None):
Expand Down
16 changes: 15 additions & 1 deletion tests/test_emu_svc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import pytest

from pathlib import Path, PosixPath
from unittest.mock import patch, call
from unittest.mock import patch, call, AsyncMock

from aiohttp import web

from app.utility.base_world import BaseWorld
from plugins.emu.app.emu_svc import EmuService
Expand Down Expand Up @@ -242,3 +244,15 @@ def test_register_required_payloads(self, emu_svc):
want = {'payload1', 'payload2', 'payload3'}
emu_svc._register_required_payloads(payloads)
assert emu_svc.required_payloads == want

async def test_handle_forwarded_beacon_bad_json_raises_http_bad_request(self, emu_svc):
"""Regression test: handle_forwarded_beacon must raise HTTPBadRequest with a reason=
keyword argument when the request body is not valid JSON."""
mock_request = AsyncMock()
mock_request.read.return_value = b'not-valid-json'

with pytest.raises(web.HTTPBadRequest) as exc_info:
await emu_svc.handle_forwarded_beacon(mock_request)

assert exc_info.value.reason is not None
assert len(exc_info.value.reason) > 0
Comment on lines +257 to +258
Comment on lines +257 to +258
Loading