1
0

EncryptionWrapperTest.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * @author Björn Schießle <schiessle@owncloud.com>
  4. *
  5. * @copyright Copyright (c) 2016, ownCloud, Inc.
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. namespace Test\Encryption;
  22. use OC\Encryption\EncryptionWrapper;
  23. use OC\Encryption\Manager;
  24. use OC\Memcache\ArrayCache;
  25. use OCP\Files\Storage;
  26. use Psr\Log\LoggerInterface;
  27. use Test\TestCase;
  28. class EncryptionWrapperTest extends TestCase {
  29. /** @var EncryptionWrapper */
  30. private $instance;
  31. /** @var \PHPUnit\Framework\MockObject\MockObject | LoggerInterface */
  32. private $logger;
  33. /** @var \PHPUnit\Framework\MockObject\MockObject | \OC\Encryption\Manager */
  34. private $manager;
  35. /** @var \PHPUnit\Framework\MockObject\MockObject | \OC\Memcache\ArrayCache */
  36. private $arrayCache;
  37. protected function setUp(): void {
  38. parent::setUp();
  39. $this->arrayCache = $this->createMock(ArrayCache::class);
  40. $this->manager = $this->createMock(Manager::class);
  41. $this->logger = $this->createMock(LoggerInterface::class);
  42. $this->instance = new EncryptionWrapper($this->arrayCache, $this->manager, $this->logger);
  43. }
  44. /**
  45. * @dataProvider provideWrapStorage
  46. */
  47. public function testWrapStorage($expectedWrapped, $wrappedStorages) {
  48. $storage = $this->getMockBuilder(Storage::class)
  49. ->disableOriginalConstructor()
  50. ->getMock();
  51. foreach ($wrappedStorages as $wrapper) {
  52. $storage->expects($this->any())
  53. ->method('instanceOfStorage')
  54. ->willReturnMap([
  55. [$wrapper, true],
  56. ]);
  57. }
  58. $mount = $this->getMockBuilder('OCP\Files\Mount\IMountPoint')
  59. ->disableOriginalConstructor()
  60. ->getMock();
  61. $returnedStorage = $this->instance->wrapStorage('mountPoint', $storage, $mount);
  62. $this->assertEquals(
  63. $expectedWrapped,
  64. $returnedStorage->instanceOfStorage('OC\Files\Storage\Wrapper\Encryption'),
  65. 'Asserted that the storage is (not) wrapped with encryption'
  66. );
  67. }
  68. public function provideWrapStorage() {
  69. return [
  70. // Wrap when not wrapped or not wrapped with storage
  71. [true, []],
  72. [true, ['OCA\Files_Trashbin\Storage']],
  73. // Do not wrap shared storages
  74. [false, [Storage\IDisableEncryptionStorage::class]],
  75. ];
  76. }
  77. }