Esempio n. 1
0
 /**
  * Test the logout callback.
  *
  * @covers ::logout
  */
 public function testLogout()
 {
     $logout_controller = $this->getMockBuilder('Drupal\\cas\\Controller\\LogoutController')->setConstructorArgs(array($this->casHelper, $this->requestStack))->setMethods(array('userLogout'))->getMock();
     $this->casHelper->expects($this->once())->method('getServerLogoutUrl')->will($this->returnValue('https://example.com/logout'));
     $logout_controller->expects($this->once())->method('userLogout');
     $response = $logout_controller->logout();
     $this->assertTrue($response->isRedirect('https://example.com/logout'));
 }
Esempio n. 2
0
 /**
  * Test the forcedLogin redirect.
  *
  * @covers ::forceLogin
  * @covers ::__construct
  */
 public function testForceLogin()
 {
     $request = $this->getMock('\\Symfony\\Component\\HttpFoundation\\Request');
     $query = $this->getMock('\\Symfony\\Component\\HttpFoundation\\ParameterBag');
     $request->query = $query;
     $this->requestStack->expects($this->once())->method('getCurrentRequest')->will($this->returnValue($request));
     $parameters = array('returnto' => 'node/1', 'foo' => 'bar');
     $query->expects($this->once())->method('all')->will($this->returnValue($parameters));
     $this->casHelper->expects($this->once())->method('getServerLoginUrl')->with($this->equalTo($parameters))->will($this->returnValue('https://example.com'));
     $expected_response = new TrustedRedirectResponse('https://example.com', 302);
     $force_login_controller = new ForceLoginController($this->casHelper, $this->requestStack);
     $response = $force_login_controller->forceLogin();
     $this->assertEquals($expected_response, $response);
 }
Esempio n. 3
0
 /**
  * Tests the enhance() method.
  *
  * @covers ::enhance
  *
  * @dataProvider enhanceDataProvider
  */
 public function testEnhance($config)
 {
     $this->casHelper->expects($this->once())->method('provideCasLogoutOverride')->willReturn($config);
     $enhancer = new CasRouteEnhancer($this->casHelper);
     $defaults = array();
     $defaults = $enhancer->enhance($defaults, $this->request);
     if ($config) {
         $this->assertArraySubset(['_controller' => '\\Drupal\\cas\\Controller\\LogoutController::logout'], $defaults);
     } else {
         $this->assertEmpty($defaults);
     }
 }
Esempio n. 4
0
 /**
  * Tests that a user is validated and logged in with Drupal acting as proxy.
  *
  * @dataProvider parameterDataProvider
  */
 public function testSuccessfulLoginProxyEnabled($returnto)
 {
     $this->setupRequestParameters($returnto, FALSE, TRUE);
     $this->requestStack->expects($this->once())->method('getCurrentRequest')->will($this->returnValue($this->requestObject));
     if ($returnto) {
         $this->assertDestinationSetFromReturnTo();
     }
     // Cas Helper should indicate Drupal is a proxy.
     $this->casHelper->expects($this->once())->method('isProxy')->will($this->returnValue(TRUE));
     $this->assertSuccessfulValidation($returnto, TRUE);
     $validation_data = new CasPropertyBag('testuser');
     $validation_data->setPgt('testpgt');
     // Login should be called.
     $this->casLogin->expects($this->once())->method('loginToDrupal')->with($this->equalTo($validation_data), $this->equalTo('ST-foobar'));
     // PGT should be saved.
     $this->casHelper->expects($this->once())->method('storePGTSession')->with($this->equalTo('testpgt'));
     $this->assertRedirectedToFrontPageOnHandle();
 }
Esempio n. 5
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);
 }