EncryptionWrapperTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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\ILogger;
  26. use Test\TestCase;
  27. class EncryptionWrapperTest extends TestCase {
  28. /** @var EncryptionWrapper */
  29. private $instance;
  30. /** @var \PHPUnit_Framework_MockObject_MockObject | \OCP\ILogger */
  31. private $logger;
  32. /** @var \PHPUnit_Framework_MockObject_MockObject | \OC\Encryption\Manager */
  33. private $manager;
  34. /** @var \PHPUnit_Framework_MockObject_MockObject | \OC\Memcache\ArrayCache */
  35. private $arrayCache;
  36. public function setUp() {
  37. parent::setUp();
  38. $this->arrayCache = $this->createMock(ArrayCache::class);
  39. $this->manager = $this->createMock(Manager::class);
  40. $this->logger = $this->createMock(ILogger::class);
  41. $this->logger = $this->createMock(ILogger::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('OC\Files\Storage\Storage')
  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, ['OCA\Files_Sharing\SharedStorage']],
  75. [false, ['OCA\Files_Sharing\External\Storage']],
  76. [false, ['OC\Files\Storage\OwnCloud']],
  77. [false, ['OCA\Files_Sharing\SharedStorage', 'OCA\Files_Sharing\External\Storage']],
  78. [false, ['OCA\Files_Sharing\SharedStorage', 'OC\Files\Storage\OwnCloud']],
  79. [false, ['OCA\Files_Sharing\External\Storage', 'OC\Files\Storage\OwnCloud']],
  80. [false, ['OCA\Files_Sharing\SharedStorage', 'OCA\Files_Sharing\External\Storage', 'OC\Files\Storage\OwnCloud']],
  81. ];
  82. }
  83. }