Exemple #1
0
 public function parseHttpRequest(ServerHttpRequest $httpRequest, array $attributes) : RequestInterface
 {
     $request = $this->httpRequestParser->parseHttpRequest($httpRequest, $attributes);
     if (!$this->isAllowed($request, $httpRequest)) {
         return new UnauthorizedRequest([], $httpRequest);
     }
     return $request;
 }
 public function it_allows_logged_in_user(ServerHttpRequest $httpRequest, RequestInterface $request, Token $token)
 {
     $tokenUuid = Uuid::uuid4();
     $passCode = bin2hex(random_bytes(20));
     $this->httpRequestParser->parseHttpRequest($httpRequest, [])->willReturn($request);
     $request->getRequestName()->willReturn($messageName = 'test.private');
     $httpRequest->getHeaderLine('Accept')->willReturn('*/*');
     $httpRequest->getHeaderLine('Authentication-Token')->willReturn($tokenUuid->toString());
     $httpRequest->getHeaderLine('Authentication-Pass-Code')->willReturn($passCode);
     $this->tokenService->getToken($tokenUuid, $passCode)->willReturn($token);
     $this->parseHttpRequest($httpRequest, [])->shouldReturn($request);
 }
Exemple #3
0
 /** {@inheritdoc} */
 public function execute(ServerHttpRequest $httpRequest) : HttpResponse
 {
     $this->log(LogLevel::INFO, 'Starting execution.');
     try {
         $requestMessage = $this->requestParser->parseHttpRequest($httpRequest, []);
         $this->log(LogLevel::INFO, 'Successfully parsed HTTP request into Request message.');
     } catch (RequestException $requestException) {
         $this->log(LogLevel::ERROR, 'Request parsing ended in exception: ' . $requestException->getMessage());
         $requestMessage = $requestException->getRequestObject();
     }
     try {
         $responseMessage = $this->executor->executeRequest($requestMessage);
     } catch (ResponseException $responseException) {
         $this->log(LogLevel::ERROR, 'Request execution ended in exception: ' . $responseException->getMessage());
         $responseMessage = $responseException->getResponseObject();
     }
     $httpResponse = $this->generator->generateResponse($responseMessage);
     $this->log(LogLevel::INFO, 'Successfully generated HTTP response.');
     return $httpResponse;
 }