|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Björn Schießle <[email protected]> |
|
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
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
namespace Test\Encryption; |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
use OC\Encryption\EncryptionWrapper; |
|
27
|
|
|
use Test\TestCase; |
|
28
|
|
|
|
|
29
|
|
|
class EncryptionWrapperTest extends TestCase { |
|
30
|
|
|
|
|
31
|
|
|
/** @var EncryptionWrapper */ |
|
32
|
|
|
private $instance; |
|
33
|
|
|
|
|
34
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject | \OCP\ILogger */ |
|
35
|
|
|
private $logger; |
|
36
|
|
|
|
|
37
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject | \OC\Encryption\Manager */ |
|
38
|
|
|
private $manager; |
|
39
|
|
|
|
|
40
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject | \OC\Memcache\ArrayCache */ |
|
41
|
|
|
private $arrayCache; |
|
42
|
|
|
|
|
43
|
|
View Code Duplication |
public function setUp() { |
|
44
|
|
|
parent::setUp(); |
|
45
|
|
|
|
|
46
|
|
|
$this->arrayCache = $this->getMock('OC\Memcache\ArrayCache'); |
|
47
|
|
|
$this->manager = $this->getMockBuilder('OC\Encryption\Manager') |
|
48
|
|
|
->disableOriginalConstructor()->getMock(); |
|
49
|
|
|
$this->logger = $this->getMock('OCP\ILogger'); |
|
50
|
|
|
|
|
51
|
|
|
$this->instance = new EncryptionWrapper($this->arrayCache, $this->manager, $this->logger); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @dataProvider provideWrapStorage |
|
57
|
|
|
*/ |
|
58
|
|
|
public function testWrapStorage($expectedWrapped, $wrappedStorages) { |
|
59
|
|
|
$storage = $this->getMockBuilder('OC\Files\Storage\Storage') |
|
60
|
|
|
->disableOriginalConstructor() |
|
61
|
|
|
->getMock(); |
|
62
|
|
|
|
|
63
|
|
|
foreach ($wrappedStorages as $wrapper) { |
|
64
|
|
|
$storage->expects($this->any()) |
|
65
|
|
|
->method('instanceOfStorage') |
|
66
|
|
|
->willReturnMap([ |
|
67
|
|
|
[$wrapper, true], |
|
68
|
|
|
]); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
$mount = $this->getMockBuilder('OCP\Files\Mount\IMountPoint') |
|
72
|
|
|
->disableOriginalConstructor() |
|
73
|
|
|
->getMock(); |
|
74
|
|
|
|
|
75
|
|
|
$returnedStorage = $this->instance->wrapStorage('mountPoint', $storage, $mount); |
|
76
|
|
|
|
|
77
|
|
|
$this->assertEquals( |
|
78
|
|
|
$expectedWrapped, |
|
79
|
|
|
$returnedStorage->instanceOfStorage('OC\Files\Storage\Wrapper\Encryption'), |
|
80
|
|
|
'Asserted that the storage is (not) wrapped with encryption' |
|
81
|
|
|
); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function provideWrapStorage() { |
|
85
|
|
|
return [ |
|
86
|
|
|
// Wrap when not wrapped or not wrapped with storage |
|
87
|
|
|
[true, []], |
|
88
|
|
|
[true, ['OCA\Files_Trashbin\Storage']], |
|
89
|
|
|
|
|
90
|
|
|
// Do not wrap shared storages |
|
91
|
|
|
[false, ['OC\Files\Storage\Shared']], |
|
92
|
|
|
[false, ['OCA\Files_Sharing\External\Storage']], |
|
93
|
|
|
[false, ['OC\Files\Storage\OwnCloud']], |
|
94
|
|
|
[false, ['OC\Files\Storage\Shared', 'OCA\Files_Sharing\External\Storage']], |
|
95
|
|
|
[false, ['OC\Files\Storage\Shared', 'OC\Files\Storage\OwnCloud']], |
|
96
|
|
|
[false, ['OCA\Files_Sharing\External\Storage', 'OC\Files\Storage\OwnCloud']], |
|
97
|
|
|
[false, ['OC\Files\Storage\Shared', 'OCA\Files_Sharing\External\Storage', 'OC\Files\Storage\OwnCloud']], |
|
98
|
|
|
]; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
} |
|
102
|
|
|
|