nextcloud/tests/lib/Session/CryptoSessionDataTest.php
Christoph Wurst aee7a7daac
fixup! fix(session): Make session encryption more robust
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
2024-08-28 10:13:43 +02:00

44 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/
namespace Test\Session;
use OC\Session\LegacyCryptoSessionData;
use OCP\Security\ICrypto;
class CryptoSessionDataTest extends Session {
/** @var \PHPUnit\Framework\MockObject\MockObject|\OCP\Security\ICrypto */
protected $crypto;
/** @var \OCP\ISession */
protected $wrappedSession;
protected function setUp(): void {
parent::setUp();
$this->wrappedSession = new \OC\Session\Memory();
$this->crypto = $this->createMock(ICrypto::class);
$this->crypto->expects($this->any())
->method('encrypt')
->willReturnCallback(function ($input) {
return '#' . $input . '#';
});
$this->crypto->expects($this->any())
->method('decrypt')
->willReturnCallback(function ($input) {
if ($input === '') {
return '';
}
return substr($input, 1, -1);
});
$this->instance = new LegacyCryptoSessionData($this->wrappedSession, $this->crypto, 'PASS');
}
}