Skip to content

Commit ebe9432

Browse files
juliusknorrAndyScherzinger
authored andcommitted
fix: Do not build encrypted password if there is none
Signed-off-by: Julius Knorr <jus@bitgrid.net>
1 parent 559d6e8 commit ebe9432

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed

lib/private/Authentication/LoginCredentials/Store.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ public function __construct(
5050
* @param array $params
5151
*/
5252
public function authenticate(array $params) {
53-
$params['password'] = $this->crypto->encrypt((string)$params['password']);
53+
if ($params['password'] !== null) {
54+
$params['password'] = $this->crypto->encrypt((string)$params['password']);
55+
}
5456
$this->session->set('login_credentials', json_encode($params));
5557
}
5658

@@ -97,10 +99,12 @@ public function getLoginCredentials(): ICredentials {
9799
if ($trySession && $this->session->exists('login_credentials')) {
98100
/** @var array $creds */
99101
$creds = json_decode($this->session->get('login_credentials'), true);
100-
try {
101-
$creds['password'] = $this->crypto->decrypt($creds['password']);
102-
} catch (Exception $e) {
103-
//decryption failed, continue with old password as it is
102+
if ($creds['password'] !== null) {
103+
try {
104+
$creds['password'] = $this->crypto->decrypt($creds['password']);
105+
} catch (Exception $e) {
106+
//decryption failed, continue with old password as it is
107+
}
104108
}
105109
return new Credentials(
106110
$creds['uid'],

tests/lib/Authentication/LoginCredentials/StoreTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,4 +253,44 @@ public function testGetLoginCredentialsPasswordlessToken() {
253253

254254
$this->store->getLoginCredentials();
255255
}
256+
257+
public function testAuthenticatePasswordlessToken(): void {
258+
$user = 'user987';
259+
$password = null;
260+
261+
$params = [
262+
'run' => true,
263+
'loginName' => $user,
264+
'uid' => $user,
265+
'password' => $password,
266+
];
267+
268+
$this->session->expects($this->once())
269+
->method('set')
270+
->with($this->equalTo('login_credentials'), $this->equalTo(json_encode($params)));
271+
272+
273+
$this->session->expects($this->once())
274+
->method('getId')
275+
->willReturn('sess2233');
276+
$this->tokenProvider->expects($this->once())
277+
->method('getToken')
278+
->with('sess2233')
279+
->will($this->throwException(new PasswordlessTokenException()));
280+
281+
$this->session->expects($this->once())
282+
->method('exists')
283+
->with($this->equalTo('login_credentials'))
284+
->willReturn(true);
285+
$this->session->expects($this->once())
286+
->method('get')
287+
->with($this->equalTo('login_credentials'))
288+
->willReturn(json_encode($params));
289+
290+
$this->store->authenticate($params);
291+
$actual = $this->store->getLoginCredentials();
292+
293+
$expected = new Credentials($user, $user, $password);
294+
$this->assertEquals($expected, $actual);
295+
}
256296
}

0 commit comments

Comments
 (0)