mirror of
https://github.com/jlengrand/bugsink.git
synced 2026-03-09 23:51:20 +00:00
@@ -418,6 +418,41 @@ class IngestViewTestCase(TransactionTestCase):
|
||||
|
||||
self.assertEqual('SIGABRT: Fatal Error: SIGABRT', Event.objects.get().title())
|
||||
|
||||
@tag("samples")
|
||||
@override_settings(FEATURE_MINIDUMPS=False)
|
||||
def test_envelope_endpoint_minidump_only_when_feature_off(self):
|
||||
# dirty copy/paste from the "feature on" case, with different expectations.
|
||||
project = Project.objects.create(name="test")
|
||||
|
||||
sentry_auth_header = get_header_value(f"http://{ project.sentry_key }@hostisignored/{ project.id }")
|
||||
|
||||
SAMPLES_DIR = os.getenv("SAMPLES_DIR", "../event-samples")
|
||||
|
||||
filename = glob(SAMPLES_DIR + "/minidumps/linux_overflow.dmp")[0] # pick a fixed one for reproducibility
|
||||
with open(filename, 'rb') as f:
|
||||
minidump_bytes = f.read()
|
||||
|
||||
event_id = uuid.uuid4().hex # required at the envelope level so we provide it.
|
||||
|
||||
data_bytes = (
|
||||
b'{"event_id": "%s"}\n' % event_id.encode("utf-8") +
|
||||
b'{"type": "attachment", "attachment_type": "event.minidump", "length": %d}\n' % len(minidump_bytes) +
|
||||
minidump_bytes
|
||||
)
|
||||
|
||||
response = self.client.post(
|
||||
f"/api/{ project.id }/envelope/",
|
||||
content_type="application/json",
|
||||
headers={
|
||||
"X-Sentry-Auth": sentry_auth_header,
|
||||
},
|
||||
data=data_bytes,
|
||||
)
|
||||
self.assertEqual(
|
||||
200, response.status_code, response.content if response.status_code != 302 else response.url)
|
||||
|
||||
self.assertEqual(0, Event.objects.count())
|
||||
|
||||
def test_envelope_endpoint_unsupported_type(self):
|
||||
# dirty copy/paste from the integration test, let's start with "something", we can always clean it later.
|
||||
project = Project.objects.create(name="test")
|
||||
|
||||
@@ -676,9 +676,9 @@ class IngestEnvelopeAPIView(BaseIngestAPIView):
|
||||
item_headers.get("attachment_type") == "event.minidump" and
|
||||
not get_settings().FEATURE_MINIDUMPS)):
|
||||
|
||||
# non-event/minidumps can be discarded; (we don't check for individual size limits, because these differ
|
||||
# per item type, we have the envelope limit to protect us, and we incur almost no cost (NullWriter))
|
||||
return NullWriter()
|
||||
# non-event/minidumps can be discarded; (the somewhat arbitrary size limit is no problem because we have
|
||||
# the envelope limit to protect us, and we incur almost no cost (NullWriter))
|
||||
return MaxDataWriter("MAX_ATTACHMENT_SIZE", NullWriter())
|
||||
|
||||
# envelope_headers["event_id"] is required when type in ["event", "attachment"] per the spec (and takes
|
||||
# precedence over the payload's event_id), so we can rely on it having been set.
|
||||
@@ -714,7 +714,7 @@ class IngestEnvelopeAPIView(BaseIngestAPIView):
|
||||
items_by_type[type_].append(output_stream)
|
||||
|
||||
event_count = len(items_by_type.get("event", []))
|
||||
minidump_count = len(items_by_type.get("attachment", []))
|
||||
minidump_count = len(items_by_type.get("attachment", [])) if get_settings().FEATURE_MINIDUMPS else 0
|
||||
|
||||
if event_count + minidump_count == 0:
|
||||
logger.info("no event or minidump found in envelope, ignoring this envelope.")
|
||||
|
||||
Reference in New Issue
Block a user