コード例 #1
0
 def test_07(self):
     """#07 Make sure that an already-authorized path goes unchanged."""
     app = rewrite.WMFRewrite(FakeApp("200 Good", {}), self.a)
     url = self.urlaccount + self.contname + self.objname
     req = webob.Request.blank(url, environ={'REQUEST_METHOD': 'GET'})
     resp = app(req.environ, start_response)
     self.assertEquals(req.url, url)  # should remain unchanged
コード例 #2
0
 def test_03(self):
     """#03 Test URL rewriting for thumbs. """
     app = rewrite.WMFRewrite(FakeApp("200 Good", {}), self.a)
     req = webob.Request.blank(self.thumbbig,
                               environ={'REQUEST_METHOD': 'GET'})
     resp = app(req.environ, start_response)
     self.assertEquals(req.environ['PATH_INFO'], self.url448)
コード例 #3
0
 def test_01a(self):
     """#01a Our app calls into the FakeApp; returns its results if 200 """
     app = rewrite.WMFRewrite(FakeApp("200 Good", {}), self.a)
     req = webob.Request.blank(self.urlbig,
                               environ={'REQUEST_METHOD': 'GET'})
     controller = rewrite.ObjectController()
     resp = app(req.environ, controller.do_start_response)
     self.assertEquals(resp, 'FAKE APP')
コード例 #4
0
 def test_11(self):
     """#11 Trap URLs that don't match the regexp"""
     app = rewrite.WMFRewrite(FakeApp("404 TryRegexp", {}), self.a)
     req = webob.Request.blank("http://localhost/a",
                               environ={'REQUEST_METHOD': 'GET'})
     resp = app(req.environ, start_response)
     self.assertEquals(resp,
             ['400 Bad Request\n\nThe server could not comply with the '\
              'request since it is either malformed or otherwise '\
              'incorrect.\n\n Regexp failed: "/a"  '])
コード例 #5
0
 def test_10(self):
     """#10 Trap weird-ass errors"""
     app = rewrite.WMFRewrite(FakeApp("999 Unrecognized", {}), self.a)
     req = webob.Request.blank("http://localhost/a/b/c",
                               environ={'REQUEST_METHOD': 'GET'})
     resp = app(req.environ, start_response)
     self.assertEquals(resp,
         ['501 Not Implemented\n\nThe server has either erred or is '\
          'incapable of performing the requested operation.\n\n Unknown '\
          'Status: 999  '])
コード例 #6
0
 def test_08(self):
     """#08 Don't let them read the container"""
     app = rewrite.WMFRewrite(FakeApp("200 Good", {}), self.a)
     req = webob.Request.blank(
         'http://alsted.wikimedia.org/wikipedia/commons/',
         environ={'REQUEST_METHOD': 'GET'})
     resp = app(req.environ, start_response)
     self.assertEquals(resp,
         ['403 Forbidden\n\nAccess was denied to this resource.\n\n '\
                 'No container listing  '])
コード例 #7
0
 def test_04(self):
     """#04 Test a write. Could fail if our token has gone stale"""
     app = rewrite.WMFRewrite(FakeApp("404 Bad", {}), self.a)
     req = webob.Request.blank(self.thumbbig,
                               environ={'REQUEST_METHOD': 'GET'})
     resp = app(req.environ, start_response)
     self.assertEquals(req.environ['PATH_INFO'], self.url448)
     # note that we PUT this file onto the server here, even if it's already there.
     datalen = 0
     for data in resp:
         datalen += len(data)
     self.assertEquals(datalen, 51543)
コード例 #8
0
 def test_05(self):
     """#05 Report 401 (authorization) errors"""
     app = rewrite.WMFRewrite(FakeApp("401 Bad", {}), self.a)
     req = webob.Request.blank(self.thumbbig,
                               environ={'REQUEST_METHOD': 'GET'})
     resp = app(req.environ, start_response)
     self.assertEquals(req.environ['PATH_INFO'], self.url448)
     self.assertEquals(resp,
         ['401 Unauthorized\n\nThis server could not verify that you are '\
          'authorized to access the document you requested. Either you '\
          'supplied the wrong credentials (e.g., bad password), or your '\
          'browser does not understand how to supply the credentials '\
          'required.\n\n Token may have timed out  '])
コード例 #9
0
 def test_06(self):
     """#06 Give them a bad token so that the PUT fails."""
     app = rewrite.WMFRewrite(FakeApp("404 Bad", {}), self.a)
     app.token = "HaHaYeahRight"
     req = webob.Request.blank(self.thumbbig,
                               environ={'REQUEST_METHOD': 'GET'})
     resp = app(req.environ, start_response)
     self.assertEquals(req.environ['PATH_INFO'], self.url448)
     # the PUT fails because we give them a bad token, but ... we should
     # really silently just hand back the file.
     try:
         datalen = 0
         for data in resp:
             datalen += len(data)
     except ClientException, x:
         self.assertEquals(datalen, 51543)
         y = "ClientException('Object PUT failed',)"
         self.assertEquals( ` x `, y)