Exemplo n.º 1
0
 public function testRequestCompile()
 {
     $this->tracker->expects($this->once())->method('isOutdated')->willReturn(true);
     $this->compiler->expects($this->once())->method('compile');
     $this->dumper->expects($this->once())->method('dump');
     $this->event->expects($this->once())->method('isMasterRequest')->willReturn(true);
     (new RequestListener($this->tracker, $this->compiler, $this->dumper))->onRequest($this->event);
 }
Exemplo n.º 2
0
 /**
  * @test
  */
 public function handleForbidden()
 {
     $listener = new WsseListener($this->securityContext, $this->authenticationManager);
     $this->request->headers->add(array('X-WSSE' => 'temp'));
     $response = new Response();
     $response->setStatusCode(403);
     //unauthorized
     $this->responseEvent->expects($this->once())->method('setResponse')->with($response);
     $listener->handle($this->responseEvent);
 }
 /**
  * Set up the whole
  */
 public function setUp()
 {
     $this->requestAttributes = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\ParameterBag')->disableOriginalConstructor()->setMethods(array('get'))->getMock();
     $request = $this->getMockBuilder('\\Symfony\\Component\\HttpFoundation\\Request')->disableOriginalConstructor()->getMock();
     $request->attributes = $this->requestAttributes;
     $this->responseEvent = $this->getMockBuilder('\\Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent')->disableOriginalConstructor()->setMethods(array('getRequestType', 'getRequest'))->getMock();
     $this->responseEvent->expects($this->any())->method('getRequest')->will($this->returnValue($request));
     $this->responseEvent->expects($this->any())->method('getRequestType')->will($this->returnValue(HttpKernelInterface::MASTER_REQUEST));
     $this->provider = new BreadcrumbProvider(self::MODEL_CLASS, self::COLLECTION_CLASS);
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     $this->event = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent')->disableOriginalConstructor()->getMock();
     $this->request = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\Request')->disableOriginalConstructor()->getMock();
     $this->parameterBag = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\ParameterBag')->disableOriginalConstructor()->getMock();
     $this->route = $this->getMockBuilder('Symfony\\Component\\Routing\\Route')->disableOriginalConstructor()->getMock();
     $this->request->attributes = $this->parameterBag;
     $this->event->expects($this->any())->method('getRequest')->will($this->returnValue($this->request));
     $this->accessManager = $this->getMockBuilder('Drupal\\Core\\Access\\AccessManager')->disableOriginalConstructor()->getMock();
     $this->currentUser = $this->getMockBuilder('Drupal\\Core\\Session\\AccountInterface')->disableOriginalConstructor()->getMock();
 }
Exemplo n.º 5
0
 /**
  * @return \PHPUnit_Framework_MockObject_MockObject
  */
 protected function getRequest()
 {
     $request = $this->getMock('\\Symfony\\Component\\HttpFoundation\\Request');
     $this->event->expects($this->once())->method('getRequestType')->will($this->returnValue(HttpKernelInterface::MASTER_REQUEST));
     $this->event->expects($this->once())->method('getRequest')->will($this->returnValue($request));
     return $request;
 }
Exemplo n.º 6
0
 /**
  * @param string $header
  * @param string $ip
  *
  * @return \PHPUnit_Framework_MockObject_MockObject
  */
 protected function getRequest($header, $ip)
 {
     $this->event->expects($this->once())->method('getRequestType')->will($this->returnValue(HttpKernelInterface::MASTER_REQUEST));
     /* @var $request \PHPUnit_Framework_MockObject_MockObject|Request */
     $request = $this->getMock('\\Symfony\\Component\\HttpFoundation\\Request');
     $request->server = $this->getMock('\\Symfony\\Component\\HttpFoundation\\ServerBag');
     $request->server->expects($this->atLeastOnce())->method('get')->will($this->returnCallback(function ($value) use($header, $ip) {
         return $value == $header ? $ip : null;
     }));
     $this->event->expects($this->once())->method('getRequest')->will($this->returnValue($request));
     return $request;
 }
 /**
  * @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 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);
 }
Exemplo n.º 10
0
 /**
  * Test processing gateway with CHECK_ONCE to make sure SESSION gets set.
  *
  * @covers ::handle
  * @covers ::handleGateway
  */
 public function testHandleGatewayWithCheckOnceSuccess()
 {
     $config_factory = $this->getConfigFactoryStub(array('cas.settings' => array('forced_login.enabled' => TRUE, 'forced_login.paths' => array('<front>'), 'gateway.check_frequency' => CasHelper::CHECK_ONCE, 'gateway.paths' => array('<front>'))));
     $cas_subscriber = $this->getMockBuilder('\\Drupal\\cas\\Subscriber\\CasSubscriber')->setConstructorArgs(array($this->requestStack, $this->routeMatcher, $config_factory, $this->currentUser, $this->conditionManager, $this->casHelper))->setMethods(NULL)->getMock();
     $this->event->expects($this->any())->method('getRequestType')->will($this->returnValue(HttpKernelInterface::MASTER_REQUEST));
     $request_object = $this->getMock('\\Symfony\\Component\\HttpFoundation\\Request');
     $attributes = $this->getMock('\\Symfony\\Component\\HttpFoundation\\ParameterBag');
     $request_object->attributes = $attributes;
     $server = $this->getMock('\\Symfony\\Component\\HttpFoundation\\ServerBag');
     $request_object->server = $server;
     $condition = $this->getMockBuilder('\\Drupal\\Core\\Condition\\ConditionPluginBase')->disableOriginalConstructor()->getMock();
     $this->conditionManager->expects($this->any())->method('createInstance')->with('request_path')->will($this->returnValue($condition));
     $condition->expects($this->any())->method('setConfiguration')->with(array('<front>'));
     $this->conditionManager->expects($this->any())->method('execute')->with($condition)->will($this->onConsecutiveCalls(FALSE, TRUE));
     $request_object->expects($this->once())->method('isMethod')->with('GET')->will($this->returnValue(TRUE));
     $this->requestStack->expects($this->any())->method('getCurrentRequest')->will($this->returnValue($request_object));
     $this->casHelper->expects($this->once())->method('getServerLoginUrl')->will($this->returnValue('https://example.com'));
     $this->event->expects($this->once())->method('setResponse');
     $cas_subscriber->handle($this->event);
     $this->assertArrayHasKey('cas_gateway_checked', $_SESSION);
 }
 public function testOnKernelRequestWithoutMasterRequest()
 {
     $this->getResponseEventMock->expects($this->once())->method('getRequestType')->will($this->returnValue(HttpKernelInterface::SUB_REQUEST));
     $this->getResponseEventMock->getRequest()->server->expects($this->never())->method('set');
     $this->fakeRequestListener->onKernelRequest($this->getResponseEventMock);
 }
Exemplo n.º 12
0
 public function testRequestMasterRequest()
 {
     $this->guard->expects($this->once())->method('rebuild');
     $this->event->expects($this->once())->method('isMasterRequest')->willReturn(true);
     (new RequestListener($this->guard))->onRequest($this->event);
 }