public function testWrappedKernelIsHandledForInternalRequests() { $request = InternalRequest::create('/', 'GET'); $this->auth->shouldReceive('check')->once()->andReturn(false); $this->container->shouldReceive('make')->once()->with('config')->andReturn(m::mock(['get' => []])); $this->app->shouldReceive('handle')->once()->with($request, HttpKernelInterface::MASTER_REQUEST, true)->andReturn(new Response('test')); $this->assertEquals('test', $this->middleware->handle($request)->getContent()); }
public function testWrappedKernelIsHandledForInternalRequestsAndAuthenticatedUsers() { $request = InternalRequest::create('/', 'GET'); $this->app->shouldReceive('handle')->once()->with($request, HttpKernelInterface::MASTER_REQUEST, true)->andReturn(new Response('test')); $this->assertEquals('test', $this->middleware->handle($request)->getContent()); $request = Request::create('/', 'GET'); $this->container->shouldReceive('make')->once()->with('dingo.api.auth')->andReturn(m::mock(['user' => true])); $this->app->shouldReceive('handle')->once()->with($request, HttpKernelInterface::MASTER_REQUEST, true)->andReturn(new Response('test')); $this->assertEquals('test', $this->middleware->handle($request)->getContent()); }
/** * Create a new internal request from an HTTP verb and URI. * * @param string $verb * @param string $uri * @param string|array $parameters * * @return \Dingo\Api\Http\InternalRequest */ protected function createRequest($verb, $uri, $parameters) { $parameters = array_merge($this->parameters, (array) $parameters); $uri = $this->addPrefixToUri($uri); // If the URI does not have a scheme then we can assume that there it is not an // absolute URI, in this case we'll prefix the root requests path to the URI. if (!parse_url($uri, PHP_URL_SCHEME)) { $uri = rtrim($this->getRootRequest()->root(), '/') . '/' . ltrim($uri); } $request = InternalRequest::create($uri, $verb, $parameters, $this->cookies, $this->uploads, [], $this->content); $request->headers->set('host', $this->getDomain()); foreach ($this->headers as $header => $value) { $request->headers->set($header, $value); } $request->headers->set('accept', $this->getAcceptHeader()); return $request; }
/** * @expectedException Symfony\Component\HttpKernel\Exception\HttpException */ public function testRouterCatchesHttpExceptionsAndRethrowsForInternalRequest() { $this->router->api(['version' => 'v1'], function () { $this->router->get('foo', function () { throw new HttpException(404); }); }); $this->router->dispatch(InternalRequest::create('foo', 'GET')); }
/** * Create a new internal request from an HTTP verb and URI. * * @param string $verb * @param string $uri * @param string|array $parameters * * @return \Dingo\Api\Http\InternalRequest */ protected function createRequest($verb, $uri, $parameters) { $parameters = array_merge($this->parameters, (array) $parameters); $uri = $this->addPrefixToUri($uri); $request = InternalRequest::create($uri, $verb, $parameters, $this->cookies, $this->uploads, [], $this->content); $request->headers->set('host', $this->getDomain()); foreach ($this->headers as $header => $value) { $request->headers->set($header, $value); } $request->headers->set('accept', $this->getAcceptHeader()); return $request; }
/** * Create a new internal request from an HTTP verb and URI. * * @param string $verb * @param string $uri * @param string|array $parameters * @return \Dingo\Api\Http\InternalRequest */ protected function createRequest($verb, $uri, $parameters) { if (!isset($this->version)) { $this->version = $this->router->getDefaultVersion(); } // Once we have a version we can go ahead and grab the API collection, // if one exists, from the router. $api = $this->router->getApiRouteCollection($this->version); if ($prefix = $api->option('prefix') and !starts_with($uri, $prefix)) { $uri = "{$prefix}/{$uri}"; } $parameters = array_merge($this->parameters, (array) $parameters); $request = InternalRequest::create($uri, $verb, $parameters, [], $this->files); if ($domain = $api->option('domain')) { $request->headers->set('host', $domain); } $request->headers->set('accept', $this->buildAcceptHeader()); return $request; }
/** * Create a new internal request from an HTTP verb and URI. * * @param string $verb * @param string $uri * @param string|array $parameters * * @return \Dingo\Api\Http\InternalRequest */ protected function createRequest($verb, $uri, $parameters) { if (!isset($this->version)) { $this->version = $this->properties->getVersion(); } $api = $this->router->getApiGroups()->getByDomainOrVersion($this->domain, $this->version); if (($prefix = $api->option('prefix')) && !starts_with($uri, $prefix)) { $uri = sprintf('%s/%s', $prefix, $uri); } $parameters = array_merge($this->parameters, (array) $parameters); $request = InternalRequest::create($this->url->to($uri), $verb, $parameters, $this->cookies, $this->uploads, [], $this->content); if ($domain = $api->option('domain')) { $request->headers->set('host', $domain); } foreach ($this->headers as $header => $value) { $request->headers->set($header, $value); } $request->headers->set('accept', $this->buildAcceptHeader()); return $request; }
public function testFilterBypassesInternalRequests() { $request = InternalRequest::create('test', 'GET'); $route = new Route(['GET'], 'test', ['protected' => true]); $this->assertNull($this->filter->filter($route, $request)); }