test_minidump_full.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. from __future__ import absolute_import
  2. import pytest
  3. import zipfile
  4. from mock import patch
  5. from six import BytesIO
  6. from django.core.urlresolvers import reverse
  7. from django.core.files.uploadedfile import SimpleUploadedFile
  8. from sentry.testutils import TransactionTestCase
  9. from sentry.models import Event, EventAttachment
  10. from tests.symbolicator import get_fixture_path, insta_snapshot_stacktrace_data
  11. class SymbolicatorMinidumpIntegrationTest(TransactionTestCase):
  12. # For these tests to run, write `symbolicator.enabled: true` into your
  13. # `~/.sentry/config.yml` and run `sentry devservices up`
  14. @pytest.fixture(autouse=True)
  15. def initialize(self, live_server):
  16. self.project.update_option('sentry:builtin_symbol_sources', [])
  17. new_prefix = live_server.url
  18. with patch('sentry.auth.system.is_internal_ip', return_value=True), \
  19. self.options({"system.url-prefix": new_prefix}):
  20. # Run test case:
  21. yield
  22. def upload_symbols(self):
  23. url = reverse(
  24. 'sentry-api-0-dsym-files',
  25. kwargs={
  26. 'organization_slug': self.project.organization.slug,
  27. 'project_slug': self.project.slug,
  28. }
  29. )
  30. self.login_as(user=self.user)
  31. out = BytesIO()
  32. f = zipfile.ZipFile(out, 'w')
  33. f.write(get_fixture_path('windows.sym'), 'crash.sym')
  34. f.close()
  35. response = self.client.post(
  36. url, {
  37. 'file':
  38. SimpleUploadedFile('symbols.zip', out.getvalue(), content_type='application/zip'),
  39. },
  40. format='multipart'
  41. )
  42. assert response.status_code == 201, response.content
  43. assert len(response.data) == 1
  44. def test_full_minidump(self):
  45. self.project.update_option('sentry:store_crash_reports', True)
  46. self.upload_symbols()
  47. with self.feature('organizations:event-attachments'):
  48. attachment = BytesIO(b'Hello World!')
  49. attachment.name = 'hello.txt'
  50. with open(get_fixture_path('windows.dmp'), 'rb') as f:
  51. resp = self._postMinidumpWithHeader(f, {
  52. 'sentry[logger]': 'test-logger',
  53. 'some_file': attachment,
  54. })
  55. assert resp.status_code == 200
  56. event = Event.objects.get()
  57. insta_snapshot_stacktrace_data(self, event.data)
  58. attachments = sorted(
  59. EventAttachment.objects.filter(
  60. event_id=event.event_id),
  61. key=lambda x: x.name)
  62. hello, minidump = attachments
  63. assert hello.name == 'hello.txt'
  64. assert hello.file.type == 'event.attachment'
  65. assert hello.file.checksum == '2ef7bde608ce5404e97d5f042f95f89f1c232871'
  66. assert minidump.name == 'windows.dmp'
  67. assert minidump.file.type == 'event.minidump'
  68. assert minidump.file.checksum == '74bb01c850e8d65d3ffbc5bad5cabc4668fce247'
  69. def test_raw_minidump(self):
  70. self.project.update_option('sentry:store_crash_reports', True)
  71. self.upload_symbols()
  72. with self.feature('organizations:event-attachments'):
  73. with open(get_fixture_path('windows.dmp'), 'rb') as f:
  74. # Send as raw request body instead of multipart/form-data
  75. resp = self._postMinidumpWithHeader(f, raw=True)
  76. assert resp.status_code == 200
  77. event = Event.objects.get()
  78. insta_snapshot_stacktrace_data(self, event.data)
  79. def test_missing_dsym(self):
  80. with self.feature('organizations:event-attachments'):
  81. with open(get_fixture_path('windows.dmp'), 'rb') as f:
  82. resp = self._postMinidumpWithHeader(f, {
  83. 'sentry[logger]': 'test-logger',
  84. })
  85. assert resp.status_code == 200
  86. event = Event.objects.get()
  87. insta_snapshot_stacktrace_data(self, event.data)
  88. assert not EventAttachment.objects.filter(event_id=event.event_id)