CryptoSessionDataTest.php 1.0 KB

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