/** * @return void */ public function setUp() { $this->viewHelperVariableContainer = $this->getMock('TYPO3\\Fluid\\Core\\ViewHelper\\ViewHelperVariableContainer'); $this->viewHelperVariableContainer->expects($this->any())->method('exists')->will($this->returnCallback(array($this, 'viewHelperVariableContainerExistsCallback'))); $this->viewHelperVariableContainer->expects($this->any())->method('get')->will($this->returnCallback(array($this, 'viewHelperVariableContainerGetCallback'))); $this->templateVariableContainer = $this->getMock('TYPO3\\Fluid\\Core\\ViewHelper\\TemplateVariableContainer'); $this->uriBuilder = $this->getMock('TYPO3\\Flow\\Mvc\\Routing\\UriBuilder'); $this->uriBuilder->expects($this->any())->method('reset')->will($this->returnValue($this->uriBuilder)); $this->uriBuilder->expects($this->any())->method('setArguments')->will($this->returnValue($this->uriBuilder)); $this->uriBuilder->expects($this->any())->method('setSection')->will($this->returnValue($this->uriBuilder)); $this->uriBuilder->expects($this->any())->method('setFormat')->will($this->returnValue($this->uriBuilder)); $this->uriBuilder->expects($this->any())->method('setCreateAbsoluteUri')->will($this->returnValue($this->uriBuilder)); $this->uriBuilder->expects($this->any())->method('setAddQueryString')->will($this->returnValue($this->uriBuilder)); $this->uriBuilder->expects($this->any())->method('setArgumentsToBeExcludedFromQueryString')->will($this->returnValue($this->uriBuilder)); // BACKPORTER TOKEN #1 $httpRequest = \TYPO3\Flow\Http\Request::create(new \TYPO3\Flow\Http\Uri('http://localhost/foo')); $this->request = $this->getMock('TYPO3\\Flow\\Mvc\\ActionRequest', array(), array($httpRequest)); $this->request->expects($this->any())->method('isMainRequest')->will($this->returnValue(TRUE)); $this->controllerContext = $this->getMock('TYPO3\\Flow\\Mvc\\Controller\\ControllerContext', array(), array(), '', FALSE); $this->controllerContext->expects($this->any())->method('getUriBuilder')->will($this->returnValue($this->uriBuilder)); $this->controllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($this->request)); $this->tagBuilder = $this->getMock('TYPO3\\Fluid\\Core\\ViewHelper\\TagBuilder'); $this->arguments = array(); $this->renderingContext = new \TYPO3\Fluid\Core\Rendering\RenderingContext(); $this->renderingContext->injectTemplateVariableContainer($this->templateVariableContainer); $this->renderingContext->injectViewHelperVariableContainer($this->viewHelperVariableContainer); $this->renderingContext->setControllerContext($this->controllerContext); }
/** * @dataProvider uriAndHostPatterns * @test */ public function requestMatchingBasicallyWorks($uri, $pattern, $expected, $message) { $request = Request::create(new \TYPO3\Flow\Http\Uri($uri))->createActionRequest(); $requestPattern = new \TYPO3\Flow\Security\RequestPattern\Host(); $requestPattern->setPattern($pattern); $this->assertEquals($expected, $requestPattern->matchRequest($request), $message); }
/** * @test */ public function dispatchContinuesWithNextRequestFoundInAForwardException() { $httpRequest = Request::create(new Uri('http://localhost')); $httpResponse = new Response(); $mainRequest = $httpRequest->createActionRequest(); $subRequest = new ActionRequest($mainRequest); $nextRequest = $httpRequest->createActionRequest(); $mainRequest->setDispatched(TRUE); $mainRequest->setControllerSubPackageKey('main'); $subRequest->setControllerSubPackageKey('sub'); $nextRequest->setControllerSubPackageKey('next'); $mockController = $this->getMock('TYPO3\\Flow\\Mvc\\Controller\\ControllerInterface', array('processRequest')); $mockController->expects($this->at(0))->method('processRequest')->will($this->returnCallback(function (ActionRequest $request) use($nextRequest) { $request->setDispatched(TRUE); $forwardException = new ForwardException(); $forwardException->setNextRequest($nextRequest); throw $forwardException; })); $mockController->expects($this->at(1))->method('processRequest')->will($this->returnCallback(function (ActionRequest $request) use($nextRequest) { // NOTE: PhpUnit creates a clone of $nextRequest, thus $request is not the same instance as expected. if ($request == $nextRequest) { $nextRequest->setDispatched(TRUE); } })); $dispatcher = $this->getMock('TYPO3\\Flow\\Mvc\\Dispatcher', array('resolveController', 'emitAfterControllerInvocation'), array(), '', FALSE); $dispatcher->expects($this->any())->method('resolveController')->will($this->returnValue($mockController)); $dispatcher->dispatch($subRequest, $httpResponse); }
/** * @test */ public function updateCredentialsSetsTheCorrectAuthenticationStatusIfNoCredentialsArrived() { $httpRequest = Request::create(new Uri('http://foo.com')); $mockActionRequest = $this->getMockBuilder(\TYPO3\Flow\Mvc\ActionRequest::class)->disableOriginalConstructor()->getMock(); $mockActionRequest->expects($this->atLeastOnce())->method('getHttpRequest')->will($this->returnValue($httpRequest)); $this->token->updateCredentials($mockActionRequest); $this->assertSame(TokenInterface::NO_CREDENTIALS_GIVEN, $this->token->getAuthenticationStatus()); }
/** * @test */ public function updateCredentialsSetsTheCorrectAuthenticationStatusIfNoCredentialsArrived() { $request = Request::create(new Uri('http://foo.com')); $actionRequest = $request->createActionRequest(); $token = new UsernamePasswordHttpBasic(); $token->updateCredentials($actionRequest); $this->assertSame(TokenInterface::NO_CREDENTIALS_GIVEN, $token->getAuthenticationStatus()); }
/** * Create a mock controllerContext * * @return \PHPUnit_Framework_MockObject_MockObject */ protected function getMockControllerContext() { $httpRequest = Request::create(new Uri('http://robertlemke.com/blog')); $mockRequest = $this->getMockBuilder(\TYPO3\Flow\Mvc\ActionRequest::class)->setConstructorArgs(array($httpRequest))->getMock(); $mockRequest->expects($this->any())->method('getControllerPackageKey')->will($this->returnValue('Acme.Demo')); $mockControllerContext = $this->getMockBuilder(\TYPO3\Flow\Mvc\Controller\ControllerContext::class)->setMethods(array('getRequest'))->disableOriginalConstructor()->getMock(); $mockControllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($mockRequest)); return $mockControllerContext; }
/** * @test */ public function requestMatchingBasicallyWorks() { $uri = new \TYPO3\Flow\Http\Uri('http://typo3.org/some/nice/path/to/index.php'); $request = Request::create($uri)->createActionRequest(); $requestPattern = new \TYPO3\Flow\Security\RequestPattern\Uri(); $requestPattern->setPattern('/some/nice/.*'); $this->assertEquals('/some/nice/.*', $requestPattern->getPattern()); $this->assertTrue($requestPattern->matchRequest($request)); }
/** * Create a mock controllerContext * * @return \PHPUnit_Framework_MockObject_MockObject */ protected function getMockControllerContext() { $httpRequest = Request::create(new Uri('http://robertlemke.com/blog')); $mockRequest = $this->getMock(\TYPO3\Flow\Mvc\ActionRequest::class, array(), array($httpRequest)); $mockRequest->expects($this->any())->method('getControllerPackageKey')->will($this->returnValue('Acme.Demo')); $mockControllerContext = $this->getMock(\TYPO3\Flow\Mvc\Controller\ControllerContext::class, array('getRequest'), array(), '', false); $mockControllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($mockRequest)); return $mockControllerContext; }
/** * Create a mock controllerContext * * @return \PHPUnit_Framework_MockObject_MockObject */ protected function getMockControllerContext() { $httpRequest = \TYPO3\Flow\Http\Request::create(new \TYPO3\Flow\Http\Uri('http://robertlemke.com/blog')); $mockRequest = $this->getMock('TYPO3\\Flow\\Mvc\\ActionRequest', array(), array($httpRequest)); $mockRequest->expects($this->any())->method('getControllerPackageKey')->will($this->returnValue('TYPO3.Fluid')); $mockControllerContext = $this->getMock('TYPO3\\Flow\\Mvc\\Controller\\ControllerContext', array('getRequest'), array(), '', FALSE); $mockControllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($mockRequest)); return $mockControllerContext; }
/** * @param string $payload * @param string $uri * @return Request */ protected function createRegistrationRequest($payload, $uri = self::ENDPOINT) { $request = Request::create(new Uri($uri)); $request->setMethod('POST'); $request->setHeader('Content-Type', 'application/json'); $request->setHeader('Accept', 'application/json'); $request->setContent($payload); return $request; }
/** * @test */ public function renderEscapesBaseUri() { $baseUri = new Uri('<some nasty uri>'); $this->request->expects($this->any())->method('getHttpRequest')->will($this->returnValue(Request::create($baseUri))); $viewHelper = new BaseViewHelper(); $this->injectDependenciesIntoViewHelper($viewHelper); $expectedResult = '<base href="http://' . htmlspecialchars($baseUri) . '/" />'; $actualResult = $viewHelper->render(); $this->assertSame($expectedResult, $actualResult); }
/** * @test */ public function renderTakesBaseUriFromControllerContext() { $baseUri = new \TYPO3\Flow\Http\Uri('http://typo3.org/'); $this->request->expects($this->any())->method('getHttpRequest')->will($this->returnValue(\TYPO3\Flow\Http\Request::create($baseUri))); $viewHelper = new \TYPO3\Fluid\ViewHelpers\BaseViewHelper(); $this->injectDependenciesIntoViewHelper($viewHelper); $expectedResult = '<base href="' . $baseUri . '" />'; $actualResult = $viewHelper->render(); $this->assertSame($expectedResult, $actualResult); }
/** * @test * @dataProvider exampleTemplates */ public function templateIsEvaluatedCorrectly($source, $variables, $expected) { $request = Request::create(new Uri('http://localhost')); $actionRequest = $request->createActionRequest(); $standaloneView = new \TYPO3\Fluid\Tests\Functional\View\Fixtures\View\StandaloneView($actionRequest, uniqid()); $standaloneView->assignMultiple($variables); $standaloneView->setTemplateSource($source); $actual = $standaloneView->render(); $this->assertSame($expected, $actual); }
/** * @test */ public function actionRequestDoesNotStripParentActionRequest() { $httpRequest = Request::create(new Uri('http://typo3.org')); $parentActionRequest = new ActionRequest($httpRequest); $actionRequest = new ActionRequest($parentActionRequest); $serializedActionRequest = serialize($actionRequest); /* @var $unserializedActionRequest ActionRequest */ $unserializedActionRequest = unserialize($serializedActionRequest); $this->assertNotNull($unserializedActionRequest->getParentRequest(), 'Parent action request should not be NULL after deserialization'); }
/** * @param string $resource * @param string $method * @return \TYPO3\Flow\Http\Response */ public function query($resource, $method = 'GET') { $uri = new Uri($this->endpoint . $resource); parse_str((string) $uri->getQuery(), $query); $query['access_token'] = $this->currentAccessToken; $query['appsecret_proof'] = hash_hmac('sha256', $this->currentAccessToken, $this->appSecret); $uri->setQuery(http_build_query($query)); $request = Request::create($uri, $method); $response = $this->requestEngine->sendRequest($request); return $response; }
/** * @test */ public function tokenCanBeCastToString() { $arguments = array(); $arguments['__authentication']['TYPO3']['Flow']['Security']['Authentication']['Token']['UsernamePassword']['username'] = '******'; $arguments['__authentication']['TYPO3']['Flow']['Security']['Authentication']['Token']['UsernamePassword']['password'] = '******'; $request = Request::create(new Uri('http://robertlemke.com/login'), 'POST', $arguments); $actionRequest = $request->createActionRequest(); $token = new UsernamePassword(); $token->updateCredentials($actionRequest); $this->assertEquals('Username: "******"', (string) $token); }
/** * @test */ public function initializeControllerInitializesRequestUriBuilderArgumentsAndContext() { $request = new ActionRequest(Request::create(new Uri('http://localhost/foo'))); $controller = $this->getAccessibleMock(\TYPO3\Flow\Mvc\Controller\AbstractController::class, array('processRequest')); $this->inject($controller, 'flashMessageContainer', new FlashMessageContainer()); $this->assertFalse($request->isDispatched()); $controller->_call('initializeController', $request, $this->mockHttpResponse); $this->assertTrue($request->isDispatched()); $this->assertInstanceOf(\TYPO3\Flow\Mvc\Controller\Arguments::class, $controller->_get('arguments')); $this->assertSame($request, $controller->_get('uriBuilder')->getRequest()); $this->assertSame($request, $controller->getControllerContext()->getRequest()); }
/** * @test */ public function startAuthenticationSetsTheCorrectValuesInTheResponseObject() { $request = Request::create(new Uri('http://robertlemke.com/admin'))->createActionRequest(); $response = new Response(); $entryPoint = new HttpBasic(); $entryPoint->setOptions(array('realm' => 'realm string')); $entryPoint->startAuthentication($request->getHttpRequest(), $response); $this->assertEquals('401', substr($response->getStatus(), 0, 3)); $this->assertEquals('Basic realm="realm string"', $response->getHeader('WWW-Authenticate')); $this->assertEquals('Authorization required', $response->getContent()); $this->assertEquals(array('realm' => 'realm string'), $entryPoint->getOptions()); }
/** * @param string $grantType One of this' interface GRANT_TYPE_* constants * @param array $additionalParameters Additional parameters for the request * @return mixed * @throws \Flowpack\OAuth2\Client\Exception * @see http://tools.ietf.org/html/rfc6749#section-4.1.3 */ protected function requestAccessToken($grantType, $additionalParameters = array()) { $parameters = array('grant_type' => $grantType, 'client_id' => $this->clientIdentifier, 'client_secret' => $this->clientSecret); $parameters = Arrays::arrayMergeRecursiveOverrule($parameters, $additionalParameters, FALSE, FALSE); $request = Request::create(new Uri($this->endpointUri), 'POST', $parameters); $request->setHeader('Content-Type', 'application/x-www-form-urlencoded'); $response = $this->requestEngine->sendRequest($request); if ($response->getStatusCode() !== 200) { throw new OAuth2Exception(sprintf('The response when requesting the access token was not as expected, code and message was: %d %s', $response->getStatusCode(), $response->getContent()), 1383749757); } $responseComponents = json_decode($response->getContent(), true); return $responseComponents['access_token']; }
/** * @test */ public function updateCredentialsIgnoresAnythingOtherThanPostRequests() { $arguments = array(); $arguments['__authentication']['TYPO3']['Flow']['Security']['Authentication']['Token']['PasswordToken']['password'] = '******'; $actionRequest = Request::create(new Uri('http://robertlemke.com/login'), 'POST', $arguments)->createActionRequest(); $token = new PasswordToken(); $token->updateCredentials($actionRequest); $this->assertEquals(array('password' => 'verysecurepassword'), $token->getCredentials()); $actionRequest = Request::create(new Uri('http://robertlemke.com/login'), 'GET', $arguments)->createActionRequest(); $token = new PasswordToken(); $token->updateCredentials($actionRequest); $this->assertEquals(array('password' => ''), $token->getCredentials()); }
/** * Helper to build mock controller context needed to test expandGenericPathPattern. * * @param string $packageKey * @param string $subPackageKey * @param string $controllerName * @param string $format * @return ControllerContext */ protected function setupMockControllerContextForPathResolving($packageKey, $subPackageKey, $controllerName, $format) { $controllerObjectName = 'TYPO3\\' . $packageKey . '\\' . ($subPackageKey != $subPackageKey . '\\' ?: '') . 'Controller\\' . $controllerName . 'Controller'; $httpRequest = Request::create(new Uri('http://robertlemke.com/blog')); $mockRequest = $this->createMock(\TYPO3\Flow\Mvc\ActionRequest::class, array(), array($httpRequest)); $mockRequest->expects($this->any())->method('getControllerPackageKey')->will($this->returnValue($packageKey)); $mockRequest->expects($this->any())->method('getControllerSubPackageKey')->will($this->returnValue($subPackageKey)); $mockRequest->expects($this->any())->method('getControllerName')->will($this->returnValue($controllerName)); $mockRequest->expects($this->any())->method('getControllerObjectName')->will($this->returnValue($controllerObjectName)); $mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue($format)); /** @var $mockControllerContext ControllerContext */ $mockControllerContext = $this->createMock(\TYPO3\Flow\Mvc\Controller\ControllerContext::class, array('getRequest'), array(), '', false); $mockControllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($mockRequest)); return $mockControllerContext; }
/** * @test */ public function processRequestShouldSetWidgetConfiguration() { $request = new \TYPO3\Flow\Mvc\ActionRequest(new \TYPO3\Flow\Mvc\ActionRequest(\TYPO3\Flow\Http\Request::create(new \TYPO3\Flow\Http\Uri('http://localhost/foo')))); $response = new \TYPO3\Flow\Http\Response(); $widgetContext = $this->getMock('TYPO3\\Fluid\\Core\\Widget\\WidgetContext', array('getWidgetConfiguration')); $widgetContext->expects($this->once())->method('getWidgetConfiguration')->will($this->returnValue('myConfiguration')); $request->setArgument('__widgetContext', $widgetContext); $abstractWidgetController = $this->getAccessibleMock('TYPO3\\Fluid\\Core\\Widget\\AbstractWidgetController', array('resolveActionMethodName', 'initializeActionMethodArguments', 'initializeActionMethodValidators', 'mapRequestArgumentsToControllerArguments', 'detectFormat', 'resolveView', 'callActionMethod')); $abstractWidgetController->_set('argumentsMappingResults', new \TYPO3\Flow\Error\Result()); $abstractWidgetController->_set('flashMessageContainer', new \TYPO3\Flow\Mvc\FlashMessageContainer()); $abstractWidgetController->_set('mvcPropertyMappingConfigurationService', $this->getMock('TYPO3\\Flow\\Mvc\\Controller\\MvcPropertyMappingConfigurationService')); $abstractWidgetController->processRequest($request, $response); $widgetConfiguration = $abstractWidgetController->_get('widgetConfiguration'); $this->assertEquals('myConfiguration', $widgetConfiguration); }
/** * @return void */ public function setUp() { parent::setup(); vfsStream::setup('Foo'); $this->httpRequest = Request::create(new Uri('http://localhost')); $this->httpResponse = new Response(); $mockRequestHandler = $this->getMock('TYPO3\\Flow\\Http\\RequestHandler', array(), array(), '', FALSE, FALSE); $mockRequestHandler->expects($this->any())->method('getHttpRequest')->will($this->returnValue($this->httpRequest)); $mockRequestHandler->expects($this->any())->method('getHttpResponse')->will($this->returnValue($this->httpResponse)); $this->mockBootstrap = $this->getMock('TYPO3\\Flow\\Core\\Bootstrap', array(), array(), '', FALSE, FALSE); $this->mockBootstrap->expects($this->any())->method('getActiveRequestHandler')->will($this->returnValue($mockRequestHandler)); $this->mockSecurityContext = $this->getMock('TYPO3\\Flow\\Security\\Context', array(), array(), '', FALSE, FALSE); $this->mockObjectManager = $this->getMock('TYPO3\\Flow\\Object\\ObjectManagerInterface', array(), array(), '', FALSE, FALSE); $this->mockObjectManager->expects($this->any())->method('get')->with('TYPO3\\Flow\\Security\\Context')->will($this->returnValue($this->mockSecurityContext)); }
/** * @test */ public function startAuthenticationSetsTheCorrectValuesInTheResponseObjectIfRouteValuesAreSpecified() { $request = Request::create(new Uri('http://robertlemke.com/admin')); $response = new Response(); $entryPoint = $this->getAccessibleMock(\TYPO3\Flow\Security\Authentication\EntryPoint\WebRedirect::class, array('dummy')); $routeValues = array('@package' => 'SomePackage', '@subpackage' => 'SomeSubPackage', '@controller' => 'SomeController', '@action' => 'someAction', '@format' => 'someFormat', 'otherArguments' => array('foo' => 'bar')); $entryPoint->setOptions(array('routeValues' => $routeValues)); $mockUriBuilder = $this->createMock(\TYPO3\Flow\Mvc\Routing\UriBuilder::class); $mockUriBuilder->expects($this->once())->method('setCreateAbsoluteUri')->with(true)->will($this->returnValue($mockUriBuilder)); $mockUriBuilder->expects($this->once())->method('uriFor')->with('someAction', array('otherArguments' => array('foo' => 'bar'), '@format' => 'someFormat'), 'SomeController', 'SomePackage', 'SomeSubPackage')->will($this->returnValue('http://resolved/redirect/uri')); $entryPoint->_set('uriBuilder', $mockUriBuilder); $entryPoint->startAuthentication($request, $response); $this->assertEquals('303', substr($response->getStatus(), 0, 3)); $this->assertEquals('http://resolved/redirect/uri', $response->getHeader('Location')); }
/** * @return void */ public function setUp() { parent::setup(); vfsStream::setup('Foo'); $this->httpRequest = Request::create(new Uri('http://localhost')); $this->httpResponse = new Response(); $mockRequestHandler = $this->createMock(\TYPO3\Flow\Http\RequestHandler::class, array(), array(), '', false, false); $mockRequestHandler->expects($this->any())->method('getHttpRequest')->will($this->returnValue($this->httpRequest)); $mockRequestHandler->expects($this->any())->method('getHttpResponse')->will($this->returnValue($this->httpResponse)); $this->mockBootstrap = $this->createMock(\TYPO3\Flow\Core\Bootstrap::class, array(), array(), '', false, false); $this->mockBootstrap->expects($this->any())->method('getActiveRequestHandler')->will($this->returnValue($mockRequestHandler)); $this->mockSecurityContext = $this->createMock(\TYPO3\Flow\Security\Context::class, array(), array(), '', false, false); $this->mockObjectManager = $this->createMock(\TYPO3\Flow\Object\ObjectManagerInterface::class, array(), array(), '', false, false); $this->mockObjectManager->expects($this->any())->method('get')->with(\TYPO3\Flow\Security\Context::class)->will($this->returnValue($this->mockSecurityContext)); }
/** * @test */ public function processRequestShouldSetWidgetConfiguration() { $mockActionRequest = $this->getMockBuilder(\TYPO3\Flow\Mvc\ActionRequest::class)->disableOriginalConstructor()->getMock(); $mockResponse = $this->getMock(\TYPO3\Flow\Http\Response::class); $httpRequest = Request::create(new Uri('http://localhost')); $mockActionRequest->expects($this->any())->method('getHttpRequest')->will($this->returnValue($httpRequest)); $expectedWidgetConfiguration = array('foo' => uniqid()); $widgetContext = new WidgetContext(); $widgetContext->setAjaxWidgetConfiguration($expectedWidgetConfiguration); $mockActionRequest->expects($this->atLeastOnce())->method('getInternalArgument')->with('__widgetContext')->will($this->returnValue($widgetContext)); $abstractWidgetController = $this->getAccessibleMock(\TYPO3\Fluid\Core\Widget\AbstractWidgetController::class, array('resolveActionMethodName', 'initializeActionMethodArguments', 'initializeActionMethodValidators', 'mapRequestArgumentsToControllerArguments', 'detectFormat', 'resolveView', 'callActionMethod')); $abstractWidgetController->_set('mvcPropertyMappingConfigurationService', $this->getMock(\TYPO3\Flow\Mvc\Controller\MvcPropertyMappingConfigurationService::class)); $abstractWidgetController->processRequest($mockActionRequest, $mockResponse); $actualWidgetConfiguration = $abstractWidgetController->_get('widgetConfiguration'); $this->assertEquals($expectedWidgetConfiguration, $actualWidgetConfiguration); }
/** * @test */ public function layoutViewHelperCanContainIfCondition() { $request = Request::create(new Uri('http://localhost')); $actionRequest = $request->createActionRequest(); $standaloneView = new StandaloneView($actionRequest, uniqid()); vfsStreamWrapper::register(); mkdir('vfs://MyLayouts'); \file_put_contents('vfs://MyLayouts/foo', 'foo: <f:render section="content" />'); \file_put_contents('vfs://MyLayouts/bar', 'bar: <f:render section="content" />'); $standaloneView->setLayoutRootPath('vfs://MyLayouts'); $source = '<f:layout name="{f:if(condition: \'1 == 1\', then: \'foo\', else: \'bar\')}" /><f:section name="content">Content</f:section>'; $standaloneView->setTemplateSource($source); $uncompiledResult = $standaloneView->render(); $compiledResult = $standaloneView->render(); $this->assertSame($uncompiledResult, $compiledResult, 'The rendered compiled template did not match the rendered uncompiled template.'); $this->assertSame('foo: Content', $standaloneView->render()); }
/** * @param string $path * @return string * @throws \Exception */ public function render($path = NULL) { /** @var RequestHandler $activeRequestHandler */ $activeRequestHandler = $this->bootstrap->getActiveRequestHandler(); $parentHttpRequest = $activeRequestHandler->getHttpRequest(); $httpRequest = Request::create(new Uri($parentHttpRequest->getBaseUri() . $path . '.html')); $matchingRoute = $this->router->route($httpRequest); if (!$matchingRoute) { throw new \Exception(sprintf('Uri with path "%s" could not be found.', $parentHttpRequest->getBaseUri() . $path . '.html'), 1426446160); } $request = new ActionRequest($parentHttpRequest); foreach ($matchingRoute as $argumentName => $argumentValue) { $request->setArgument($argumentName, $argumentValue); } $response = new Response($activeRequestHandler->getHttpResponse()); $this->dispatcher->dispatch($request, $response); return $response->getContent(); }
/** * Inspect the received access token as documented in https://developers.facebook.com/docs/facebook-login/access-tokens/, section Getting Info about Tokens and Debugging * * @param string $tokenToInspect * @return array * @throws OAuth2Exception */ public function requestValidatedTokenInformation($tokenToInspect) { $applicationToken = $this->requestClientCredentialsGrantAccessToken(); $requestArguments = array('input_token' => $tokenToInspect, 'access_token' => $applicationToken); $request = Request::create(new Uri('https://graph.facebook.com/debug_token?' . http_build_query($requestArguments))); $response = $this->requestEngine->sendRequest($request); $responseContent = $response->getContent(); if ($response->getStatusCode() !== 200) { throw new OAuth2Exception(sprintf('The response was not of type 200 but gave code and error %d "%s"', $response->getStatusCode(), $responseContent), 1383758360); } $responseArray = json_decode($responseContent, TRUE, 16, JSON_BIGINT_AS_STRING); $responseArray['data']['app_id'] = (string) $responseArray['data']['app_id']; $responseArray['data']['user_id'] = (string) $responseArray['data']['user_id']; if (!$responseArray['data']['is_valid'] || $responseArray['data']['app_id'] !== $this->clientIdentifier) { $this->securityLogger->log('Requesting validated token information from the Facebook endpoint did not succeed.', LOG_NOTICE, array('response' => var_export($responseArray, TRUE), 'clientIdentifier' => $this->clientIdentifier)); return FALSE; } else { return $responseArray['data']; } }
/** * @test */ public function postRequestOnRestrictedActionWithoutCsrfTokenCausesAccessDeniedException() { $this->markTestIncomplete('Needs to be implemented'); $arguments = array(); $arguments['__authentication']['TYPO3']['Flow']['Security']['Authentication']['Token']['UsernamePassword']['username'] = '******'; $arguments['__authentication']['TYPO3']['Flow']['Security']['Authentication']['Token']['UsernamePassword']['password'] = '******'; $request = Request::create(new Uri('http://localhost/test/security/authentication/usernamepassword/authenticate'), 'POST', $arguments); $response = $this->browser->sendRequest($request); $sessionCookie = $response->getCookie('TYPO3_Flow_Session'); $request = Request::create(new Uri('http://localhost/test/security/restricted/admin')); $request->setCookie($sessionCookie); $response = $this->browser->sendRequest($request); // Expect an exception because no account is authenticated: $response = $this->browser->request(new Uri('http://localhost/test/security/restricted/customer'), 'POST'); // ... // Expect an different exception because although an account is authenticated, the request lacks a CSRF token: $response = $this->browser->request(new Uri('http://localhost/test/security/restricted/customer'), 'POST', $arguments); // ... // Expect that it works after you logged in $csrfToken = $this->securityContext->getCsrfProtectionToken(); $request = Request::create(new Uri('http://localhost/test/security/restricted/customer'), 'POST'); // ... }