/**
  * @test
  */
 public function handleReturnResponse()
 {
     $token = new WsseToken();
     $token->setUser('admin');
     $token->setAttribute('digest', 'admin');
     $token->setAttribute('nonce', 'admin');
     $token->setAttribute('created', '2010-12-12 20:00:00');
     $this->authenticationManager->expects($this->once())->method('authenticate')->with($token)->will($this->returnValue($this->response));
     $this->responseEvent->expects($this->once())->method('setResponse')->with($this->response);
     $this->request->headers->add(array('X-WSSE' => 'UsernameToken Username="******", PasswordDigest="admin", Nonce="admin", Created="2010-12-12 20:00:00"'));
     $this->wsseListener->handle($this->responseEvent);
 }
 /**
  * @test
  */
 public function handleReturnResponse()
 {
     $token = new WsseToken();
     $token->setUser('admin');
     $token->digest = 'admin';
     $token->nonce = 'admin';
     $token->created = '2010-12-12 20:00:00';
     $response = new Response();
     $this->authenticationManager->expects($this->once())->method('authenticate')->with($token)->will($this->returnValue($token));
     $this->request->headers->add(array('x-wsse' => 'UsernameToken Username="******"' . ', PasswordDigest="admin", Nonce="admin", Created="2010-12-12 20:00:00"'));
     $listener = new WsseListener($this->securityContext, $this->authenticationManager);
     $listener->handle($this->responseEvent);
 }
 /**
  * @test
  */
 public function it_grants_access_when_authenticated()
 {
     $this->userSessionService->setMinimalUserInfo($this->minimalUserInfo);
     $user = new User();
     $user->id = $this->minimalUserInfo->getId();
     $authToken = new UiTIDToken($user->getRoles());
     $authToken->setUser($user);
     $this->authenticationManager->expects($this->once())->method('authenticate')->with($this->minimalToken)->willReturn($authToken);
     $this->tokenStorage->expects($this->once())->method('setToken')->with($authToken);
     // Make sure no Response is set, so the request can be handled by the
     // actual controllers.
     $this->event->expects($this->never())->method('setResponse');
     $this->listener->handle($this->event);
 }
 /**
  * @test
  */
 public function it_returns_an_unauthorized_response_if_jwt_authentication_fails()
 {
     $tokenString = 'headers.payload.signature';
     $jwt = new Jwt(['alg' => 'none'], [], null, ['headers', 'payload']);
     $token = new JwtUserToken($jwt);
     $request = new Request([], [], [], [], [], ['HTTP_AUTHORIZATION' => 'Bearer ' . $tokenString], '');
     $this->getResponseEvent->expects($this->any())->method('getRequest')->willReturn($request);
     $this->jwtDecoderService->expects($this->once())->method('parse')->with(new StringLiteral($tokenString))->willReturn($jwt);
     $authenticationException = new AuthenticationException('Authentication failed', 666);
     $this->authenticationManager->expects($this->once())->method('authenticate')->with($token)->willThrowException($authenticationException);
     $this->getResponseEvent->expects($this->once())->method('setResponse')->willReturnCallback(function (Response $response) {
         $this->assertEquals('Authentication failed', $response->getContent());
         $this->assertEquals(401, $response->getStatusCode());
     });
     $this->listener->handle($this->getResponseEvent);
 }