Ejemplo n.º 1
0
 /**
  * @return string
  * @throws \TYPO3\Flow\Security\Exception\InvalidArgumentForHashGenerationException
  */
 public function getJWTToken()
 {
     /** @var \TYPO3\Flow\Security\Account $account */
     $account = $this->securityContext->getAccount();
     $this->apiToken = $this->securityContext->getAuthenticationTokensOfType('RFY\\JWT\\Security\\Authentication\\Token\\JwtToken')[0];
     if ($account->getAuthenticationProviderName() !== $this->apiToken->getAuthenticationProviderName()) {
         // TODO: Currently you can get only 1 tokenAccount because of the duplication restraint based on accountIdentifier & AuthenticationProviderName
         $account = $this->accountRepository->findActiveByAccountIdentifierAndAuthenticationProviderName($account->getAccountIdentifier(), $this->apiToken->getAuthenticationProviderName());
         if ($account === NULL) {
             $account = $this->generateTokenAccount();
         }
     }
     $payload = array();
     $payload['identifier'] = $account->getAccountIdentifier();
     $payload['partyIdentifier'] = $this->persistenceManager->getIdentifierByObject($account->getParty());
     $payload['user_agent'] = $this->request->getHeader('User-Agent');
     $payload['ip_address'] = $this->request->getClientIpAddress();
     if ($account->getCreationDate() instanceof \DateTime) {
         $payload['creationDate'] = $account->getCreationDate()->getTimestamp();
     }
     if ($account->getExpirationDate() instanceof \DateTime) {
         $payload['expirationDate'] = $account->getExpirationDate()->getTimestamp();
     }
     // Add hmac
     $hmac = $this->hashService->generateHmac($this->signature);
     return JWT::encode($payload, $hmac);
 }
 /**
  * @param HttpRequest $request
  * @return Redirection
  */
 public function findOneByRequest(HttpRequest $request)
 {
     $requestPath = preg_replace('/(\\\\|%|_)/', '\\\\$1', $request->getRelativePath());
     $query = $this->createQuery();
     $query->getQueryBuilder()->where(':requestPath LIKE e.requestPattern')->setParameter('requestPath', $requestPath);
     return $query->execute()->getFirst();
 }
 /**
  *
  */
 public function __construct($message, $code, \TYPO3\Flow\Http\Response $response, \TYPO3\Flow\Http\Request $request = NULL, \Exception $previous = NULL)
 {
     $this->response = $response;
     $this->request = $request;
     if ($request !== NULL) {
         $message = sprintf("[%s %s]: %s\n\nRequest data: %s", $request->getMethod(), $request->getUri(), $message . '; Response body: ' . $response->getContent(), $request->getContent());
     }
     parent::__construct($message, $code, $previous);
 }
 /**
  * Extracts the WidgetContext from the given $httpRequest.
  * If the request contains an argument "__widgetId" the context is fetched from the session (AjaxWidgetContextHolder).
  * Otherwise the argument "__widgetContext" is expected to contain the serialized WidgetContext (protected by a HMAC suffix)
  *
  * @param Request $httpRequest
  * @return WidgetContext
  */
 protected function extractWidgetContext(Request $httpRequest)
 {
     if ($httpRequest->hasArgument('__widgetId')) {
         return $this->ajaxWidgetContextHolder->get($httpRequest->getArgument('__widgetId'));
     } elseif ($httpRequest->hasArgument('__widgetContext')) {
         $serializedWidgetContextWithHmac = $httpRequest->getArgument('__widgetContext');
         $serializedWidgetContext = $this->hashService->validateAndStripHmac($serializedWidgetContextWithHmac);
         return unserialize(base64_decode($serializedWidgetContext));
     }
     return null;
 }
Ejemplo n.º 5
0
 /**
  * Creates a PSR-7 compatible request
  *
  * @param \TYPO3\Flow\Http\Request $nativeRequest Flow request object
  * @param array $files List of uploaded files like in $_FILES
  * @param array $query List of uploaded files like in $_GET
  * @param array $post List of uploaded files like in $_POST
  * @param array $cookies List of uploaded files like in $_COOKIES
  * @param array $server List of uploaded files like in $_SERVER
  * @return \Psr\Http\Message\ServerRequestInterface PSR-7 request object
  */
 protected function createRequest(\TYPO3\Flow\Http\Request $nativeRequest, array $files, array $query, array $post, array $cookies, array $server)
 {
     $server = ServerRequestFactory::normalizeServer($server);
     $files = ServerRequestFactory::normalizeFiles($files);
     $headers = $nativeRequest->getHeaders()->getAll();
     $uri = (string) $nativeRequest->getUri();
     $method = $nativeRequest->getMethod();
     $body = new Stream('php://temp', 'wb+');
     $body->write($nativeRequest->getContent());
     return new ServerRequest($server, $files, $uri, $method, $body, $headers, $cookies, $query, $post);
 }
 public function setUp()
 {
     $this->fileSystemTarget = new FileSystemTarget('test');
     $this->mockBootstrap = $this->getMockBuilder(Bootstrap::class)->disableOriginalConstructor()->getMock();
     $this->mockRequestHandler = $this->getMockBuilder(HttpRequestHandlerInterface::class)->getMock();
     $this->mockHttpRequest = $this->getMockBuilder(Request::class)->disableOriginalConstructor()->getMock();
     $this->mockHttpRequest->expects($this->any())->method('getBaseUri')->will($this->returnValue(new Uri('http://detected/base/uri/')));
     $this->mockRequestHandler->expects($this->any())->method('getHttpRequest')->will($this->returnValue($this->mockHttpRequest));
     $this->mockBootstrap->expects($this->any())->method('getActiveRequestHandler')->will($this->returnValue($this->mockRequestHandler));
     $this->inject($this->fileSystemTarget, 'bootstrap', $this->mockBootstrap);
 }
 /**
  * Starts the authentication by redirecting to the SSO endpoint
  *
  * The redirect includes the callback URI (the original URI from the given request)
  * the client identifier and a signature of the arguments with the client private key.
  *
  * @param \TYPO3\Flow\Http\Request $request The current request
  * @param \TYPO3\Flow\Http\Response $response The current response
  * @return void
  */
 public function startAuthentication(Request $request, Response $response)
 {
     $callbackUri = $request->getUri();
     if (!isset($this->options['server'])) {
         throw new Exception('Missing "server" option for SingleSignOnRedirect entry point. Please specifiy one using the entryPointOptions setting.', 1351690358);
     }
     $ssoServer = $this->ssoServerFactory->create($this->options['server']);
     $ssoClient = $this->ssoClientFactory->create();
     $redirectUri = $ssoServer->buildAuthenticationEndpointUri($ssoClient, $callbackUri);
     $response->setStatus(303);
     $response->setHeader('Location', $redirectUri);
 }
 /**
  * @param HttpRequest $request
  * @param Redirection $redirection
  * @return void
  */
 protected function sendRedirectHeaders(HttpRequest $request, Redirection $redirection)
 {
     if (headers_sent()) {
         return;
     }
     $sourceUriPath = $redirection->getRequestPattern();
     $targetUriPath = $redirection->getTarget();
     if (strpos($sourceUriPath, '%') !== false) {
         $sourceUriPath = preg_quote($sourceUriPath, '/');
         $sourceUriPath = str_replace('%', '(.*)', $sourceUriPath);
         $targetUriPath = preg_replace('/' . $sourceUriPath . '/', $redirection->getTarget(), $request->getRelativePath());
     }
     header($redirection->getStatusLine());
     header('Location: ' . $request->getBaseUri() . $targetUriPath);
 }
Ejemplo n.º 9
0
 /**
  * Construct
  */
 public function __construct()
 {
     $httpRequest = \TYPO3\Flow\Http\Request::createFromEnvironment();
     $actionRequest = new \TYPO3\Flow\Mvc\ActionRequest($httpRequest);
     $this->uriBuilder = new \TYPO3\Flow\Mvc\Routing\UriBuilder();
     $this->uriBuilder->setRequest($actionRequest);
 }
 /**
  * @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());
 }
Ejemplo n.º 12
0
 /**
  * Handles a HTTP request
  *
  * @return void
  */
 public function handleRequest()
 {
     // Create the request very early so the Resource Management has a chance to grab it:
     $this->request = \TYPO3\Flow\Http\Request::createFromEnvironment();
     $this->response = new \TYPO3\Flow\Http\Response();
     $this->boot();
     $this->resolveDependencies();
     $this->request->injectSettings($this->settings);
     $this->addDebugToolbarRoutes();
     $this->router->setRoutesConfiguration($this->routesConfiguration);
     $actionRequest = $this->router->route($this->request);
     $this->securityContext->setRequest($actionRequest);
     $this->dispatcher->dispatch($actionRequest, $this->response);
     $this->response->makeStandardsCompliant($this->request);
     \Debug\Toolbar\Service\DataStorage::add('Request:Requests', $actionRequest);
     \Debug\Toolbar\Service\DataStorage::add('Request:Responses', $this->response);
     \Debug\Toolbar\Toolbar\View::handleRedirects($this->request, $this->response);
     $this->emitAboutToRenderDebugToolbar();
     \Debug\Toolbar\Service\DataStorage::set('Modules', \Debug\Toolbar\Service\Collector::getModules());
     if ($actionRequest->getFormat() === 'html') {
         echo \Debug\Toolbar\Toolbar\View::attachToolbar($this->response->getContent());
     } else {
         echo $this->response->getContent();
     }
     $this->bootstrap->shutdown('Runtime');
     $this->exit->__invoke();
     \Debug\Toolbar\Service\DataStorage::save();
 }
Ejemplo n.º 13
0
 /**
  * @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);
 }
Ejemplo n.º 14
0
 /**
  * @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 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());
 }
 /**
  * @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);
 }
 /**
  * @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());
 }
Ejemplo n.º 18
0
 /**
  * @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));
 }
 /**
  * @return null|string
  */
 protected function getRequestMediaType()
 {
     if (PHP_SAPI !== 'cli' && ($httpRequest = \TYPO3\Flow\Http\Request::createFromEnvironment())) {
         if ($httpRequest !== NULL) {
             return $httpRequest->getNegotiatedMediaType($this->supportedMediaTypes);
         }
     }
     return NULL;
 }
 /**
  * @return ControllerContext
  */
 protected function createControllerContextFromEnvironment()
 {
     $httpRequest = Request::createFromEnvironment();
     /** @var ActionRequest $request */
     $request = $httpRequest->createActionRequest();
     $uriBuilder = new UriBuilder();
     $uriBuilder->setRequest($request);
     return new ControllerContext($request, new Response(), new Arguments(array()), $uriBuilder);
 }
 /**
  * Sets up this test case
  */
 public function setUp()
 {
     $this->routerCachingService = $this->getAccessibleMock(\TYPO3\Flow\Mvc\Routing\RouterCachingService::class, array('dummy'));
     $this->mockRouteCache = $this->getMockBuilder(\TYPO3\Flow\Cache\Frontend\VariableFrontend::class)->disableOriginalConstructor()->getMock();
     $this->inject($this->routerCachingService, 'routeCache', $this->mockRouteCache);
     $this->mockResolveCache = $this->getMockBuilder(\TYPO3\Flow\Cache\Frontend\StringFrontend::class)->disableOriginalConstructor()->getMock();
     $this->inject($this->routerCachingService, 'resolveCache', $this->mockResolveCache);
     $this->mockPersistenceManager = $this->getMockBuilder(\TYPO3\Flow\Persistence\PersistenceManagerInterface::class)->getMock();
     $this->inject($this->routerCachingService, 'persistenceManager', $this->mockPersistenceManager);
     $this->mockSystemLogger = $this->getMockBuilder(\TYPO3\Flow\Log\SystemLoggerInterface::class)->getMock();
     $this->inject($this->routerCachingService, 'systemLogger', $this->mockSystemLogger);
     $this->mockHttpRequest = $this->getMockBuilder(\TYPO3\Flow\Http\Request::class)->disableOriginalConstructor()->getMock();
     $this->mockHttpRequest->expects($this->any())->method('getMethod')->will($this->returnValue('GET'));
     $this->mockHttpRequest->expects($this->any())->method('getRelativePath')->will($this->returnValue('some/route/path'));
     $this->mockUri = $this->getMockBuilder(\TYPO3\Flow\Http\Uri::class)->disableOriginalConstructor()->getMock();
     $this->mockUri->expects($this->any())->method('getHost')->will($this->returnValue('subdomain.domain.com'));
     $this->mockHttpRequest->expects($this->any())->method('getUri')->will($this->returnValue($this->mockUri));
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * Sets up this test case
  */
 public function setUp()
 {
     $this->routerCachingService = $this->getAccessibleMock('TYPO3\\Flow\\Mvc\\Routing\\RouterCachingService', array('dummy'));
     $this->mockFindMatchResultsCache = $this->getMockBuilder('TYPO3\\Flow\\Cache\\Frontend\\VariableFrontend')->disableOriginalConstructor()->getMock();
     $this->routerCachingService->_set('findMatchResultsCache', $this->mockFindMatchResultsCache);
     $this->mockResolveCache = $this->getMockBuilder('TYPO3\\Flow\\Cache\\Frontend\\StringFrontend')->disableOriginalConstructor()->getMock();
     $this->routerCachingService->_set('resolveCache', $this->mockResolveCache);
     $this->mockPersistenceManager = $this->getMockBuilder('TYPO3\\Flow\\Persistence\\PersistenceManagerInterface')->getMock();
     $this->routerCachingService->_set('persistenceManager', $this->mockPersistenceManager);
     $this->mockSystemLogger = $this->getMockBuilder('TYPO3\\Flow\\Log\\SystemLoggerInterface')->getMock();
     $this->routerCachingService->_set('systemLogger', $this->mockSystemLogger);
     $this->mockHttpRequest = $this->getMockBuilder('TYPO3\\Flow\\Http\\Request')->disableOriginalConstructor()->getMock();
     $this->mockHttpRequest->expects($this->any())->method('getMethod')->will($this->returnValue('GET'));
     $this->mockHttpRequest->expects($this->any())->method('getRelativePath')->will($this->returnValue('some/route/path'));
     $this->mockUri = $this->getMockBuilder('TYPO3\\Flow\\Http\\Uri')->disableOriginalConstructor()->getMock();
     $this->mockUri->expects($this->any())->method('getHost')->will($this->returnValue('subdomain.domain.com'));
     $this->mockHttpRequest->expects($this->any())->method('getUri')->will($this->returnValue($this->mockUri));
 }
Ejemplo n.º 25
0
 /**
  * @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;
 }
 /**
  * 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;
 }
Ejemplo n.º 27
0
 /**
  * @test
  */
 public function buildDoesNotPrependsScriptRequestPathIfCreateRelativePathsCompatibilityFlagIsTrue()
 {
     $this->mockHttpRequest->expects($this->never())->method('getScriptRequestPath');
     $this->mockRouter->expects($this->once())->method('resolve')->will($this->returnValue('resolvedUri'));
     $this->uriBuilder->setCreateAbsoluteUri(FALSE);
     $this->uriBuilder->setCreateRelativePaths(TRUE);
     $expectedResult = 'resolvedUri';
     $actualResult = $this->uriBuilder->build();
     $this->assertEquals($expectedResult, $actualResult);
 }
 /**
  * @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 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 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');
 }