test_minidump_full.py 3.3 KB

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