123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- from __future__ import absolute_import
- import os
- import pytest
- import zipfile
- from mock import patch
- from six import BytesIO
- from django.core.urlresolvers import reverse
- from django.core.files.uploadedfile import SimpleUploadedFile
- from sentry.testutils import TransactionTestCase
- from sentry.models import Event, File, ProjectDebugFile
- from tests.symbolicator import insta_snapshot_stacktrace_data
- REAL_RESOLVING_EVENT_DATA = {
- "platform": "cocoa",
- "debug_meta": {
- "images": [{
- "type": "apple",
- "arch": "x86_64",
- "uuid": "502fc0a5-1ec1-3e47-9998-684fa139dca7",
- "image_vmaddr": "0x0000000100000000",
- "image_size": 4096,
- "image_addr": "0x0000000100000000",
- "name": "Foo.app/Contents/Foo"
- }],
- "sdk_info": {
- "dsym_type": "macho",
- "sdk_name": "macOS",
- "version_major": 10,
- "version_minor": 12,
- "version_patchlevel": 4,
- }
- },
- "exception": {
- "values": [
- {
- 'stacktrace': {
- "frames": [
- {
- "platform": "foobar",
- "function": "hi"
- },
- {
- "function": "unknown",
- "instruction_addr": "0x0000000100000fa0"
- }
- ]
- },
- "type": "Fail",
- "value": "fail"
- }
- ]
- },
- }
- class ResolvingIntegrationTestBase(object):
- def test_real_resolving(self):
- url = reverse(
- 'sentry-api-0-dsym-files',
- kwargs={
- 'organization_slug': self.project.organization.slug,
- 'project_slug': self.project.slug,
- }
- )
- self.login_as(user=self.user)
- out = BytesIO()
- f = zipfile.ZipFile(out, 'w')
- f.write(os.path.join(os.path.dirname(__file__), 'fixtures', 'hello.dsym'),
- 'dSYM/hello')
- f.close()
- response = self.client.post(
- url, {
- 'file':
- SimpleUploadedFile('symbols.zip', out.getvalue(), content_type='application/zip'),
- },
- format='multipart'
- )
- assert response.status_code == 201, response.content
- assert len(response.data) == 1
- resp = self._postWithHeader(dict(project=self.project.id, **REAL_RESOLVING_EVENT_DATA))
- assert resp.status_code == 200
- event = Event.objects.get()
- assert event.data['culprit'] == 'main'
- insta_snapshot_stacktrace_data(self, event.data)
- def test_debug_id_resolving(self):
- file = File.objects.create(
- name='crash.pdb',
- type='default',
- headers={'Content-Type': 'text/x-breakpad'},
- )
- path = os.path.join(os.path.dirname(__file__), 'fixtures', 'windows.sym')
- with open(path) as f:
- file.putfile(f)
- ProjectDebugFile.objects.create(
- file=file,
- object_name='crash.pdb',
- cpu_name='x86',
- project=self.project,
- debug_id='3249d99d-0c40-4931-8610-f4e4fb0b6936-1',
- code_id='5AB380779000',
- )
- self.login_as(user=self.user)
- event_data = {
- 'contexts': {
- 'device': {
- 'arch': 'x86'
- },
- 'os': {
- 'build': u'',
- 'name': 'Windows',
- 'type': 'os',
- 'version': u'10.0.14393'
- }
- },
- 'debug_meta': {
- 'images': [
- {
- 'id': u'3249d99d-0c40-4931-8610-f4e4fb0b6936-1',
- 'image_addr': '0x2a0000',
- 'image_size': 36864,
- 'name': u'C:\\projects\\breakpad-tools\\windows\\Release\\crash.exe',
- 'type': 'symbolic'
- }
- ]
- },
- 'exception': {
- 'stacktrace': {
- 'frames': [
- {
- 'function': '<unknown>',
- 'instruction_addr': '0x2a2a3d',
- 'package': u'C:\\projects\\breakpad-tools\\windows\\Release\\crash.exe'
- }
- ]
- },
- 'thread_id': 1636,
- 'type': u'EXCEPTION_ACCESS_VIOLATION_WRITE',
- 'value': u'Fatal Error: EXCEPTION_ACCESS_VIOLATION_WRITE'
- },
- 'platform': 'native'
- }
- resp = self._postWithHeader(event_data)
- assert resp.status_code == 200
- event = Event.objects.get()
- assert event.data['culprit'] == 'main'
- insta_snapshot_stacktrace_data(self, event.data)
- def test_missing_dsym(self):
- self.login_as(user=self.user)
- resp = self._postWithHeader(dict(project=self.project.id, **REAL_RESOLVING_EVENT_DATA))
- assert resp.status_code == 200
- event = Event.objects.get()
- assert event.data['culprit'] == 'unknown'
- insta_snapshot_stacktrace_data(self, event.data)
- def test_missing_debug_images(self):
- self.login_as(user=self.user)
- payload = dict(project=self.project.id, **REAL_RESOLVING_EVENT_DATA)
- del payload['debug_meta']
- resp = self._postWithHeader(payload)
- assert resp.status_code == 200
- event = Event.objects.get()
- assert event.data['culprit'] == 'unknown'
- insta_snapshot_stacktrace_data(self, event.data)
- class SymbolicatorResolvingIntegrationTest(ResolvingIntegrationTestBase, TransactionTestCase):
- # For these tests to run, write `symbolicator.enabled: true` into your
- # `~/.sentry/config.yml` and run `sentry devservices up`
- @pytest.fixture(autouse=True)
- def initialize(self, live_server):
- new_prefix = live_server.url
- with patch('sentry.auth.system.is_internal_ip', return_value=True), \
- self.options({"system.url-prefix": new_prefix}):
- # Run test case:
- yield
|