test_payload_full.py 6.2 KB

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