예제 #1
0
 def testSampleZip(self):
     sample_dir = 'extensions/talking_alarm_clock'
     request = Request.ForTest('extensions/examples/%s.zip' % sample_dir)
     response = RenderServlet(request, _RenderServletDelegate()).Get()
     self.assertEqual(200, response.status)
     self.assertEqual('application/zip',
                      response.headers.get('content-type'))
예제 #2
0
    def Get(self):
        if (not IsDevServer() and not fnmatch(
                urlparse(self._request.host).netloc, '*.appspot.com')):
            # Only allow patches on appspot URLs; it doesn't matter if appspot.com is
            # XSS'ed, but it matters for chrome.com.
            redirect_host = 'https://chrome-apps-doc.appspot.com'
            logging.info('Redirecting from XSS-able host %s to %s' %
                         (self._request.host, redirect_host))
            return Response.Redirect('%s/_patch/%s' %
                                     (redirect_host, self._request.path))

        path_with_issue = self._request.path.lstrip('/')
        if '/' in path_with_issue:
            issue, path_without_issue = path_with_issue.split('/', 1)
        else:
            return Response.NotFound(
                'Malformed URL. It should look like ' +
                'https://developer.chrome.com/_patch/12345/extensions/...')

        try:
            response = RenderServlet(
                Request(path_without_issue, self._request.host,
                        self._request.headers),
                _PatchServletDelegate(issue, self._delegate)).Get()
            # Disable cache for patched content.
            response.headers.pop('cache-control', None)
        except RietveldPatcherError as e:
            response = Response.NotFound(e.message,
                                         {'Content-Type': 'text/plain'})

        redirect_url, permanent = response.GetRedirect()
        if redirect_url is not None:
            response = Response.Redirect(
                '/_patch/%s%s' % (issue, redirect_url), permanent)
        return response
예제 #3
0
 def testStaticFile(self):
     static_file = 'css/site.css'
     request = Request.ForTest('static/%s' % static_file)
     response = RenderServlet(request, _RenderServletDelegate()).Get()
     self.assertEqual(200, response.status)
     self.assertEqual('text/css', response.headers.get('content-type'))
     self.assertEqual(ReadFile('docs/static/%s' % static_file),
                      response.content.ToString())
예제 #4
0
 def testHtmlTemplate(self):
     html_file = 'extensions/storage.html'
     request = Request.ForTest(html_file)
     response = RenderServlet(request, _RenderServletDelegate()).Get()
     self.assertEqual(200, response.status)
     self.assertEqual('text/html', response.headers.get('content-type'))
     # Can't really test rendering all that well.
     self.assertTrue(
         len(response.content) > len(
             ReadFile('docs/templates/public/%s' % html_file)))
예제 #5
0
 def testSampleFile(self):
     sample_file = 'extensions/talking_alarm_clock/background.js'
     request = Request.ForTest('extensions/examples/%s' % sample_file)
     response = RenderServlet(request, _RenderServletDelegate()).Get()
     self.assertEqual(200, response.status)
     content_type = response.headers.get('content-type')
     self.assertTrue(content_type == 'application/javascript'
                     or content_type == 'application/x-javascript')
     self.assertEqual(ReadFile('docs/examples/%s' % sample_file),
                      response.content.ToString())
예제 #6
0
 def run_cron_for_dir(d, path_prefix=''):
     success = True
     start_time = time.time()
     files = [
         f for f in server_instance.content_cache.GetFromFileListing(d)
         if not f.endswith('/')
     ]
     logging.info('cron/%s: rendering %s files from %s...' %
                  (channel, len(files), d))
     try:
         for i, f in enumerate(files):
             error = None
             path = '%s%s' % (path_prefix, f)
             try:
                 response = RenderServlet(
                     Request(path, self._request.headers)).Get(
                         server_instance=server_instance)
                 if response.status != 200:
                     error = 'Got %s response' % response.status
             except DeadlineExceededError:
                 logging.error(
                     'cron/%s: deadline exceeded rendering %s (%s of %s): %s'
                     % (channel, path, i + 1, len(files),
                        traceback.format_exc()))
                 raise
             except error:
                 pass
             if error:
                 logging.error('cron/%s: error rendering %s: %s' %
                               (channel, path, error))
                 success = False
     finally:
         logging.info(
             'cron/%s: rendering %s files from %s took %s seconds' %
             (channel, len(files), d, time.time() - start_time))
     return success
예제 #7
0
 def render_path(path):
   return RenderServlet(Request(path, 'http://localhost', {}),
                        _LocalRenderServletDelegate(),
                        default_channel='trunk').Get()
 def GetConstructor(delegate_for_test=None):
     render_servlet_delegate = InstanceServletRenderServletDelegate(
         delegate_for_test or InstanceServlet.Delegate())
     return lambda request: RenderServlet(request, render_servlet_delegate)
예제 #9
0
 def _Render(self, path):
     return RenderServlet(Request.ForTest(path),
                          _RenderServletDelegate()).Get()
 def get_via_render_servlet(path):
     request = Request(path, self._request.host, self._request.headers)
     delegate = _SingletonRenderServletDelegate(server_instance)
     return RenderServlet(request, delegate).Get()
예제 #11
0
 def _Render(self, path, headers=None):
     return RenderServlet(Request.ForTest(path, headers=headers),
                          _RenderServletDelegate()).Get()
예제 #12
0
 def _RenderWithoutPatch(self, path):
     return RenderServlet(Request.ForTest(path, host=_ALLOWED_HOST),
                          _RenderServletDelegate()).Get()
예제 #13
0
 def testNotFound(self):
     request = Request.ForTest('extensions/not_found.html')
     response = RenderServlet(request, _RenderServletDelegate()).Get()
     self.assertEqual(404, response.status)
예제 #14
0
 def testDefaultChannel(self):
     request = Request.ForTest('stable/extensions/storage.html')
     response = RenderServlet(request, _RenderServletDelegate()).Get()
     self.assertEqual(302, response.status)
예제 #15
0
 def testExtensionAppRedirect(self):
     request = Request.ForTest('storage.html')
     response = RenderServlet(request, _RenderServletDelegate()).Get()
     self.assertEqual(302, response.status)
예제 #16
0
 def testChannelRedirect(self):
     request = Request.ForTest('stable/extensions/storage.html')
     self.assertEqual(
         Response.Redirect('/extensions/storage.html', permanent=True),
         RenderServlet(request, _RenderServletDelegate()).Get())
예제 #17
0
 def Render(path, headers=None):
     assert not '\\' in path
     return RenderServlet(Request.ForTest(path, headers=headers),
                          _LocalRenderServletDelegate()).Get()