Skip to content

Commit

Permalink
don't allow token login for disabled users
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristophWurst committed May 18, 2016
1 parent dc0e361 commit f824f3e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/private/User/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ private function loginWithToken($uid) {
// user does not exist
return false;
}
if (!$user->isEnabled()) {
// disabled users can not log in
return false;
}

//login
$this->setUser($user);
Expand Down
32 changes: 32 additions & 0 deletions tests/lib/user/session.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,4 +477,36 @@ public function testActiveUserAfterSetSession() {
$this->assertEquals($users['bar'], $userSession->getUser());
}

public function testTryTokenLoginWithDisabledUser() {
$manager = $this->getMockBuilder('\OC\User\Manager')
->disableOriginalConstructor()
->getMock();
$session = new Memory('');
$token = $this->getMock('\OC\Authentication\Token\IToken');
$user = $this->getMock('\OCP\IUser');
$userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->defaultProvider);
$request = $this->getMock('\OCP\IRequest');

$request->expects($this->once())
->method('getHeader')
->with('Authorization')
->will($this->returnValue('token xxxxx'));
$this->defaultProvider->expects($this->once())
->method('validateToken')
->with('xxxxx')
->will($this->returnValue($token));
$token->expects($this->once())
->method('getUID')
->will($this->returnValue('user123'));
$manager->expects($this->once())
->method('get')
->with('user123')
->will($this->returnValue($user));
$user->expects($this->once())
->method('isEnabled')
->will($this->returnValue(false));

$this->assertFalse($userSession->tryTokenLogin($request));
}

}

0 comments on commit f824f3e

Please sign in to comment.