1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
<?php
/**
* @copyright 2016, Roeland Jago Douma <roeland@famdouma.nl>
*
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace Test\Lockdown\Filesystem;
use Icewind\Streams\IteratorDirectory;
use OC\ForbiddenException;
use OC\Lockdown\Filesystem\NullCache;
use OC\Lockdown\Filesystem\NullStorage;
use OCP\Files\Storage;
use Test\TestCase;
class NullStorageTest extends TestCase {
/** @var NullStorage */
private $storage;
public function setUp() {
parent::setUp();
$this->storage = new NullStorage([]);
}
public function testGetId() {
$this->assertSame('null', $this->storage->getId());
}
public function testMkdir() {
$this->expectException(ForbiddenException::class);
$this->expectExceptionMessage('This request is not allowed to access the filesystem');
$this->storage->mkdir('foo');
}
public function testRmdir() {
$this->expectException(ForbiddenException::class);
$this->expectExceptionMessage('This request is not allowed to access the filesystem');
$this->storage->rmdir('foo');
}
public function testOpendir() {
$this->assertInstanceOf(IteratorDirectory::class, $this->storage->opendir('foo'));
}
public function testIs_dir() {
$this->assertTrue($this->storage->is_dir(''));
$this->assertFalse($this->storage->is_dir('foo'));
}
public function testIs_file() {
$this->assertFalse($this->storage->is_file('foo'));
}
public function testStat() {
$this->expectException(ForbiddenException::class);
$this->expectExceptionMessage('This request is not allowed to access the filesystem');
$this->storage->stat('foo');
}
public function testFiletype() {
$this->assertSame('dir', $this->storage->filetype(''));
$this->assertFalse($this->storage->filetype('foo'));
}
public function testFilesize() {
$this->expectException(ForbiddenException::class);
$this->expectExceptionMessage('This request is not allowed to access the filesystem');
$this->storage->filesize('foo');
}
public function testIsCreatable() {
$this->assertFalse($this->storage->isCreatable('foo'));
}
public function testIsReadable() {
$this->assertTrue($this->storage->isReadable(''));
$this->assertFalse($this->storage->isReadable('foo'));
}
public function testIsUpdatable() {
$this->assertFalse($this->storage->isUpdatable('foo'));
}
public function testIsDeletable() {
$this->assertFalse($this->storage->isDeletable('foo'));
}
public function testIsSharable() {
$this->assertFalse($this->storage->isSharable('foo'));
}
public function testGetPermissions() {
$this->assertNull($this->storage->getPermissions('foo'));
}
public function testFile_exists() {
$this->assertTrue($this->storage->file_exists(''));
$this->assertFalse($this->storage->file_exists('foo'));
}
public function testFilemtime() {
$this->assertFalse($this->storage->isReadable('foo'));
}
public function testFile_get_contents() {
$this->expectException(ForbiddenException::class);
$this->expectExceptionMessage('This request is not allowed to access the filesystem');
$this->storage->file_get_contents('foo');
}
public function testFile_put_contents() {
$this->expectException(ForbiddenException::class);
$this->expectExceptionMessage('This request is not allowed to access the filesystem');
$this->storage->file_put_contents('foo', 'bar');
}
public function testUnlink() {
$this->expectException(ForbiddenException::class);
$this->expectExceptionMessage('This request is not allowed to access the filesystem');
$this->storage->unlink('foo');
}
public function testRename() {
$this->expectException(ForbiddenException::class);
$this->expectExceptionMessage('This request is not allowed to access the filesystem');
$this->storage->rename('foo', 'bar');
}
public function testCopy() {
$this->expectException(ForbiddenException::class);
$this->expectExceptionMessage('This request is not allowed to access the filesystem');
$this->storage->copy('foo', 'bar');
}
public function testFopen() {
$this->expectException(ForbiddenException::class);
$this->expectExceptionMessage('This request is not allowed to access the filesystem');
$this->storage->fopen('foo', 'R');
}
public function testGetMimeType() {
$this->expectException(ForbiddenException::class);
$this->expectExceptionMessage('This request is not allowed to access the filesystem');
$this->storage->getMimeType('foo');
}
public function testHash() {
$this->expectException(ForbiddenException::class);
$this->expectExceptionMessage('This request is not allowed to access the filesystem');
$this->storage->hash('md5', 'foo', true);
}
public function testFree_space() {
$this->assertSame(0, $this->storage->free_space('foo'));
}
public function testTouch() {
$this->expectException(ForbiddenException::class);
$this->expectExceptionMessage('This request is not allowed to access the filesystem');
$this->storage->touch('foo');
}
public function testGetLocalFile() {
$this->assertFalse($this->storage->getLocalFile('foo'));
}
public function testHasUpdated() {
$this->assertFalse($this->storage->hasUpdated('foo', 42));
}
public function testGetETag() {
$this->assertSame('', $this->storage->getETag('foo'));
}
public function testIsLocal() {
$this->assertFalse($this->storage->isLocal());
}
public function testGetDirectDownload() {
$this->assertFalse($this->storage->getDirectDownload('foo'));
}
public function testCopyFromStorage() {
$sourceStorage = $this->createMock(Storage::class);
$this->expectException(ForbiddenException::class);
$this->expectExceptionMessage('This request is not allowed to access the filesystem');
$this->storage->copyFromStorage($sourceStorage, 'foo', 'bar');
}
public function testMoveFromStorage() {
$sourceStorage = $this->createMock(Storage::class);
$this->expectException(ForbiddenException::class);
$this->expectExceptionMessage('This request is not allowed to access the filesystem');
$this->storage->moveFromStorage($sourceStorage, 'foo', 'bar');
}
public function testTest() {
$this->assertTrue($this->storage->test());
return true;
}
public function testGetOwner() {
$this->assertNull($this->storage->getOwner('foo'));
}
public function testGetCache() {
$this->assertInstanceOf(NullCache::class, $this->storage->getCache('foo'));
}
}
|