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: 7 additions & 2 deletions lib/private/Authentication/LoginCredentials/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,13 @@ public function getLoginCredentials(): ICredentials {
}

if ($trySession && $this->session->exists('login_credentials')) {
$creds = json_decode($this->session->get('login_credentials'));
return new Credentials($creds->uid, $creds->loginName, $creds->password);
/** @var array $creds */
$creds = json_decode($this->session->get('login_credentials'), true);
return new Credentials(
$creds['uid'],
$creds['loginName'] ?? $this->session->get('loginname') ?? $creds['uid'], // Pre 20 didn't have a loginName property, hence fall back to the session value and then to the UID
$creds['password']
);
}

// If we reach this line, an exception was thrown.
Expand Down
76 changes: 76 additions & 0 deletions tests/lib/Authentication/LoginCredentials/StoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use OCP\ISession;
use OCP\Session\Exceptions\SessionNotAvailableException;
use Test\TestCase;
use function json_encode;

class StoreTest extends TestCase {

Expand Down Expand Up @@ -140,6 +141,81 @@ public function testGetLoginCredentialsInvalidToken() {
$this->store->getLoginCredentials();
}

public function testGetLoginCredentialsPartialCredentialsAndSessionName() {
$uid = 'id987';
$user = 'user987';
$password = '7389374';

$this->session->expects($this->once())
->method('getId')
->willReturn('sess2233');
$this->tokenProvider->expects($this->once())
->method('getToken')
->with('sess2233')
->will($this->throwException(new InvalidTokenException()));
$this->session->expects($this->once())
->method('exists')
->with($this->equalTo('login_credentials'))
->willReturn(true);
$this->session->expects($this->exactly(2))
->method('get')
->willReturnMap([
[
'login_credentials',
json_encode([
'uid' => $uid,
'password' => $password,
])
],
[
'loginname',
$user,
],
]);
$expected = new Credentials($uid, $user, $password);

$actual = $this->store->getLoginCredentials();

$this->assertEquals($expected, $actual);
}

public function testGetLoginCredentialsPartialCredentials() {
$uid = 'id987';
$password = '7389374';

$this->session->expects($this->once())
->method('getId')
->willReturn('sess2233');
$this->tokenProvider->expects($this->once())
->method('getToken')
->with('sess2233')
->will($this->throwException(new InvalidTokenException()));
$this->session->expects($this->once())
->method('exists')
->with($this->equalTo('login_credentials'))
->willReturn(true);
$this->session->expects($this->exactly(2))
->method('get')
->willReturnMap([
[
'login_credentials',
json_encode([
'uid' => $uid,
'password' => $password,
])
],
[
'loginname',
null,
],
]);
$expected = new Credentials($uid, $uid, $password);

$actual = $this->store->getLoginCredentials();

$this->assertEquals($expected, $actual);
}

public function testGetLoginCredentialsInvalidTokenLoginCredentials() {
$uid = 'id987';
$user = 'user987';
Expand Down