test_payload_full.py 6.4 KB

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