CryptoSessionDataTest.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  6. * SPDX-License-Identifier: AGPL-3.0-only
  7. */
  8. namespace Test\Session;
  9. use OC\Session\LegacyCryptoSessionData;
  10. use OCP\Security\ICrypto;
  11. class CryptoSessionDataTest extends Session {
  12. /** @var \PHPUnit\Framework\MockObject\MockObject|\OCP\Security\ICrypto */
  13. protected $crypto;
  14. /** @var \OCP\ISession */
  15. protected $wrappedSession;
  16. protected function setUp(): void {
  17. parent::setUp();
  18. $this->wrappedSession = new \OC\Session\Memory();
  19. $this->crypto = $this->createMock(ICrypto::class);
  20. $this->crypto->expects($this->any())
  21. ->method('encrypt')
  22. ->willReturnCallback(function ($input) {
  23. return '#' . $input . '#';
  24. });
  25. $this->crypto->expects($this->any())
  26. ->method('decrypt')
  27. ->willReturnCallback(function ($input) {
  28. if ($input === '') {
  29. return '';
  30. }
  31. return substr($input, 1, -1);
  32. });
  33. $this->instance = new LegacyCryptoSessionData($this->wrappedSession, $this->crypto, 'PASS');
  34. }
  35. }