diff options
author | Julius Knorr <jus@bitgrid.net> | 2025-02-28 11:59:10 +0100 |
---|---|---|
committer | Andy Scherzinger <info@andy-scherzinger.de> | 2025-03-28 15:16:34 +0100 |
commit | a9d2ac3472784a99556cc7625a9709e293bbaf5d (patch) | |
tree | ff288902b265d1f8285544ab158ce06a54790815 | |
parent | a68978b5ba2c263913c1d8e97b7c6965cacf7f91 (diff) | |
download | nextcloud-server-backport/51130/stable29.tar.gz nextcloud-server-backport/51130/stable29.zip |
fix: Do not build encrypted password if there is nonebackport/51130/stable29
Signed-off-by: Julius Knorr <jus@bitgrid.net>
-rw-r--r-- | lib/private/Authentication/LoginCredentials/Store.php | 14 | ||||
-rw-r--r-- | tests/lib/Authentication/LoginCredentials/StoreTest.php | 40 |
2 files changed, 49 insertions, 5 deletions
diff --git a/lib/private/Authentication/LoginCredentials/Store.php b/lib/private/Authentication/LoginCredentials/Store.php index b354611be26..3c056446101 100644 --- a/lib/private/Authentication/LoginCredentials/Store.php +++ b/lib/private/Authentication/LoginCredentials/Store.php @@ -68,7 +68,9 @@ class Store implements IStore { * @param array $params */ public function authenticate(array $params) { - $params['password'] = $this->crypto->encrypt((string)$params['password']); + if ($params['password'] !== null) { + $params['password'] = $this->crypto->encrypt((string)$params['password']); + } $this->session->set('login_credentials', json_encode($params)); } @@ -115,10 +117,12 @@ class Store implements IStore { if ($trySession && $this->session->exists('login_credentials')) { /** @var array $creds */ $creds = json_decode($this->session->get('login_credentials'), true); - try { - $creds['password'] = $this->crypto->decrypt($creds['password']); - } catch (Exception $e) { - //decryption failed, continue with old password as it is + if ($creds['password'] !== null) { + try { + $creds['password'] = $this->crypto->decrypt($creds['password']); + } catch (Exception $e) { + //decryption failed, continue with old password as it is + } } return new Credentials( $creds['uid'], diff --git a/tests/lib/Authentication/LoginCredentials/StoreTest.php b/tests/lib/Authentication/LoginCredentials/StoreTest.php index 8c1dd2272b2..7e4501c5c10 100644 --- a/tests/lib/Authentication/LoginCredentials/StoreTest.php +++ b/tests/lib/Authentication/LoginCredentials/StoreTest.php @@ -270,4 +270,44 @@ class StoreTest extends TestCase { $this->store->getLoginCredentials(); } + + public function testAuthenticatePasswordlessToken(): void { + $user = 'user987'; + $password = null; + + $params = [ + 'run' => true, + 'loginName' => $user, + 'uid' => $user, + 'password' => $password, + ]; + + $this->session->expects($this->once()) + ->method('set') + ->with($this->equalTo('login_credentials'), $this->equalTo(json_encode($params))); + + + $this->session->expects($this->once()) + ->method('getId') + ->willReturn('sess2233'); + $this->tokenProvider->expects($this->once()) + ->method('getToken') + ->with('sess2233') + ->will($this->throwException(new PasswordlessTokenException())); + + $this->session->expects($this->once()) + ->method('exists') + ->with($this->equalTo('login_credentials')) + ->willReturn(true); + $this->session->expects($this->once()) + ->method('get') + ->with($this->equalTo('login_credentials')) + ->willReturn(json_encode($params)); + + $this->store->authenticate($params); + $actual = $this->store->getLoginCredentials(); + + $expected = new Credentials($user, $user, $password); + $this->assertEquals($expected, $actual); + } } |