test_unreal_full.py 5.3 KB

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