| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import base64 | 5 import base64 |
| 6 import json | 6 import json |
| 7 import os | 7 import os |
| 8 import re | 8 import re |
| 9 | 9 |
| 10 import webapp2 | 10 import webapp2 |
| 11 import webtest | 11 import webtest |
| 12 | 12 |
| 13 from crash.test.crash_testcase import CrashTestCase | 13 from crash.test.crash_testcase import CrashTestCase |
| 14 from handlers.crash import fracas_crash | 14 from handlers.crash import fracas_crash |
| 15 from model.crash.crash_config import CrashConfig | |
| 16 | 15 |
| 17 | 16 |
| 18 class FracasCrashTest(CrashTestCase): | 17 class FracasCrashTest(CrashTestCase): |
| 19 app_module = webapp2.WSGIApplication([ | 18 app_module = webapp2.WSGIApplication([ |
| 20 ('/crash/fracas', fracas_crash.FracasCrash), | 19 ('/_ah/push-handlers/crash/fracas', fracas_crash.FracasCrash), |
| 21 ], debug=True) | 20 ], debug=True) |
| 22 | 21 |
| 23 def _MockScheduleNewAnalysisForCrash(self, requested_crashes): | 22 def _MockScheduleNewAnalysisForCrash(self, requested_crashes): |
| 24 def Mocked_ScheduleNewAnalysisForCrash(*crash_data, **_): | 23 def Mocked_ScheduleNewAnalysisForCrash(*crash_data, **_): |
| 25 requested_crashes.append(crash_data) | 24 requested_crashes.append(crash_data) |
| 26 self.mock(fracas_crash.fracas_crash_pipeline, 'ScheduleNewAnalysisForCrash', | 25 self.mock(fracas_crash.fracas_crash_pipeline, 'ScheduleNewAnalysisForCrash', |
| 27 Mocked_ScheduleNewAnalysisForCrash) | 26 Mocked_ScheduleNewAnalysisForCrash) |
| 28 | 27 |
| 29 def testUnauthorizedToken(self): | |
| 30 requested_crashes = [] | |
| 31 self._MockScheduleNewAnalysisForCrash(requested_crashes) | |
| 32 self.assertRaisesRegexp( | |
| 33 webtest.app.AppError, | |
| 34 re.compile('.*403.* Unauthorized access: invalid token.*', | |
| 35 re.MULTILINE | re.DOTALL), | |
| 36 self.test_app.post, '/crash/fracas?token=UnauthorizedToken') | |
| 37 self.assertEqual(0, len(requested_crashes)) | |
| 38 | |
| 39 def testAnalysisScheduled(self): | 28 def testAnalysisScheduled(self): |
| 40 requested_crashes = [] | 29 requested_crashes = [] |
| 41 self._MockScheduleNewAnalysisForCrash(requested_crashes) | 30 self._MockScheduleNewAnalysisForCrash(requested_crashes) |
| 31 self.mock_current_user(user_email='test@chromium.org', is_admin=True) |
| 42 | 32 |
| 43 channel = 'supported_channel' | 33 channel = 'supported_channel' |
| 44 platform = 'supported_platform' | 34 platform = 'supported_platform' |
| 45 signature = 'signature/here' | 35 signature = 'signature/here' |
| 46 stack_trace = 'frame1\nframe2\nframe3' | 36 stack_trace = 'frame1\nframe2\nframe3' |
| 47 chrome_version = '50.2500.0.0' | 37 chrome_version = '50.2500.0.0' |
| 48 versions_to_cpm = [['50.2500.0.0']] | 38 versions_to_cpm = [['50.2500.0.0']] |
| 49 | 39 |
| 50 request_json_data = { | 40 request_json_data = { |
| 51 'message': { | 41 'message': { |
| 52 'data': base64.b64encode(json.dumps({ | 42 'data': base64.b64encode(json.dumps({ |
| 53 'channel': channel, | 43 'channel': channel, |
| 54 'platform': platform, | 44 'platform': platform, |
| 55 'signature': signature, | 45 'signature': signature, |
| 56 'stack_trace': stack_trace, | 46 'stack_trace': stack_trace, |
| 57 'chrome_version': chrome_version, | 47 'chrome_version': chrome_version, |
| 58 'versions_to_cpm': versions_to_cpm, | 48 'versions_to_cpm': versions_to_cpm, |
| 59 })), | 49 })), |
| 60 'message_id': 'id', | 50 'message_id': 'id', |
| 61 }, | 51 }, |
| 62 'subscription': 'subscription', | 52 'subscription': 'subscription', |
| 63 } | 53 } |
| 64 | 54 |
| 65 crash_config = CrashConfig.Get() | 55 self.test_app.post_json('/_ah/push-handlers/crash/fracas', |
| 66 token = crash_config.fracas.get('crash_data_push_token') | 56 request_json_data) |
| 67 self.test_app.post_json('/crash/fracas?token=%s' % token, request_json_data) | |
| 68 | 57 |
| 69 self.assertEqual(1, len(requested_crashes)) | 58 self.assertEqual(1, len(requested_crashes)) |
| 70 self.assertEqual( | 59 self.assertEqual( |
| 71 (channel, platform, signature, stack_trace, | 60 (channel, platform, signature, stack_trace, |
| 72 chrome_version, versions_to_cpm), | 61 chrome_version, versions_to_cpm), |
| 73 requested_crashes[0]) | 62 requested_crashes[0]) |
| OLD | NEW |