Merge branch 'main' into avm99963-monorail

Merged commit 34d8229ae2b51fb1a15bd208e6fe6185c94f6266

GitOrigin-RevId: 7ee0917f93a577e475f8e09526dd144d245593f4
diff --git a/framework/test/monorailrequest_test.py b/framework/test/monorailrequest_test.py
index ef52f1e..0c81694 100644
--- a/framework/test/monorailrequest_test.py
+++ b/framework/test/monorailrequest_test.py
@@ -1,7 +1,6 @@
-# Copyright 2016 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 or at
-# https://developers.google.com/open-source/licenses/bsd
+# Copyright 2016 The Chromium Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
 
 """Unit tests for the monorailrequest module."""
 from __future__ import print_function
@@ -18,17 +17,16 @@
 except ImportError:
   import mox
 import six
+import werkzeug
 
 from google.appengine.api import oauth
 from google.appengine.api import users
 
-import webapp2
-
 from framework import exceptions
 from framework import monorailrequest
 from framework import permissions
-from proto import project_pb2
-from proto import tracker_pb2
+from mrproto import project_pb2
+from mrproto import tracker_pb2
 from services import service_manager
 from testing import fake
 from testing import testing_helpers
@@ -170,14 +168,15 @@
 
   def testGetIntListParam_NoParam(self):
     mr = monorailrequest.MonorailRequest(self.services)
-    mr.ParseRequest(webapp2.Request.blank('servlet'), self.services)
+    mr.ParseRequest(testing_helpers.RequestStub('servlet'), self.services)
     self.assertEqual(mr.GetIntListParam('ids'), None)
     self.assertEqual(mr.GetIntListParam('ids', default_value=['test']),
                       ['test'])
 
   def testGetIntListParam_OneValue(self):
     mr = monorailrequest.MonorailRequest(self.services)
-    mr.ParseRequest(webapp2.Request.blank('servlet?ids=11'), self.services)
+    request = testing_helpers.RequestStub('servlet?ids=11')
+    mr.ParseRequest(request, self.services)
     self.assertEqual(mr.GetIntListParam('ids'), [11])
     self.assertEqual(mr.GetIntListParam('ids', default_value=['test']),
                       [11])
@@ -185,7 +184,7 @@
   def testGetIntListParam_MultiValue(self):
     mr = monorailrequest.MonorailRequest(self.services)
     mr.ParseRequest(
-        webapp2.Request.blank('servlet?ids=21,22,23'), self.services)
+        testing_helpers.RequestStub('servlet?ids=21,22,23'), self.services)
     self.assertEqual(mr.GetIntListParam('ids'), [21, 22, 23])
     self.assertEqual(mr.GetIntListParam('ids', default_value=['test']),
                       [21, 22, 23])
@@ -194,18 +193,18 @@
     mr = monorailrequest.MonorailRequest(self.services)
     with self.assertRaises(exceptions.InputException):
       mr.ParseRequest(
-          webapp2.Request.blank('servlet?ids=not_an_int'), self.services)
+          testing_helpers.RequestStub('servlet?ids=not_an_int'), self.services)
 
   def testGetIntListParam_Malformed(self):
     mr = monorailrequest.MonorailRequest(self.services)
     with self.assertRaises(exceptions.InputException):
       mr.ParseRequest(
-          webapp2.Request.blank('servlet?ids=31,32,,'), self.services)
+          testing_helpers.RequestStub('servlet?ids=31,32,,'), self.services)
 
   def testDefaultValuesNoUrl(self):
     """If request has no param, default param values should be used."""
     mr = monorailrequest.MonorailRequest(self.services)
-    mr.ParseRequest(webapp2.Request.blank('servlet'), self.services)
+    mr.ParseRequest(testing_helpers.RequestStub('servlet'), self.services)
     self.assertEqual(mr.GetParam('r', 3), 3)
     self.assertEqual(mr.GetIntParam('r', 3), 3)
     self.assertEqual(mr.GetPositiveIntParam('r', 3), 3)
@@ -213,7 +212,7 @@
 
   def _MRWithMockRequest(
       self, path, headers=None, *mr_args, **mr_kwargs):
-    request = webapp2.Request.blank(path, headers=headers)
+    request = testing_helpers.RequestStub(path, headers=headers)
     mr = monorailrequest.MonorailRequest(self.services, *mr_args, **mr_kwargs)
     mr.ParseRequest(request, self.services)
     return mr
@@ -282,7 +281,7 @@
         mr.viewed_user_auth.user_pb)
 
   def testViewedUser_NoSuchEmail(self):
-    with self.assertRaises(webapp2.HTTPException) as cm:
+    with self.assertRaises(werkzeug.exceptions.HTTPException) as cm:
       self._MRWithMockRequest('/u/unknownuser@example.com/')
     self.assertEqual(404, cm.exception.code)
 
@@ -353,13 +352,13 @@
 
     # project colspec contains hotlist columns
     mr = testing_helpers.MakeMonorailRequest(
-        path='p/proj/issues/detail?id=123&colspec=Rank Adder Adder Owner')
+        path='/p/proj/issues/detail?id=123&colspec=Rank Adder Adder Owner')
     mr.ComputeColSpec(None)
     self.assertEqual(tracker_constants.DEFAULT_COL_SPEC, mr.col_spec)
 
     # hotlist columns are not deleted when page is a hotlist page
     mr = testing_helpers.MakeMonorailRequest(
-        path='u/jrobbins@example.com/hotlists/TestHotlist?colspec=Rank Adder',
+        path='/u/jrobbins@example.com/hotlists/TestHotlist?colspec=Rank Adder',
         hotlist=self.hotlist)
     mr.ComputeColSpec(None)
     self.assertEqual('Rank Adder', mr.col_spec)
@@ -513,10 +512,13 @@
     self.assertEqual(['Foo-Bar', 'Foo-Bar-Baz', 'Release-1.2', 'Hey', 'There'],
                      parse('Foo-Bar Foo-Bar-Baz Release-1.2 Hey!There'))
     self.assertEqual(
-        ['\xe7\xaa\xbf\xe8\x8b\xa5\xe7\xb9\xb9'.decode('utf-8'),
-         '\xe5\x9f\xba\xe5\x9c\xb0\xe3\x81\xaf'.decode('utf-8')],
-        parse('\xe7\xaa\xbf\xe8\x8b\xa5\xe7\xb9\xb9 '
-              '\xe5\x9f\xba\xe5\x9c\xb0\xe3\x81\xaf'.decode('utf-8')))
+        [
+            b'\xe7\xaa\xbf\xe8\x8b\xa5\xe7\xb9\xb9'.decode('utf-8'),
+            b'\xe5\x9f\xba\xe5\x9c\xb0\xe3\x81\xaf'.decode('utf-8')
+        ],
+        parse(
+            b'\xe7\xaa\xbf\xe8\x8b\xa5\xe7\xb9\xb9 '
+            b'\xe5\x9f\xba\xe5\x9c\xb0\xe3\x81\xaf'.decode('utf-8')))
 
   def testParseColSpec_Dedup(self):
     """An attacker cannot inflate response size by repeating a column."""
@@ -584,7 +586,7 @@
         email=lambda: email))
     self.mox.ReplayAll()
 
-    request = webapp2.Request.blank('/p/' + project_name)
+    request = testing_helpers.RequestStub('/p/' + project_name)
     mr = monorailrequest.MonorailRequest(self.services)
     with mr.profiler.Phase('parse user info'):
       mr.ParseRequest(request, self.services)
@@ -609,7 +611,7 @@
 
   def testExternalUserPermissions_Archived(self):
     mr = self.MakeRequestAsUser('archived', 'user@gmail.com')
-    self.CheckPermissions(mr.perms, False, False, False)
+    self.CheckPermissions(mr.perms, True, False, False)
 
   def testExternalUserPermissions_MembersOnly(self):
     mr = self.MakeRequestAsUser('members-only', 'user@gmail.com')