fix login controller tests

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
pull/2424/head
Arthur Schiwon 10 years ago
parent 287bae8c5f
commit 2994cbc586
No known key found for this signature in database
GPG Key ID: 7424F1874854DF23
  1. 3
      core/Controller/LoginController.php
  2. 14
      tests/Core/Controller/LoginControllerTest.php

@ -207,6 +207,9 @@ class LoginController extends Controller {
* @return RedirectResponse
*/
public function tryLogin($user, $password, $redirect_url, $remember_login = false, $timezone = '', $timezone_offset = '') {
if(!is_string($user)) {
throw new \InvalidArgumentException('Username must be string');
}
$currentDelay = $this->throttler->getDelay($this->request->getRemoteAddress(), 'login');
$this->throttler->sleepDelay($this->request->getRemoteAddress(), 'login');

@ -334,6 +334,7 @@ class LoginControllerTest extends TestCase {
$user->expects($this->any())
->method('getUID')
->will($this->returnValue('uid'));
$loginName = 'loginli';
$user->expects($this->any())
->method('getLastLogin')
->willReturn(123456);
@ -362,10 +363,10 @@ class LoginControllerTest extends TestCase {
->will($this->returnValue($user));
$this->userSession->expects($this->once())
->method('login')
->with($user, $password);
->with($loginName, $password);
$this->userSession->expects($this->once())
->method('createSessionToken')
->with($this->request, $user->getUID(), $user, $password, false);
->with($this->request, $user->getUID(), $loginName, $password, false);
$this->twoFactorManager->expects($this->once())
->method('isTwoFactorAuthenticated')
->with($user)
@ -387,7 +388,7 @@ class LoginControllerTest extends TestCase {
);
$expected = new \OCP\AppFramework\Http\RedirectResponse($indexPageUrl);
$this->assertEquals($expected, $this->loginController->tryLogin($user, $password, null, false, 'Europe/Berlin', '1'));
$this->assertEquals($expected, $this->loginController->tryLogin($loginName, $password, null, false, 'Europe/Berlin', '1'));
}
public function testLoginWithValidCredentialsAndRememberMe() {
@ -396,6 +397,7 @@ class LoginControllerTest extends TestCase {
$user->expects($this->any())
->method('getUID')
->will($this->returnValue('uid'));
$loginName = 'loginli';
$password = 'secret';
$indexPageUrl = \OC_Util::getDefaultPageUrl();
@ -421,10 +423,10 @@ class LoginControllerTest extends TestCase {
->will($this->returnValue($user));
$this->userSession->expects($this->once())
->method('login')
->with($user, $password);
->with($loginName, $password);
$this->userSession->expects($this->once())
->method('createSessionToken')
->with($this->request, $user->getUID(), $user, $password, true);
->with($this->request, $user->getUID(), $loginName, $password, true);
$this->twoFactorManager->expects($this->once())
->method('isTwoFactorAuthenticated')
->with($user)
@ -437,7 +439,7 @@ class LoginControllerTest extends TestCase {
->with($user);
$expected = new \OCP\AppFramework\Http\RedirectResponse($indexPageUrl);
$this->assertEquals($expected, $this->loginController->tryLogin($user, $password, null, true));
$this->assertEquals($expected, $this->loginController->tryLogin($loginName, $password, null, true));
}
public function testLoginWithoutPassedCsrfCheckAndNotLoggedIn() {

Loading…
Cancel
Save