mirror of
https://github.com/nextcloud/server.git
synced 2026-02-15 08:48:14 -05:00
Merge pull request #51327 from nextcloud/backport/51130/stable30
[stable30] fix: Do not build encrypted password if there is none
This commit is contained in:
commit
5ebcf9b72b
2 changed files with 49 additions and 5 deletions
|
|
@ -50,7 +50,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));
|
||||
}
|
||||
|
||||
|
|
@ -97,10 +99,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'],
|
||||
|
|
|
|||
|
|
@ -253,4 +253,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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue