Skip to content

Commit

Permalink
[stable9.1] Fix logClientIn for non-existing users (#26292)
Browse files Browse the repository at this point in the history
The check for two factor enforcement would return true for non-existing
users. This fix makes it return false in order to be able to perform
the regular login which will then fail and return false.

This prevents throwing PasswordLoginForbidden for non-existing users.
  • Loading branch information
Vincent Petry authored and DeepDiver1975 committed Oct 7, 2016
1 parent 5e4233a commit 7f07988
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/private/User/Session.php
Expand Up @@ -349,6 +349,9 @@ protected function isTwoFactorEnforced($username) {
$user = $this->manager->get($username);
if (is_null($user)) {
$users = $this->manager->getByEmail($username);
if (empty($users)) {
return false;
}
if (count($users) !== 1) {
return true;
}
Expand Down
26 changes: 26 additions & 0 deletions tests/lib/User/SessionTest.php
Expand Up @@ -373,6 +373,32 @@ public function testLogClientInNoTokenPasswordWith2fa() {
$userSession->logClientIn('john', 'doe', $request);
}

public function testLogClientInUnexist() {
$manager = $this->getMockBuilder('\OC\User\Manager')
->disableOriginalConstructor()
->getMock();
$session = $this->createMock('\OCP\ISession');
$request = $this->createMock('\OCP\IRequest');
$user = $this->createMock('\OCP\IUser');

/** @var \OC\User\Session $userSession */
$userSession = $this->getMockBuilder('\OC\User\Session')
->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config])
->setMethods(['login', 'supportsCookies', 'createSessionToken', 'getUser'])
->getMock();

$this->tokenProvider->expects($this->once())
->method('getToken')
->with('doe')
->will($this->throwException(new \OC\Authentication\Exceptions\InvalidTokenException()));
$this->config->expects($this->once())
->method('getSystemValue')
->with('token_auth_enforced', false)
->will($this->returnValue(false));

$this->assertFalse($userSession->logClientIn('unexist', 'doe', $request));
}

public function testLogClientInWithTokenPassword() {
$manager = $this->getMockBuilder('\OC\User\Manager')
->disableOriginalConstructor()
Expand Down

0 comments on commit 7f07988

Please sign in to comment.