Skip to content
This repository has been archived by the owner on Feb 1, 2018. It is now read-only.

Commit

Permalink
bug 866874 - redirect bp- prefix on crash_id
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbe committed Apr 29, 2013
1 parent 9cbc154 commit 5053fb5
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
93 changes: 93 additions & 0 deletions crashstats/crashstats/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2190,6 +2190,99 @@ def mocked_get(url, **options):
ok_('I LOVE CHEESE' in response.content)
ok_('bob@uncle.com' not in response.content)

@mock.patch('requests.post')
@mock.patch('requests.get')
def test_report_index_redirect_by_prefix(self, rget, rpost):

dump = "OS|Mac OS X|10.6.8 10K549\\nCPU|amd64|family 6 mod"
comment0 = "This is a comment"
email0 = "some@emailaddress.com"
url0 = "someaddress.com"
email1 = "some@otheremailaddress.com"

def mocked_get(url, **options):
if '/crash_data/' in url and '/datatype/meta/' in url:
return Response("""
{
"InstallTime": "1339289895",
"FramePoisonSize": "4096",
"Theme": "classic/1.0",
"Version": "5.0a1",
"Email": "%s",
"Vendor": "Mozilla",
"URL": "%s"
}
""" % (email0, url0))
if 'crashes/comments' in url:
return Response("""
{
"hits": [
{
"user_comments": "%s",
"date_processed": "2012-08-21T11:17:28-07:00",
"email": "%s",
"uuid": "469bde48-0e8f-3586-d486-b98810120830"
}
],
"total": 1
}
""" % (comment0, email1))

if '/crash_data/' in url and '/datatype/processed' in url:
return Response("""
{
"client_crash_date": "2012-06-11T06:08:45",
"dump": "%s",
"signature": "FakeSignature1",
"user_comments": null,
"uptime": 14693,
"release_channel": "nightly",
"uuid": "11cb72f5-eb28-41e1-a8e4-849982120611",
"flash_version": "[blank]",
"hangid": null,
"distributor_version": null,
"truncated": true,
"process_type": null,
"id": 383569625,
"os_version": "10.6.8 10K549",
"version": "5.0a1",
"build": "20120609030536",
"ReleaseChannel": "nightly",
"addons_checked": null,
"product": "WaterWolf",
"os_name": "Mac OS X",
"last_crash": 371342,
"date_processed": "2012-06-11T06:08:44",
"cpu_name": "amd64",
"reason": "EXC_BAD_ACCESS / KERN_INVALID_ADDRESS",
"address": "0x8",
"completeddatetime": "2012-06-11T06:08:57",
"success": true
}
""" % dump)

raise NotImplementedError(url)

rget.side_effect = mocked_get

def mocked_post(url, **options):
if '/bugs/' in url:
return Response("""
{"hits": [{"id": "123456789",
"signature": "Something"}]}
""")
raise NotImplementedError(url)

rpost.side_effect = mocked_post

crash_id = (
settings.CRASH_ID_PREFIX + '11cb72f5-eb28-41e1-a8e4-849982120611'
)
assert len(crash_id) > 36
url = reverse('crashstats.report_index', args=[crash_id])
response = self.client.get(url)
eq_(response.status_code, 302)

@mock.patch('requests.post')
@mock.patch('requests.get')
def test_report_list_with_no_data(self, rget, rpost):
Expand Down
12 changes: 12 additions & 0 deletions crashstats/crashstats/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,18 @@ def report_index(request, crash_id):
if not crash_id:
raise http.Http404("Crash id is missing")

# Sometimes, in Socorro we use a prefix on the crash ID. Usually it's
# 'bp-' but this is configurable.
# If you try to use this to reach the perma link for a crash, it should
# redirect to the report index with the correct crash ID.
if crash_id.startswith(settings.CRASH_ID_PREFIX):
crash_id = crash_id.replace(
settings.CRASH_ID_PREFIX,
'',
1
)
return redirect(reverse('crashstats.report_index', args=(crash_id,)))

data = {
'crash_id': crash_id
}
Expand Down
5 changes: 5 additions & 0 deletions crashstats/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,8 @@
'mail=%(mail)s,o=org,dc=mozilla',
'mail=%(mail)s,o=net,dc=mozillacom',
]


# A prefix that is sometimes prefixed on the crash ID when used elsewhere in
# the socorro eco-system.
CRASH_ID_PREFIX = 'bp-'

0 comments on commit 5053fb5

Please sign in to comment.