/** * Sends the given HTTP request * * @param \TYPO3\FLOW3\Http\Request $request * @return \TYPO3\FLOW3\Http\Response * @throws \TYPO3\FLOW3\Http\Exception * @api */ public function sendRequest(Request $request) { $requestHandler = $this->bootstrap->getActiveRequestHandler(); if (!$requestHandler instanceof \TYPO3\FLOW3\Tests\FunctionalTestRequestHandler) { throw new \TYPO3\FLOW3\Http\Exception('The browser\'s internal request engine has only been designed for use within functional tests.', 1335523749); } $response = new Response(); $requestHandler->setHttpRequest($request); $requestHandler->setHttpResponse($response); try { $actionRequest = $this->router->route($request); $this->securityContext->clearContext(); $this->securityContext->injectRequest($actionRequest); $this->dispatcher->dispatch($actionRequest, $response); } catch (\Exception $exception) { $pathPosition = strpos($exception->getFile(), 'Packages/'); $filePathAndName = $pathPosition !== FALSE ? substr($exception->getFile(), $pathPosition) : $exception->getFile(); $exceptionCodeNumber = $exception->getCode() > 0 ? '#' . $exception->getCode() . ': ' : ''; $content = PHP_EOL . 'Uncaught Exception in FLOW3 ' . $exceptionCodeNumber . $exception->getMessage() . PHP_EOL; $content .= 'thrown in file ' . $filePathAndName . PHP_EOL; $content .= 'in line ' . $exception->getLine() . PHP_EOL . PHP_EOL; $content .= \TYPO3\FLOW3\Error\Debugger::getBacktraceCode($exception->getTrace(), FALSE, TRUE) . PHP_EOL; $response->setStatus(500); $response->setContent($content); $response->setHeader('X-FLOW3-ExceptionCode', $exceptionCodeNumber); $response->setHeader('X-FLOW3-ExceptionMessage', $exception->getMessage()); } return $response; }
/** * Adds a CSRF token as argument in ExtDirect requests * * @FLOW3\Around("method(TYPO3\ExtJS\ExtDirect\Transaction->buildRequest()) && setting(TYPO3.FLOW3.security.enable)") * @param \TYPO3\FLOW3\Aop\JoinPointInterface $joinPoint The current join point * @return \TYPO3\FLOW3\Mvc\ActionRequest */ public function transferCsrfTokenToExtDirectRequests(\TYPO3\FLOW3\Aop\JoinPointInterface $joinPoint) { $extDirectRequest = $joinPoint->getAdviceChain()->proceed($joinPoint); $requestHandler = $this->bootstrap->getActiveRequestHandler(); if ($requestHandler instanceof \TYPO3\FLOW3\Http\HttpRequestHandlerInterface) { $arguments = $requestHandler->getHttpRequest()->getArguments(); if (isset($arguments['__csrfToken'])) { $requestArguments = $extDirectRequest->getArguments(); $requestArguments['__csrfToken'] = $arguments['__csrfToken']; $extDirectRequest->setArguments($requestArguments); } } return $extDirectRequest; }
/** * Initializes the context after all dependencies have been injected. * * @return void */ public function initializeObject() { $this->locale = new Locale('mul_ZZ'); $activeRequestHandler = $this->bootstrap->getActiveRequestHandler(); if ($activeRequestHandler instanceof \TYPO3\FLOW3\Http\HttpRequestHandlerInterface) { $matchingDomains = $this->domainRepository->findByHost($activeRequestHandler->getHttpRequest()->getUri()->getHost()); if (count($matchingDomains) > 0) { $this->currentDomain = $matchingDomains[0]; $this->currentSite = $matchingDomains[0]->getSite(); } else { $this->currentSite = $this->siteRepository->findFirst(); } } else { $this->currentSite = $this->siteRepository->findFirst(); } }
/** * Detects the (resources) base URI and stores it as a protected class variable. * * $this->resourcesPublishingPath must be set prior to calling this method. * * @return void */ protected function detectResourcesBaseUri() { $requestHandler = $this->bootstrap->getActiveRequestHandler(); if ($requestHandler instanceof \TYPO3\FLOW3\Http\HttpRequestHandlerInterface) { $uri = $requestHandler->getHttpRequest()->getBaseUri(); } else { $uri = ''; } $this->resourcesBaseUri = $uri . substr($this->resourcesPublishingPath, strlen(FLOW3_PATH_WEB)); }
/** * Sets up a virtual browser and web environment for seamless HTTP and MVC * related tests. * * @return void */ protected function setupHttp() { $_GET = array(); $_POST = array(); $_COOKIE = array(); $_FILES = array(); $_SERVER = array('REDIRECT_FLOW3_CONTEXT' => 'Development', 'REDIRECT_FLOW3_REWRITEURLS' => '1', 'REDIRECT_STATUS' => '200', 'FLOW3_CONTEXT' => 'Testing', 'FLOW3_REWRITEURLS' => '1', 'HTTP_HOST' => 'localhost', 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/534.52.7 (KHTML, like Gecko) Version/5.1.2 Safari/534.52.7', 'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'HTTP_ACCEPT_LANGUAGE' => 'en-us', 'HTTP_ACCEPT_ENCODING' => 'gzip, deflate', 'HTTP_CONNECTION' => 'keep-alive', 'PATH' => '/usr/bin:/bin:/usr/sbin:/sbin', 'SERVER_SIGNATURE' => '', 'SERVER_SOFTWARE' => 'Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/1.0.0e DAV/2 PHP/5.3.8', 'SERVER_NAME' => 'localhost', 'SERVER_ADDR' => '127.0.0.1', 'SERVER_PORT' => '80', 'REMOTE_ADDR' => '127.0.0.1', 'DOCUMENT_ROOT' => '/opt/local/apache2/htdocs/', 'SERVER_ADMIN' => 'george@localhost', 'SCRIPT_FILENAME' => '/opt/local/apache2/htdocs/Web/index.php', 'REMOTE_PORT' => '51439', 'REDIRECT_QUERY_STRING' => '', 'REDIRECT_URL' => '', 'GATEWAY_INTERFACE' => 'CGI/1.1', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'REQUEST_METHOD' => 'GET', 'QUERY_STRING' => '', 'REQUEST_URI' => '', 'SCRIPT_NAME' => '/index.php', 'PHP_SELF' => '/index.php', 'REQUEST_TIME' => 1326472534); $this->browser = new \TYPO3\FLOW3\Http\Client\Browser(); $this->router = $this->browser->getRequestEngine()->getRouter(); $requestHandler = self::$bootstrap->getActiveRequestHandler(); $requestHandler->setHttpRequest(\TYPO3\FLOW3\Http\Request::create(new \TYPO3\FLOW3\Http\Uri('http://localhost'))); }