/**
  * @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);
 }
 /**
  * @test
  */
 public function updateCredentialsIgnoresAnythingOtherThanPostRequests()
 {
     $arguments = array();
     $arguments['__authentication']['TYPO3']['Flow']['Security']['Authentication']['Token']['PasswordToken']['password'] = '******';
     $this->mockHttpRequest->expects($this->atLeastOnce())->method('getMethod')->will($this->returnValue('POST'));
     $this->mockActionRequest->expects($this->atLeastOnce())->method('getInternalArguments')->will($this->returnValue($arguments));
     $this->token->updateCredentials($this->mockActionRequest);
     $this->assertEquals(array('password' => 'verysecurepassword'), $this->token->getCredentials());
     $secondToken = new PasswordToken();
     $secondMockActionRequest = $this->getMockBuilder(\TYPO3\Flow\Mvc\ActionRequest::class)->disableOriginalConstructor()->getMock();
     $secondMockHttpRequest = $this->getMockBuilder(\TYPO3\Flow\Http\Request::class)->disableOriginalConstructor()->getMock();
     $secondMockActionRequest->expects($this->any())->method('getHttpRequest')->will($this->returnValue($secondMockHttpRequest));
     $secondMockHttpRequest->expects($this->atLeastOnce())->method('getMethod')->will($this->returnValue('GET'));
     $secondToken->updateCredentials($secondMockActionRequest);
     $this->assertEquals(array('password' => ''), $secondToken->getCredentials());
 }
 /**
  * @test
  */
 public function handleMergesInternalArgumentsWithRoutingMatchResults()
 {
     $this->mockHttpRequest->expects($this->any())->method('getArguments')->will($this->returnValue(array('__internalArgument1' => 'request', '__internalArgument2' => 'request', '__internalArgument3' => 'request')));
     $this->mockPropertyMapper->expects($this->any())->method('convert')->with('', 'array', $this->mockPropertyMappingConfiguration)->will($this->returnValue(array('__internalArgument2' => 'requestBody', '__internalArgument3' => 'requestBody')));
     $this->mockComponentContext->expects($this->atLeastOnce())->method('getParameter')->with('TYPO3\\Flow\\Mvc\\Routing\\RoutingComponent', 'matchResults')->will($this->returnValue(array('__internalArgument3' => 'routing')));
     $this->mockActionRequest->expects($this->once())->method('setArguments')->with(array('__internalArgument1' => 'request', '__internalArgument2' => 'requestBody', '__internalArgument3' => 'routing'));
     $this->dispatchComponent->handle($this->mockComponentContext);
 }
예제 #4
0
 /**
  * @test
  */
 public function buildAddsActionNameFromRootRequestIfRequestIsOfTypeSubRequest()
 {
     $expectedArguments = array('@action' => 'RootRequestActionName');
     $this->mockMainRequest->expects($this->once())->method('getControllerActionName')->will($this->returnValue('RootRequestActionName'));
     $this->mockMainRequest->expects($this->any())->method('getArguments')->will($this->returnValue(array()));
     $this->uriBuilder->setRequest($this->mockSubRequest);
     $this->uriBuilder->build();
     $this->assertEquals($expectedArguments, $this->uriBuilder->getLastArguments());
 }
 /**
  * @test
  */
 public function tokenCanBeCastToString()
 {
     $arguments = array();
     $arguments['__authentication']['TYPO3']['Flow']['Security']['Authentication']['Token']['UsernamePassword']['username'] = '******';
     $arguments['__authentication']['TYPO3']['Flow']['Security']['Authentication']['Token']['UsernamePassword']['password'] = '******';
     $this->mockHttpRequest->expects($this->atLeastOnce())->method('getMethod')->will($this->returnValue('POST'));
     $this->mockActionRequest->expects($this->atLeastOnce())->method('getInternalArguments')->will($this->returnValue($arguments));
     $this->token->updateCredentials($this->mockActionRequest);
     $this->assertEquals('Username: "******"', (string) $this->token);
 }
 /**
  * @test
  */
 public function matchRequestReturnsFalseIfAuthorizationChecksAreDisabled()
 {
     $httpRequest = Request::create(new Uri('http://localhost'), 'POST');
     $this->mockActionRequest->expects($this->any())->method('getHttpRequest')->will($this->returnValue($httpRequest));
     $mockAuthenticationManager = $this->createMock(\TYPO3\Flow\Security\Authentication\AuthenticationManagerInterface::class);
     $mockAuthenticationManager->expects($this->any())->method('isAuthenticated')->will($this->returnValue(true));
     $mockSecurityContext = $this->createMock(\TYPO3\Flow\Security\Context::class);
     $mockSecurityContext->expects($this->atLeastOnce())->method('areAuthorizationChecksDisabled')->will($this->returnValue(true));
     $mockCsrfProtectionPattern = $this->getAccessibleMock(\TYPO3\Flow\Security\RequestPattern\CsrfProtection::class, array('dummy'));
     $mockCsrfProtectionPattern->_set('authenticationManager', $mockAuthenticationManager);
     $mockCsrfProtectionPattern->_set('systemLogger', $this->mockSystemLogger);
     $mockCsrfProtectionPattern->_set('securityContext', $mockSecurityContext);
     $this->assertFalse($mockCsrfProtectionPattern->matchRequest($this->mockActionRequest));
 }
 /**
  * @test
  */
 public function evaluateIgnoresPackagePropertyIfAResourcePathIsGiven()
 {
     $this->mockTsRuntime->expects($this->any())->method('evaluate')->will($this->returnCallback(function ($evaluatePath, $that) {
         $relativePath = str_replace('resourceUri/test/', '', $evaluatePath);
         switch ($relativePath) {
             case 'path':
                 return 'resource://Some.Package/Public/SomeResource';
             case 'package':
                 return 'Specified.Package';
         }
         return null;
     }));
     $this->mockActionRequest->expects($this->any())->method('getControllerPackageKey')->will($this->returnValue('Current.Package'));
     $this->mockResourceManager->expects($this->atLeastOnce())->method('getPublicPackageResourceUri')->will($this->returnValue('Static/Resources/Packages/Some.Package/SomeResource'));
     $this->assertSame('Static/Resources/Packages/Some.Package/SomeResource', $this->resourceUriImplementation->evaluate());
 }
 /**
  * @test
  */
 public function processRequestInjectsSettingsToView()
 {
     $this->actionController = $this->getAccessibleMock(\TYPO3\Flow\Mvc\Controller\ActionController::class, array('resolveActionMethodName', 'initializeActionMethodArguments', 'initializeActionMethodValidators', 'resolveView', 'callActionMethod'));
     $this->inject($this->actionController, 'objectManager', $this->mockObjectManager);
     $this->inject($this->actionController, 'controllerContext', $this->mockControllerContext);
     $mockSettings = array('foo', 'bar');
     $this->inject($this->actionController, 'settings', $mockSettings);
     $mockMvcPropertyMappingConfigurationService = $this->createMock(\TYPO3\Flow\Mvc\Controller\MvcPropertyMappingConfigurationService::class);
     $this->inject($this->actionController, 'mvcPropertyMappingConfigurationService', $mockMvcPropertyMappingConfigurationService);
     $mockHttpRequest = $this->getMockBuilder(\TYPO3\Flow\Http\Request::class)->disableOriginalConstructor()->getMock();
     $mockHttpRequest->expects($this->any())->method('getNegotiatedMediaType')->will($this->returnValue('*/*'));
     $this->mockRequest->expects($this->any())->method('getHttpRequest')->will($this->returnValue($mockHttpRequest));
     $mockResponse = $this->createMock(\TYPO3\Flow\Http\Response::class);
     $mockView = $this->createMock(\TYPO3\Flow\Mvc\View\ViewInterface::class);
     $mockView->expects($this->once())->method('assign')->with('settings', $mockSettings);
     $this->actionController->expects($this->once())->method('resolveView')->will($this->returnValue($mockView));
     $this->actionController->processRequest($this->mockRequest, $mockResponse);
 }
 /**
  * @test
  * @expectedException \TYPO3\Flow\Mvc\Exception\RequiredArgumentMissingException
  */
 public function mapRequestArgumentsToControllerArgumentsThrowsExceptionIfRequiredArgumentWasNotSet()
 {
     $mockPropertyMapper = $this->getMockBuilder(\TYPO3\Flow\Property\PropertyMapper::class)->disableOriginalConstructor()->setMethods(array('convert'))->getMock();
     $mockPropertyMapper->expects($this->atLeastOnce())->method('convert')->will($this->returnArgument(0));
     $controllerArguments = new Arguments();
     $controllerArguments->addNewArgument('foo', 'string', true);
     $controllerArguments->addNewArgument('baz', 'string', true);
     foreach ($controllerArguments as $controllerArgument) {
         $this->inject($controllerArgument, 'propertyMapper', $mockPropertyMapper);
     }
     $controller = $this->getAccessibleMock(\TYPO3\Flow\Mvc\Controller\AbstractController::class, array('processRequest'));
     $controller->_call('initializeController', $this->mockActionRequest, $this->mockHttpResponse);
     $controller->_set('arguments', $controllerArguments);
     $this->mockActionRequest->expects($this->at(0))->method('hasArgument')->with('foo')->will($this->returnValue(true));
     $this->mockActionRequest->expects($this->at(1))->method('getArgument')->with('foo')->will($this->returnValue('bar'));
     $this->mockActionRequest->expects($this->at(2))->method('hasArgument')->with('baz')->will($this->returnValue(false));
     $controller->_call('mapRequestArgumentsToControllerArguments');
 }
 /**
  * @test
  * @expectedException \TYPO3\Flow\Mvc\Exception\RequiredArgumentMissingException
  */
 public function mapRequestArgumentsToControllerArgumentsThrowsExceptionIfRequiredArgumentWasNotSet()
 {
     $mockPropertyMapper = $this->getMock('TYPO3\\Flow\\Property\\PropertyMapper', array('convert'), array(), '', FALSE);
     $mockPropertyMapper->expects($this->atLeastOnce())->method('convert')->will($this->returnArgument(0));
     $controllerArguments = new Arguments();
     $controllerArguments->addNewArgument('foo', 'string', TRUE);
     $controllerArguments->addNewArgument('baz', 'string', TRUE);
     foreach ($controllerArguments as $controllerArgument) {
         $this->inject($controllerArgument, 'propertyMapper', $mockPropertyMapper);
     }
     $controller = $this->getAccessibleMock('TYPO3\\Flow\\Mvc\\Controller\\AbstractController', array('processRequest'));
     $controller->_call('initializeController', $this->mockActionRequest, $this->mockHttpResponse);
     $controller->_set('arguments', $controllerArguments);
     $this->mockActionRequest->expects($this->at(0))->method('hasArgument')->with('foo')->will($this->returnValue(TRUE));
     $this->mockActionRequest->expects($this->at(1))->method('getArgument')->with('foo')->will($this->returnValue('bar'));
     $this->mockActionRequest->expects($this->at(2))->method('hasArgument')->with('baz')->will($this->returnValue(FALSE));
     $controller->_call('mapRequestArgumentsToControllerArguments');
 }
 /**
  * @test
  * @expectedException \TYPO3\Flow\Security\Exception\AccessDeniedException
  */
 public function dispatchRethrowsAccessDeniedException()
 {
     $this->mockActionRequest->expects($this->any())->method('isDispatched')->will($this->returnValue(TRUE));
     $this->mockFirewall->expects($this->once())->method('blockIllegalRequests')->will($this->throwException(new AccessDeniedException()));
     $this->dispatcher->dispatch($this->mockActionRequest, $this->mockHttpResponse);
 }