Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix logClientIn for non-existing users #26292

Merged
merged 1 commit into from Oct 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/private/User/Session.php
Expand Up @@ -348,6 +348,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 @@ -384,6 +384,32 @@ public function testLogClientInNoTokenPasswordWith2fa() {
$userSession->logClientIn('john', 'doe', $request);
}

public function testLogClientInUnexist() {
$manager = $this->getMockBuilder('\OC\User\Manager')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

general note: I prefer to use \OC\User\Manager::class instead of the string name - helps when searching by type in ide and anyhow looks cleaner to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay... thing is I just copy-pasted the previous test and adjusted it.

Noted for the future, there's a lot to adjust.

->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