test_unreal_full.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import zipfile
  2. from io import BytesIO
  3. from unittest.mock import patch
  4. import pytest
  5. from django.core.files.uploadedfile import SimpleUploadedFile
  6. from django.urls import reverse
  7. from sentry.lang.native.utils import STORE_CRASH_REPORTS_ALL
  8. from sentry.models.eventattachment import EventAttachment
  9. from sentry.testutils.cases import TransactionTestCase
  10. from sentry.testutils.factories import get_fixture_path
  11. from sentry.testutils.relay import RelayStoreHelper
  12. from sentry.testutils.skips import requires_kafka, requires_symbolicator
  13. from sentry.utils.safe import get_path
  14. from tests.symbolicator import normalize_native_exception
  15. # IMPORTANT:
  16. #
  17. # This test suite requires Symbolicator in order to run correctly.
  18. # Set `symbolicator.enabled: true` in your `~/.sentry/config.yml` and run `sentry devservices up`
  19. #
  20. # If you are using a local instance of Symbolicator, you need to
  21. # either change `system.url-prefix` option override inside `initialize` fixture to `system.internal-url-prefix`,
  22. # or add `127.0.0.1 host.docker.internal` entry to your `/etc/hosts`
  23. pytestmark = [requires_symbolicator, requires_kafka]
  24. def get_unreal_crash_file():
  25. return get_fixture_path("native", "unreal_crash")
  26. def get_unreal_crash_apple_file():
  27. return get_fixture_path("native", "unreal_crash_apple")
  28. class SymbolicatorUnrealIntegrationTest(RelayStoreHelper, TransactionTestCase):
  29. @pytest.fixture(autouse=True)
  30. def initialize(self, live_server):
  31. self.project.update_option("sentry:builtin_symbol_sources", [])
  32. with patch("sentry.auth.system.is_internal_ip", return_value=True), self.options(
  33. {"system.url-prefix": live_server.url}
  34. ):
  35. # Run test case
  36. yield
  37. def upload_symbols(self):
  38. url = reverse(
  39. "sentry-api-0-dsym-files",
  40. kwargs={
  41. "organization_id_or_slug": self.project.organization.slug,
  42. "project_id_or_slug": self.project.slug,
  43. },
  44. )
  45. self.login_as(user=self.user)
  46. out = BytesIO()
  47. f = zipfile.ZipFile(out, "w")
  48. f.write(get_fixture_path("native", "unreal_crash.sym"), "crash.sym")
  49. f.close()
  50. response = self.client.post(
  51. url,
  52. {
  53. "file": SimpleUploadedFile(
  54. "symbols.zip", out.getvalue(), content_type="application/zip"
  55. )
  56. },
  57. format="multipart",
  58. )
  59. assert response.status_code == 201, response.content
  60. assert len(response.json()) == 1
  61. def unreal_crash_test_impl(self, filename):
  62. self.project.update_option("sentry:store_crash_reports", STORE_CRASH_REPORTS_ALL)
  63. self.upload_symbols()
  64. # attachments feature has to be on for the files extract stick around
  65. with self.feature("organizations:event-attachments"):
  66. with open(filename, "rb") as f:
  67. event = self.post_and_retrieve_unreal(f.read())
  68. self.insta_snapshot(
  69. {
  70. "contexts": event.data.get("contexts"),
  71. "exception": {
  72. "values": [
  73. normalize_native_exception(x)
  74. for x in get_path(event.data, "exception", "values") or ()
  75. ]
  76. },
  77. "stacktrace": event.data.get("stacktrace"),
  78. "threads": event.data.get("threads"),
  79. "extra": event.data.get("extra"),
  80. "sdk": event.data.get("sdk"),
  81. }
  82. )
  83. return sorted(EventAttachment.objects.filter(event_id=event.event_id), key=lambda x: x.name)
  84. def test_unreal_crash_with_attachments(self):
  85. attachments = self.unreal_crash_test_impl(get_unreal_crash_file())
  86. assert len(attachments) == 4
  87. context, config, minidump, log = attachments
  88. assert context.name == "CrashContext.runtime-xml"
  89. assert context.sha1 == "835d3e10db5d1799dc625132c819c047261ddcfb"
  90. assert config.name == "CrashReportClient.ini"
  91. assert config.sha1 == "5839c750bdde8cba4d2a979ea857b8154cffdab5"
  92. assert minidump.name == "UE4Minidump.dmp"
  93. assert minidump.sha1 == "089d9fd3b5c0cc4426339ab46ec3835e4be83c0f"
  94. assert log.name == "YetAnother.log" # Log file is named after the project
  95. assert log.sha1 == "24d1c5f75334cd0912cc2670168d593d5fe6c081"
  96. def test_unreal_apple_crash_with_attachments(self):
  97. attachments = self.unreal_crash_test_impl(get_unreal_crash_apple_file())
  98. assert len(attachments) == 6
  99. context, config, diagnostics, log, info, minidump = attachments
  100. assert context.name == "CrashContext.runtime-xml"
  101. assert context.sha1 == "5d2723a7d25111645702fcbbcb8e1d038db56c6e"
  102. assert config.name == "CrashReportClient.ini"
  103. assert config.sha1 == "4d6a2736e3e4969a68b7adbe197b05c171c29ea0"
  104. assert diagnostics.name == "Diagnostics.txt"
  105. assert diagnostics.sha1 == "aa271bf4e307a78005410234081945352e8fb236"
  106. assert log.name == "YetAnotherMac.log" # Log file is named after the project
  107. assert log.sha1 == "735e751a8b6b943dbc0abce0e6d096f4d48a0c1e"
  108. assert info.name == "info.txt"
  109. assert info.sha1 == "279b27ac5d0e6792d088e0662ce1a18413b772bc"
  110. assert minidump.name == "minidump.dmp"
  111. assert minidump.sha1 == "728d0f4b09cf5a7942da3893b6db79ac842b701a"