作者:bwaidelic
项目:Wwwision.Redirect
/**
* @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();
}
作者:johannesste
项目:Flowpack.ElasticSearc
/**
*
*/
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);
}
作者:kszym
项目:flow-development-collectio
/**
* 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;
}
作者:aimeo
项目:ai-flo
/**
* 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);
}
作者:kszym
项目:flow-development-collectio
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);
}
作者:anih
项目:Flowpack.SingleSignOn.Clien
/**
* 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);
}
作者:bwaidelic
项目:Wwwision.Redirect
/**
* @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);
}
作者:sixty-nin
项目:Hfrahmann.Opaut
/**
* 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);
}
作者:sengkimlon
项目:Flow3-Authentificatio
/**
* @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);
}
作者:nlx-sasch
项目:flow-development-collectio
/**
* @test
*/
public function updateCredentialsIgnoresAnythingOtherThanPostRequests()
{
$arguments = array();
$arguments['__authentication']['TYPO3']['Flow']['Security']['Authentication']['Token']['PasswordToken']['password'] = 'verysecurepassword';
$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());
}
作者:radmiraa
项目:Debug.Toolba
/**
* 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();
}
作者:animaltoo
项目:webinterfac
/**
* @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);
}
作者:kszym
项目:flow-development-collectio
/**
* @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);
}
作者:animaltoo
项目:webinterfac
/**
* @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());
}
作者:sokunthearit
项目:Intern-Project-Week-
/**
* @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);
}
作者:kszym
项目:flow-development-collectio
/**
* @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());
}
作者:animaltoo
项目:webinterfac
/**
* @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));
}
作者:HofUniversityIW
项目:backen
/**
* @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;
}
作者:robertlemk
项目:neos-development-collectio
/**
* @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);
}
作者:patrickrec
项目:flow-development-collectio
/**
* 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));
}