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'))
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
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())
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)))
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())
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
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)
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()
def _Render(self, path, headers=None): return RenderServlet(Request.ForTest(path, headers=headers), _RenderServletDelegate()).Get()
def _RenderWithoutPatch(self, path): return RenderServlet(Request.ForTest(path, host=_ALLOWED_HOST), _RenderServletDelegate()).Get()
def testNotFound(self): request = Request.ForTest('extensions/not_found.html') response = RenderServlet(request, _RenderServletDelegate()).Get() self.assertEqual(404, response.status)
def testDefaultChannel(self): request = Request.ForTest('stable/extensions/storage.html') response = RenderServlet(request, _RenderServletDelegate()).Get() self.assertEqual(302, response.status)
def testExtensionAppRedirect(self): request = Request.ForTest('storage.html') response = RenderServlet(request, _RenderServletDelegate()).Get() self.assertEqual(302, response.status)
def testChannelRedirect(self): request = Request.ForTest('stable/extensions/storage.html') self.assertEqual( Response.Redirect('/extensions/storage.html', permanent=True), RenderServlet(request, _RenderServletDelegate()).Get())
def Render(path, headers=None): assert not '\\' in path return RenderServlet(Request.ForTest(path, headers=headers), _LocalRenderServletDelegate()).Get()