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

Convert 2FA token type to string #25275

Merged
merged 1 commit into from
Jan 22, 2021
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
6 changes: 3 additions & 3 deletions lib/private/Authentication/TwoFactorAuth/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ public function needsSecondFactor(IUser $user = null): bool {
$tokenId = $token->getId();
$tokensNeeding2FA = $this->config->getUserKeys($user->getUID(), 'login_token_2fa');

if (!\in_array($tokenId, $tokensNeeding2FA, true)) {
if (!\in_array((string) $tokenId, $tokensNeeding2FA, true)) {
$this->session->set(self::SESSION_UID_DONE, $user->getUID());
return false;
}
Expand Down Expand Up @@ -376,14 +376,14 @@ public function prepareTwoFactorLogin(IUser $user, bool $rememberMe) {

$id = $this->session->getId();
$token = $this->tokenProvider->getToken($id);
$this->config->setUserValue($user->getUID(), 'login_token_2fa', $token->getId(), $this->timeFactory->getTime());
$this->config->setUserValue($user->getUID(), 'login_token_2fa', (string) $token->getId(), $this->timeFactory->getTime());
}

public function clearTwoFactorPending(string $userId) {
$tokensNeeding2FA = $this->config->getUserKeys($userId, 'login_token_2fa');

foreach ($tokensNeeding2FA as $tokenId) {
$this->tokenProvider->invalidateTokenById($userId, $tokenId);
$this->tokenProvider->invalidateTokenById($userId, (int)$tokenId);
}
}
}
10 changes: 5 additions & 5 deletions tests/lib/Authentication/TwoFactorAuth/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ public function testVerifyChallenge() {
->willReturn(42);
$this->config->expects($this->once())
->method('deleteUserValue')
->with('jos', 'login_token_2fa', 42);
->with('jos', 'login_token_2fa', '42');

$result = $this->manager->verifyChallenge('email', $this->user, $challenge);

Expand Down Expand Up @@ -515,7 +515,7 @@ public function testNeedsSecondFactor() {
$this->config->method('getUserKeys')
->with('user', 'login_token_2fa')
->willReturn([
42
'42'
]);

$manager = $this->getMockBuilder(Manager::class)
Expand Down Expand Up @@ -588,7 +588,7 @@ public function testPrepareTwoFactorLogin() {
->willReturn(1337);

$this->config->method('setUserValue')
->with('ferdinand', 'login_token_2fa', 42, 1337);
->with('ferdinand', 'login_token_2fa', '42', '1337');


$this->manager->prepareTwoFactorLogin($this->user, true);
Expand Down Expand Up @@ -618,7 +618,7 @@ public function testPrepareTwoFactorLoginDontRemember() {
->willReturn(1337);

$this->config->method('setUserValue')
->with('ferdinand', 'login_token_2fa', 42, 1337);
->with('ferdinand', 'login_token_2fa', '42', '1337');

$this->manager->prepareTwoFactorLogin($this->user, false);
}
Expand Down Expand Up @@ -666,7 +666,7 @@ public function testNeedsSecondFactorSessionAuthFailDBPass() {
$this->config->method('getUserKeys')
->with('user', 'login_token_2fa')
->willReturn([
42, 43, 44
'42', '43', '44'
]);

$this->session->expects($this->once())
Expand Down