test_payload_full.py 6.3 KB

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