From 18878421eca5beda2bf27e798472480f343ac46e Mon Sep 17 00:00:00 2001 From: "maruel@chromium.org" Date: Tue, 10 Jan 2012 16:45:37 +0000 Subject: [PATCH] Make sure that direct call to SendStack() doesn't send a stack trace for non googler I don't want to receive them even in the case of a direct call to SendStack(). R=dpranke@chromium.org BUG= TEST= Review URL: http://codereview.chromium.org/9145001 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@117039 0039d316-1c4b-4281-b951-d872f2087c98 --- breakpad.py | 17 +++++++++++------ tests/breakpad_unittest.py | 9 ++++++--- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/breakpad.py b/breakpad.py index afe469c6c..6ae5b2361 100644 --- a/breakpad.py +++ b/breakpad.py @@ -1,4 +1,4 @@ -# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# Copyright (c) 2012 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -33,6 +33,12 @@ _TIME_STARTED = time.time() _HOST_NAME = socket.getfqdn() +# Skip unit tests and we don't want anything from non-googler. +IS_ENABLED = ( + not 'test' in getattr(sys.modules['__main__'], '__file__', '') and + not 'NO_BREAKPAD' in os.environ and + _HOST_NAME.endswith(('.google.com', '.chromium.org'))) + def post(url, params): """HTTP POST with timeout when it's supported.""" @@ -75,6 +81,9 @@ def FormatException(e): def SendStack(last_tb, stack, url=None, maxlen=50): """Sends the stack trace to the breakpad server.""" + if not IS_ENABLED: + # Make sure to not send anything for non googler. + return if not url: url = DEFAULT_URL + '/breakpad' print 'Sending crash report ...' @@ -133,11 +142,7 @@ def Register(): atexit.register(CheckForException) -# Skip unit tests and we don't want anything from non-googler. -if (not 'test' in getattr(sys.modules['__main__'], '__file__', '') and - not 'NO_BREAKPAD' in os.environ and - (_HOST_NAME.endswith('.google.com') or - _HOST_NAME.endswith('.chromium.org'))): +if IS_ENABLED: Register() # Uncomment this line if you want to test it out. diff --git a/tests/breakpad_unittest.py b/tests/breakpad_unittest.py index 4d59c0b85..72a7c11ca 100755 --- a/tests/breakpad_unittest.py +++ b/tests/breakpad_unittest.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# Copyright (c) 2012 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -23,20 +23,23 @@ class Breakpad(SuperMoxTestBase): self.mox.StubOutWithMock(breakpad.getpass, 'getuser') self.mox.StubOutWithMock(breakpad.urllib2, 'urlopen') breakpad._HOST_NAME = 'bozo' + self.assertEquals(False, breakpad.IS_ENABLED) + breakpad.IS_ENABLED = True self._old_sys_argv = breakpad.sys.argv breakpad.sys.argv = ['my_test'] self._old_sys_version = breakpad.sys.version breakpad.sys.version = 'random python' def tearDown(self): + breakpad.IS_ENABLED = False breakpad.sys.version = self._old_sys_version breakpad.sys.argv = self._old_sys_argv super(Breakpad, self).tearDown() def testMembersChanged(self): members = [ - 'CheckForException', 'DEFAULT_URL', 'FormatException', 'Register', - 'SendProfiling', 'SendStack', + 'CheckForException', 'DEFAULT_URL', 'FormatException', 'IS_ENABLED', + 'Register', 'SendProfiling', 'SendStack', 'atexit', 'getpass', 'os', 'post', 'socket', 'sys', 'time', 'traceback', 'urllib', 'urllib2', ]