Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions lib/private/User/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,10 +403,8 @@ public function logClientIn($user,
return false;
}

if (!$isTokenPassword && $this->isTokenAuthEnforced()) {
throw new PasswordLoginForbiddenException();
}
if (!$isTokenPassword && $this->isTwoFactorEnforced($user)) {
if (!$isTokenPassword && ($this->isTokenAuthEnforced() || $this->isTwoFactorEnforced($user))) {
$this->handleLoginFailed($throttler, $currentDelay, $remoteAddress, $user, $password);
throw new PasswordLoginForbiddenException();
}

Expand Down Expand Up @@ -576,7 +574,8 @@ public function tryBasicAuthLogin(IRequest $request,
// If credentials were provided, they need to be valid, otherwise we do boom
throw new LoginException();
} catch (PasswordLoginForbiddenException $ex) {
// Nothing to do
// If credentials were provided, they need to be valid, otherwise we do boom
throw new LoginException(previous: $ex);
}
}
return false;
Expand Down
22 changes: 20 additions & 2 deletions tests/lib/User/SessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ public function testLogClientInNoTokenPasswordWith2fa(): void {
->method('getRemoteAddress')
->willReturn('192.168.0.1');
$this->throttler
->expects($this->once())
->expects($this->exactly(2))
->method('sleepDelayOrThrowOnMax')
->with('192.168.0.1');
$this->throttler
Expand All @@ -448,6 +448,15 @@ public function testLogClientInNoTokenPasswordWith2fa(): void {
->with('192.168.0.1')
->willReturn(0);

$this->throttler
->expects($this->once())
->method('registerAttempt')
->with('login', '192.168.0.1', ['user' => 'john']);
$this->dispatcher
->expects($this->once())
->method('dispatchTyped')
->with(new LoginFailed('john', 'doe'));

$userSession->logClientIn('john', 'doe', $request, $this->throttler);
}

Expand Down Expand Up @@ -550,7 +559,7 @@ public function testLogClientInNoTokenPasswordNo2fa(): void {
->method('getRemoteAddress')
->willReturn('192.168.0.1');
$this->throttler
->expects($this->once())
->expects($this->exactly(2))
->method('sleepDelayOrThrowOnMax')
->with('192.168.0.1');
$this->throttler
Expand All @@ -559,6 +568,15 @@ public function testLogClientInNoTokenPasswordNo2fa(): void {
->with('192.168.0.1')
->willReturn(0);

$this->throttler
->expects($this->once())
->method('registerAttempt')
->with('login', '192.168.0.1', ['user' => 'john']);
$this->dispatcher
->expects($this->once())
->method('dispatchTyped')
->with(new LoginFailed('john', 'doe'));

$userSession->logClientIn('john', 'doe', $request, $this->throttler);
}

Expand Down
Loading