Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2020-09-07 12:21:16 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2020-09-07 14:31:24 +0300
commitadf100a42ffdbcc25eda717c8a80e0ba0458f437 (patch)
treefb592835037c0d49d517ad16a022ea496580bcbd /tests/lib/Authentication
parent3eb748fc39e24c57f2ba57ed4fd089dd746bdd61 (diff)
Fix undefined class property access after upgrade from 19 to 20
The serialized data in 19 has one property less and this was not considered in the code. Hence adding a fallback. Moreover I'm changing the deserialization into an array instead of object, as that is the safer option. Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'tests/lib/Authentication')
-rw-r--r--tests/lib/Authentication/LoginCredentials/StoreTest.php76
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/lib/Authentication/LoginCredentials/StoreTest.php b/tests/lib/Authentication/LoginCredentials/StoreTest.php
index 67cb0a18297..ad8a074660c 100644
--- a/tests/lib/Authentication/LoginCredentials/StoreTest.php
+++ b/tests/lib/Authentication/LoginCredentials/StoreTest.php
@@ -35,6 +35,7 @@ use OCP\ILogger;
use OCP\ISession;
use OCP\Session\Exceptions\SessionNotAvailableException;
use Test\TestCase;
+use function json_encode;
class StoreTest extends TestCase {
@@ -140,6 +141,81 @@ class StoreTest extends TestCase {
$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';