test_unreal_full.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 import EventAttachment, File
  9. from sentry.testutils import RelayStoreHelper, TransactionTestCase
  10. from tests.symbolicator import get_fixture_path
  11. # IMPORTANT:
  12. # For these tests to run, write `symbolicator.enabled: true` into your
  13. # `~/.sentry/config.yml` and run `sentry devservices up`
  14. def get_unreal_crash_file():
  15. return get_fixture_path("unreal_crash")
  16. def get_unreal_crash_apple_file():
  17. return get_fixture_path("unreal_crash_apple")
  18. class SymbolicatorUnrealIntegrationTest(RelayStoreHelper, TransactionTestCase):
  19. # For these tests to run, write `symbolicator.enabled: true` into your
  20. # `~/.sentry/config.yml` and run `sentry devservices up`
  21. # Also running locally, it might be necessary to set the
  22. # `system.internal-url-prefix` option instead of `system.url-prefix`.
  23. @pytest.fixture(autouse=True)
  24. def initialize(self, live_server):
  25. self.project.update_option("sentry:builtin_symbol_sources", [])
  26. new_prefix = live_server.url
  27. with patch("sentry.auth.system.is_internal_ip", return_value=True), self.options(
  28. {"system.url-prefix": new_prefix}
  29. ):
  30. # Run test case:
  31. yield
  32. def upload_symbols(self):
  33. url = reverse(
  34. "sentry-api-0-dsym-files",
  35. kwargs={
  36. "organization_slug": self.project.organization.slug,
  37. "project_slug": self.project.slug,
  38. },
  39. )
  40. self.login_as(user=self.user)
  41. out = BytesIO()
  42. f = zipfile.ZipFile(out, "w")
  43. f.write(get_fixture_path("unreal_crash.sym"), "crash.sym")
  44. f.close()
  45. response = self.client.post(
  46. url,
  47. {
  48. "file": SimpleUploadedFile(
  49. "symbols.zip", out.getvalue(), content_type="application/zip"
  50. )
  51. },
  52. format="multipart",
  53. )
  54. assert response.status_code == 201, response.content
  55. assert len(response.data) == 1
  56. def unreal_crash_test_impl(self, filename):
  57. self.project.update_option("sentry:store_crash_reports", STORE_CRASH_REPORTS_ALL)
  58. self.upload_symbols()
  59. # attachments feature has to be on for the files extract stick around
  60. with self.feature("organizations:event-attachments"):
  61. with open(filename, "rb") as f:
  62. event = self.post_and_retrieve_unreal(f.read())
  63. self.insta_snapshot(
  64. {
  65. "contexts": event.data.get("contexts"),
  66. "exception": event.data.get("exception"),
  67. "stacktrace": event.data.get("stacktrace"),
  68. "threads": event.data.get("threads"),
  69. "extra": event.data.get("extra"),
  70. "sdk": event.data.get("sdk"),
  71. }
  72. )
  73. return sorted(EventAttachment.objects.filter(event_id=event.event_id), key=lambda x: x.name)
  74. def test_unreal_crash_with_attachments(self):
  75. attachments = self.unreal_crash_test_impl(get_unreal_crash_file())
  76. assert len(attachments) == 4
  77. context, config, minidump, log = attachments
  78. assert context.name == "CrashContext.runtime-xml"
  79. context_file = File.objects.get(id=context.file_id)
  80. assert context_file.type == "unreal.context"
  81. assert context_file.checksum == "835d3e10db5d1799dc625132c819c047261ddcfb"
  82. assert config.name == "CrashReportClient.ini"
  83. config_file = File.objects.get(id=config.file_id)
  84. assert config_file.type == "event.attachment"
  85. assert config_file.checksum == "5839c750bdde8cba4d2a979ea857b8154cffdab5"
  86. assert minidump.name == "UE4Minidump.dmp"
  87. minidump_file = File.objects.get(id=minidump.file_id)
  88. assert minidump_file.type == "event.minidump"
  89. assert minidump_file.checksum == "089d9fd3b5c0cc4426339ab46ec3835e4be83c0f"
  90. assert log.name == "YetAnother.log" # Log file is named after the project
  91. log_file = File.objects.get(id=log.file_id)
  92. assert log_file.type == "unreal.logs"
  93. assert log_file.checksum == "24d1c5f75334cd0912cc2670168d593d5fe6c081"
  94. def test_unreal_apple_crash_with_attachments(self):
  95. attachments = self.unreal_crash_test_impl(get_unreal_crash_apple_file())
  96. assert len(attachments) == 6
  97. context, config, diagnostics, log, info, minidump = attachments
  98. assert context.name == "CrashContext.runtime-xml"
  99. context_file = File.objects.get(id=context.file_id)
  100. assert context_file.type == "unreal.context"
  101. assert context_file.checksum == "5d2723a7d25111645702fcbbcb8e1d038db56c6e"
  102. assert config.name == "CrashReportClient.ini"
  103. config_file = File.objects.get(id=config.file_id)
  104. assert config_file.type == "event.attachment"
  105. assert config_file.checksum == "4d6a2736e3e4969a68b7adbe197b05c171c29ea0"
  106. assert diagnostics.name == "Diagnostics.txt"
  107. diagnostics_file = File.objects.get(id=diagnostics.file_id)
  108. assert diagnostics_file.type == "event.attachment"
  109. assert diagnostics_file.checksum == "aa271bf4e307a78005410234081945352e8fb236"
  110. assert log.name == "YetAnotherMac.log" # Log file is named after the project
  111. log_file = File.objects.get(id=log.file_id)
  112. assert log_file.type == "unreal.logs"
  113. assert log_file.checksum == "735e751a8b6b943dbc0abce0e6d096f4d48a0c1e"
  114. assert info.name == "info.txt"
  115. info_file = File.objects.get(id=info.file_id)
  116. assert info_file.type == "event.attachment"
  117. assert info_file.checksum == "279b27ac5d0e6792d088e0662ce1a18413b772bc"
  118. assert minidump.name == "minidump.dmp"
  119. minidump_file = File.objects.get(id=minidump.file_id)
  120. assert minidump_file.type == "event.applecrashreport"
  121. assert minidump_file.checksum == "728d0f4b09cf5a7942da3893b6db79ac842b701a"