test_payload_full.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. from __future__ import absolute_import
  2. import pytest
  3. import zipfile
  4. from sentry.utils.compat.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 import eventstore
  9. from sentry.testutils import TransactionTestCase, RelayStoreHelper
  10. from sentry.models import File, ProjectDebugFile
  11. from sentry.testutils.helpers.datetime import iso_format, before_now
  12. from tests.symbolicator import get_fixture_path, insta_snapshot_stacktrace_data
  13. # IMPORTANT:
  14. # For these tests to run, write `symbolicator.enabled: true` into your
  15. # `~/.sentry/config.yml` and run `sentry devservices up`
  16. REAL_RESOLVING_EVENT_DATA = {
  17. "platform": "cocoa",
  18. "debug_meta": {
  19. "images": [
  20. {
  21. "type": "apple",
  22. "arch": "x86_64",
  23. "uuid": "502fc0a5-1ec1-3e47-9998-684fa139dca7",
  24. "image_vmaddr": "0x0000000100000000",
  25. "image_size": 4096,
  26. "image_addr": "0x0000000100000000",
  27. "name": "Foo.app/Contents/Foo",
  28. }
  29. ],
  30. "sdk_info": {
  31. "dsym_type": "macho",
  32. "sdk_name": "macOS",
  33. "version_major": 10,
  34. "version_minor": 12,
  35. "version_patchlevel": 4,
  36. },
  37. },
  38. "exception": {
  39. "values": [
  40. {
  41. "stacktrace": {
  42. "frames": [
  43. {"platform": "foobar", "function": "hi"},
  44. {"function": "unknown", "instruction_addr": "0x0000000100000fa0"},
  45. ]
  46. },
  47. "type": "Fail",
  48. "value": "fail",
  49. }
  50. ]
  51. },
  52. "timestamp": iso_format(before_now(seconds=1)),
  53. }
  54. class SymbolicatorResolvingIntegrationTest(RelayStoreHelper, TransactionTestCase):
  55. # For these tests to run, write `symbolicator.enabled: true` into your
  56. # `~/.sentry/config.yml` and run `sentry devservices up`
  57. @pytest.fixture(autouse=True)
  58. def initialize(self, live_server):
  59. self.project.update_option("sentry:builtin_symbol_sources", [])
  60. new_prefix = live_server.url
  61. with patch("sentry.auth.system.is_internal_ip", return_value=True), self.options(
  62. {"system.url-prefix": new_prefix}
  63. ):
  64. # Run test case:
  65. yield
  66. def get_event(self, event_id):
  67. return eventstore.get_event_by_id(self.project.id, event_id)
  68. def test_real_resolving(self):
  69. url = reverse(
  70. "sentry-api-0-dsym-files",
  71. kwargs={
  72. "organization_slug": self.project.organization.slug,
  73. "project_slug": self.project.slug,
  74. },
  75. )
  76. self.login_as(user=self.user)
  77. out = BytesIO()
  78. f = zipfile.ZipFile(out, "w")
  79. f.write(get_fixture_path("hello.dsym"), "dSYM/hello")
  80. f.close()
  81. response = self.client.post(
  82. url,
  83. {
  84. "file": SimpleUploadedFile(
  85. "symbols.zip", out.getvalue(), content_type="application/zip"
  86. )
  87. },
  88. format="multipart",
  89. )
  90. assert response.status_code == 201, response.content
  91. assert len(response.data) == 1
  92. event = self.post_and_retrieve_event(REAL_RESOLVING_EVENT_DATA)
  93. assert event.data["culprit"] == "main"
  94. insta_snapshot_stacktrace_data(self, event.data)
  95. def test_debug_id_resolving(self):
  96. file = File.objects.create(
  97. name="crash.pdb", type="default", headers={"Content-Type": "text/x-breakpad"}
  98. )
  99. path = get_fixture_path("windows.sym")
  100. with open(path, "rb") as f:
  101. file.putfile(f)
  102. ProjectDebugFile.objects.create(
  103. file=file,
  104. object_name="crash.pdb",
  105. cpu_name="x86",
  106. project=self.project,
  107. debug_id="3249d99d-0c40-4931-8610-f4e4fb0b6936-1",
  108. code_id="5AB380779000",
  109. )
  110. self.login_as(user=self.user)
  111. event_data = {
  112. "contexts": {
  113. "device": {"arch": "x86"},
  114. "os": {"build": u"", "name": "Windows", "type": "os", "version": u"10.0.14393"},
  115. },
  116. "debug_meta": {
  117. "images": [
  118. {
  119. "id": u"3249d99d-0c40-4931-8610-f4e4fb0b6936-1",
  120. "image_addr": "0x2a0000",
  121. "image_size": 36864,
  122. "name": u"C:\\projects\\breakpad-tools\\windows\\Release\\crash.exe",
  123. "type": "symbolic",
  124. }
  125. ]
  126. },
  127. "exception": {
  128. "stacktrace": {
  129. "frames": [
  130. {
  131. "function": "<unknown>",
  132. "instruction_addr": "0x2a2a3d",
  133. "package": u"C:\\projects\\breakpad-tools\\windows\\Release\\crash.exe",
  134. }
  135. ]
  136. },
  137. "thread_id": 1636,
  138. "type": u"EXCEPTION_ACCESS_VIOLATION_WRITE",
  139. "value": u"Fatal Error: EXCEPTION_ACCESS_VIOLATION_WRITE",
  140. },
  141. "platform": "native",
  142. "timestamp": iso_format(before_now(seconds=1)),
  143. }
  144. event = self.post_and_retrieve_event(event_data)
  145. assert event.data["culprit"] == "main"
  146. insta_snapshot_stacktrace_data(self, event.data)
  147. def test_missing_dsym(self):
  148. self.login_as(user=self.user)
  149. event = self.post_and_retrieve_event(REAL_RESOLVING_EVENT_DATA)
  150. assert event.data["culprit"] == "unknown"
  151. insta_snapshot_stacktrace_data(self, event.data)
  152. def test_missing_debug_images(self):
  153. self.login_as(user=self.user)
  154. payload = dict(project=self.project.id, **REAL_RESOLVING_EVENT_DATA)
  155. del payload["debug_meta"]
  156. event = self.post_and_retrieve_event(payload)
  157. assert event.data["culprit"] == "unknown"
  158. insta_snapshot_stacktrace_data(self, event.data)