test_unreal_full.py 5.4 KB

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