Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(342)

Unified Diff: appengine/monorail/sitewide/test/moved_test.py

Issue 1868553004: Open Source Monorail (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: appengine/monorail/sitewide/test/moved_test.py
diff --git a/appengine/monorail/sitewide/test/moved_test.py b/appengine/monorail/sitewide/test/moved_test.py
new file mode 100644
index 0000000000000000000000000000000000000000..67e205ddfea9032515e59434d25f179b008eadfd
--- /dev/null
+++ b/appengine/monorail/sitewide/test/moved_test.py
@@ -0,0 +1,65 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is govered by a BSD-style
+# license that can be found in the LICENSE file or at
+# https://developers.google.com/open-source/licenses/bsd
+
+"""Unit tests for the moved project notification page servlet."""
+
+import unittest
+
+import webapp2
+
+from services import service_manager
+from sitewide import moved
+from testing import fake
+from testing import testing_helpers
+
+
+class MovedTest(unittest.TestCase):
+
+ def setUp(self):
+ self.services = service_manager.Services(
+ project=fake.ProjectService())
+ self.servlet = moved.ProjectMoved('req', 'res', services=self.services)
+
+ def testGatherPageData(self):
+ project_name = 'my-project'
+ moved_to = 'http://we-are-outta-here.com/'
+ _request, mr = testing_helpers.GetRequestObjects(
+ path='/hosting/moved?project=my-project')
+
+ try:
+ self.servlet.GatherPageData(mr)
+ self.fail()
+ except webapp2.HTTPException as e:
+ self.assertEquals(404, e.code)
+
+ project = self.services.project.TestAddProject(project_name)
+ # Project exists but has not been moved, so 400 BAD_REQUEST.
+ try:
+ self.servlet.GatherPageData(mr)
+ self.fail()
+ except webapp2.HTTPException as e:
+ self.assertEquals(400, e.code)
+
+ # Display the moved_to url if it is valid.
+ project.moved_to = moved_to
+ page_data = self.servlet.GatherPageData(mr)
+ self.assertItemsEqual(
+ ['project_name', 'moved_to_url'],
+ page_data.keys())
+ self.assertEqual(project_name, page_data['project_name'])
+ self.assertEqual(moved_to, page_data['moved_to_url'])
+
+ # We only display URLs that start with 'http'.
+ project.moved_to = 'javascript:alert(1)'
+ page_data = self.servlet.GatherPageData(mr)
+ self.assertItemsEqual(
+ ['project_name', 'moved_to_url'],
+ page_data.keys())
+ self.assertEqual(project_name, page_data['project_name'])
+ self.assertEqual('#invalid-destination-url', page_data['moved_to_url'])
+
+
+if __name__ == '__main__':
+ unittest.main()
« no previous file with comments | « appengine/monorail/sitewide/test/hostinghome_test.py ('k') | appengine/monorail/sitewide/test/projectcreate_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698