| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 mock | 5 import mock |
| 6 import re | 6 import re |
| 7 import urllib | 7 import urllib |
| 8 | 8 |
| 9 import webapp2 | 9 import webapp2 |
| 10 import webtest | 10 import webtest |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 PermissionLevelHandler.PERMISSION_LEVEL = permission | 102 PermissionLevelHandler.PERMISSION_LEVEL = permission |
| 103 # Simulation of task queue request by setting the header requires admin | 103 # Simulation of task queue request by setting the header requires admin |
| 104 # login. | 104 # login. |
| 105 self._VerifyAuthorizedAccess( | 105 self._VerifyAuthorizedAccess( |
| 106 'test@chromium.org', True, {'X-AppEngine-QueueName': 'task_queue'}) | 106 'test@chromium.org', True, {'X-AppEngine-QueueName': 'task_queue'}) |
| 107 | 107 |
| 108 def testUnknownPermissionLevel(self): | 108 def testUnknownPermissionLevel(self): |
| 109 PermissionLevelHandler.PERMISSION_LEVEL = 80000 # An unknown permission. | 109 PermissionLevelHandler.PERMISSION_LEVEL = 80000 # An unknown permission. |
| 110 self._VerifyUnauthorizedAccess('test@google.com') | 110 self._VerifyUnauthorizedAccess('test@google.com') |
| 111 | 111 |
| 112 def testLoginLinkForGetButForceToUseReferer(self): |
| 113 PermissionLevelHandler.PERMISSION_LEVEL = Permission.CORP_USER |
| 114 PermissionLevelHandler.REDIRECT_TO_DISTINATION_PAGE_FOR_GET = False |
| 115 referer_url = 'http://localhost/referer' |
| 116 login_url = ('https://www.google.com/accounts/Login?continue=%s' % |
| 117 urllib.quote(referer_url)) |
| 118 self.assertRaisesRegexp( |
| 119 webtest.app.AppError, |
| 120 re.compile('.*401 Unauthorized.*%s.*' % re.escape(login_url), |
| 121 re.MULTILINE | re.DOTALL), |
| 122 self.test_app.get, '/permission', headers={'referer': referer_url}) |
| 123 |
| 112 def testLoginLinkForGetWithReferer(self): | 124 def testLoginLinkForGetWithReferer(self): |
| 113 PermissionLevelHandler.PERMISSION_LEVEL = Permission.CORP_USER | 125 PermissionLevelHandler.PERMISSION_LEVEL = Permission.CORP_USER |
| 114 referer_url = 'http://localhost/referer' | 126 referer_url = 'http://localhost/referer' |
| 115 login_url = ('https://www.google.com/accounts/Login?continue=%s' % | 127 login_url = ('https://www.google.com/accounts/Login?continue=%s' % |
| 116 urllib.quote('http://localhost/permission')) | 128 urllib.quote('http://localhost/permission')) |
| 117 self.assertRaisesRegexp( | 129 self.assertRaisesRegexp( |
| 118 webtest.app.AppError, | 130 webtest.app.AppError, |
| 119 re.compile('.*401 Unauthorized.*%s.*' % re.escape(login_url), | 131 re.compile('.*401 Unauthorized.*%s.*' % re.escape(login_url), |
| 120 re.MULTILINE | re.DOTALL), | 132 re.MULTILINE | re.DOTALL), |
| 121 self.test_app.get, '/permission', headers={'referer': referer_url}) | 133 self.test_app.get, '/permission', headers={'referer': referer_url}) |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 app_module = webapp2.WSGIApplication([ | 288 app_module = webapp2.WSGIApplication([ |
| 277 ('/exception', InternalExceptionHandler), | 289 ('/exception', InternalExceptionHandler), |
| 278 ], debug=True) | 290 ], debug=True) |
| 279 | 291 |
| 280 def testInternalException(self): | 292 def testInternalException(self): |
| 281 self.assertRaisesRegexp( | 293 self.assertRaisesRegexp( |
| 282 webtest.app.AppError, | 294 webtest.app.AppError, |
| 283 re.compile('.*500 Internal Server Error.*An internal error occurred.*', | 295 re.compile('.*500 Internal Server Error.*An internal error occurred.*', |
| 284 re.MULTILINE | re.DOTALL), | 296 re.MULTILINE | re.DOTALL), |
| 285 self.test_app.get, '/exception') | 297 self.test_app.get, '/exception') |
| OLD | NEW |