@@ -28,357 +28,357 @@ |
||
28 | 28 | */ |
29 | 29 | class PublicAuthTest extends \Test\TestCase { |
30 | 30 | |
31 | - private ISession&MockObject $session; |
|
32 | - private IRequest&MockObject $request; |
|
33 | - private IManager&MockObject $shareManager; |
|
34 | - private IThrottler&MockObject $throttler; |
|
35 | - private LoggerInterface&MockObject $logger; |
|
36 | - private IURLGenerator&MockObject $urlGenerator; |
|
37 | - private PublicAuth $auth; |
|
38 | - |
|
39 | - private bool|string $oldUser; |
|
40 | - |
|
41 | - protected function setUp(): void { |
|
42 | - parent::setUp(); |
|
43 | - |
|
44 | - $this->session = $this->createMock(ISession::class); |
|
45 | - $this->request = $this->createMock(IRequest::class); |
|
46 | - $this->shareManager = $this->createMock(IManager::class); |
|
47 | - $this->throttler = $this->createMock(IThrottler::class); |
|
48 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
49 | - $this->urlGenerator = $this->createMock(IURLGenerator::class); |
|
50 | - |
|
51 | - $this->auth = new PublicAuth( |
|
52 | - $this->request, |
|
53 | - $this->shareManager, |
|
54 | - $this->session, |
|
55 | - $this->throttler, |
|
56 | - $this->logger, |
|
57 | - $this->urlGenerator, |
|
58 | - ); |
|
59 | - |
|
60 | - // Store current user |
|
61 | - $this->oldUser = \OC_User::getUser(); |
|
62 | - } |
|
63 | - |
|
64 | - protected function tearDown(): void { |
|
65 | - \OC_User::setIncognitoMode(false); |
|
66 | - |
|
67 | - // Set old user |
|
68 | - \OC_User::setUserId($this->oldUser); |
|
69 | - if ($this->oldUser !== false) { |
|
70 | - \OC_Util::setupFS($this->oldUser); |
|
71 | - } |
|
72 | - |
|
73 | - parent::tearDown(); |
|
74 | - } |
|
75 | - |
|
76 | - public function testGetToken(): void { |
|
77 | - $this->request->method('getPathInfo') |
|
78 | - ->willReturn('/dav/files/GX9HSGQrGE'); |
|
79 | - |
|
80 | - $result = self::invokePrivate($this->auth, 'getToken'); |
|
81 | - |
|
82 | - $this->assertSame('GX9HSGQrGE', $result); |
|
83 | - } |
|
84 | - |
|
85 | - public function testGetTokenInvalid(): void { |
|
86 | - $this->request->method('getPathInfo') |
|
87 | - ->willReturn('/dav/files'); |
|
88 | - |
|
89 | - $this->expectException(\Sabre\DAV\Exception\NotFound::class); |
|
90 | - self::invokePrivate($this->auth, 'getToken'); |
|
91 | - } |
|
92 | - |
|
93 | - public function testCheckTokenValidShare(): void { |
|
94 | - $this->request->method('getPathInfo') |
|
95 | - ->willReturn('/dav/files/GX9HSGQrGE'); |
|
96 | - |
|
97 | - $share = $this->createMock(IShare::class); |
|
98 | - $share->method('getPassword')->willReturn(null); |
|
99 | - |
|
100 | - $this->shareManager->expects($this->once()) |
|
101 | - ->method('getShareByToken') |
|
102 | - ->with('GX9HSGQrGE') |
|
103 | - ->willReturn($share); |
|
104 | - |
|
105 | - $result = self::invokePrivate($this->auth, 'checkToken'); |
|
106 | - $this->assertSame([true, 'principals/GX9HSGQrGE'], $result); |
|
107 | - } |
|
31 | + private ISession&MockObject $session; |
|
32 | + private IRequest&MockObject $request; |
|
33 | + private IManager&MockObject $shareManager; |
|
34 | + private IThrottler&MockObject $throttler; |
|
35 | + private LoggerInterface&MockObject $logger; |
|
36 | + private IURLGenerator&MockObject $urlGenerator; |
|
37 | + private PublicAuth $auth; |
|
38 | + |
|
39 | + private bool|string $oldUser; |
|
40 | + |
|
41 | + protected function setUp(): void { |
|
42 | + parent::setUp(); |
|
43 | + |
|
44 | + $this->session = $this->createMock(ISession::class); |
|
45 | + $this->request = $this->createMock(IRequest::class); |
|
46 | + $this->shareManager = $this->createMock(IManager::class); |
|
47 | + $this->throttler = $this->createMock(IThrottler::class); |
|
48 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
49 | + $this->urlGenerator = $this->createMock(IURLGenerator::class); |
|
50 | + |
|
51 | + $this->auth = new PublicAuth( |
|
52 | + $this->request, |
|
53 | + $this->shareManager, |
|
54 | + $this->session, |
|
55 | + $this->throttler, |
|
56 | + $this->logger, |
|
57 | + $this->urlGenerator, |
|
58 | + ); |
|
59 | + |
|
60 | + // Store current user |
|
61 | + $this->oldUser = \OC_User::getUser(); |
|
62 | + } |
|
63 | + |
|
64 | + protected function tearDown(): void { |
|
65 | + \OC_User::setIncognitoMode(false); |
|
66 | + |
|
67 | + // Set old user |
|
68 | + \OC_User::setUserId($this->oldUser); |
|
69 | + if ($this->oldUser !== false) { |
|
70 | + \OC_Util::setupFS($this->oldUser); |
|
71 | + } |
|
72 | + |
|
73 | + parent::tearDown(); |
|
74 | + } |
|
75 | + |
|
76 | + public function testGetToken(): void { |
|
77 | + $this->request->method('getPathInfo') |
|
78 | + ->willReturn('/dav/files/GX9HSGQrGE'); |
|
79 | + |
|
80 | + $result = self::invokePrivate($this->auth, 'getToken'); |
|
81 | + |
|
82 | + $this->assertSame('GX9HSGQrGE', $result); |
|
83 | + } |
|
84 | + |
|
85 | + public function testGetTokenInvalid(): void { |
|
86 | + $this->request->method('getPathInfo') |
|
87 | + ->willReturn('/dav/files'); |
|
88 | + |
|
89 | + $this->expectException(\Sabre\DAV\Exception\NotFound::class); |
|
90 | + self::invokePrivate($this->auth, 'getToken'); |
|
91 | + } |
|
92 | + |
|
93 | + public function testCheckTokenValidShare(): void { |
|
94 | + $this->request->method('getPathInfo') |
|
95 | + ->willReturn('/dav/files/GX9HSGQrGE'); |
|
96 | + |
|
97 | + $share = $this->createMock(IShare::class); |
|
98 | + $share->method('getPassword')->willReturn(null); |
|
99 | + |
|
100 | + $this->shareManager->expects($this->once()) |
|
101 | + ->method('getShareByToken') |
|
102 | + ->with('GX9HSGQrGE') |
|
103 | + ->willReturn($share); |
|
104 | + |
|
105 | + $result = self::invokePrivate($this->auth, 'checkToken'); |
|
106 | + $this->assertSame([true, 'principals/GX9HSGQrGE'], $result); |
|
107 | + } |
|
108 | 108 | |
109 | - public function testCheckTokenInvalidShare(): void { |
|
110 | - $this->request->method('getPathInfo') |
|
111 | - ->willReturn('/dav/files/GX9HSGQrGE'); |
|
109 | + public function testCheckTokenInvalidShare(): void { |
|
110 | + $this->request->method('getPathInfo') |
|
111 | + ->willReturn('/dav/files/GX9HSGQrGE'); |
|
112 | 112 | |
113 | - $this->shareManager |
|
114 | - ->expects($this->once()) |
|
115 | - ->method('getShareByToken') |
|
116 | - ->with('GX9HSGQrGE') |
|
117 | - ->will($this->throwException(new ShareNotFound())); |
|
118 | - |
|
119 | - $this->expectException(\Sabre\DAV\Exception\NotFound::class); |
|
120 | - self::invokePrivate($this->auth, 'checkToken'); |
|
121 | - } |
|
122 | - |
|
123 | - public function testCheckTokenAlreadyAuthenticated(): void { |
|
124 | - $this->request->method('getPathInfo') |
|
125 | - ->willReturn('/dav/files/GX9HSGQrGE'); |
|
113 | + $this->shareManager |
|
114 | + ->expects($this->once()) |
|
115 | + ->method('getShareByToken') |
|
116 | + ->with('GX9HSGQrGE') |
|
117 | + ->will($this->throwException(new ShareNotFound())); |
|
118 | + |
|
119 | + $this->expectException(\Sabre\DAV\Exception\NotFound::class); |
|
120 | + self::invokePrivate($this->auth, 'checkToken'); |
|
121 | + } |
|
122 | + |
|
123 | + public function testCheckTokenAlreadyAuthenticated(): void { |
|
124 | + $this->request->method('getPathInfo') |
|
125 | + ->willReturn('/dav/files/GX9HSGQrGE'); |
|
126 | 126 | |
127 | - $share = $this->createMock(IShare::class); |
|
128 | - $share->method('getShareType')->willReturn(42); |
|
127 | + $share = $this->createMock(IShare::class); |
|
128 | + $share->method('getShareType')->willReturn(42); |
|
129 | 129 | |
130 | - $this->shareManager->expects($this->once()) |
|
131 | - ->method('getShareByToken') |
|
132 | - ->with('GX9HSGQrGE') |
|
133 | - ->willReturn($share); |
|
130 | + $this->shareManager->expects($this->once()) |
|
131 | + ->method('getShareByToken') |
|
132 | + ->with('GX9HSGQrGE') |
|
133 | + ->willReturn($share); |
|
134 | 134 | |
135 | - $this->session->method('exists')->with('public_link_authenticated')->willReturn(true); |
|
136 | - $this->session->method('get')->with('public_link_authenticated')->willReturn('42'); |
|
135 | + $this->session->method('exists')->with('public_link_authenticated')->willReturn(true); |
|
136 | + $this->session->method('get')->with('public_link_authenticated')->willReturn('42'); |
|
137 | 137 | |
138 | - $result = self::invokePrivate($this->auth, 'checkToken'); |
|
139 | - $this->assertSame([true, 'principals/GX9HSGQrGE'], $result); |
|
140 | - } |
|
138 | + $result = self::invokePrivate($this->auth, 'checkToken'); |
|
139 | + $this->assertSame([true, 'principals/GX9HSGQrGE'], $result); |
|
140 | + } |
|
141 | 141 | |
142 | - public function testCheckTokenPasswordNotAuthenticated(): void { |
|
143 | - $this->request->method('getPathInfo') |
|
144 | - ->willReturn('/dav/files/GX9HSGQrGE'); |
|
142 | + public function testCheckTokenPasswordNotAuthenticated(): void { |
|
143 | + $this->request->method('getPathInfo') |
|
144 | + ->willReturn('/dav/files/GX9HSGQrGE'); |
|
145 | 145 | |
146 | - $share = $this->createMock(IShare::class); |
|
147 | - $share->method('getPassword')->willReturn('password'); |
|
148 | - $share->method('getShareType')->willReturn(42); |
|
146 | + $share = $this->createMock(IShare::class); |
|
147 | + $share->method('getPassword')->willReturn('password'); |
|
148 | + $share->method('getShareType')->willReturn(42); |
|
149 | 149 | |
150 | - $this->shareManager->expects($this->once()) |
|
151 | - ->method('getShareByToken') |
|
152 | - ->with('GX9HSGQrGE') |
|
153 | - ->willReturn($share); |
|
150 | + $this->shareManager->expects($this->once()) |
|
151 | + ->method('getShareByToken') |
|
152 | + ->with('GX9HSGQrGE') |
|
153 | + ->willReturn($share); |
|
154 | 154 | |
155 | - $this->session->method('exists')->with('public_link_authenticated')->willReturn(false); |
|
155 | + $this->session->method('exists')->with('public_link_authenticated')->willReturn(false); |
|
156 | 156 | |
157 | - $this->expectException(\Sabre\DAV\Exception\NotAuthenticated::class); |
|
158 | - self::invokePrivate($this->auth, 'checkToken'); |
|
159 | - } |
|
157 | + $this->expectException(\Sabre\DAV\Exception\NotAuthenticated::class); |
|
158 | + self::invokePrivate($this->auth, 'checkToken'); |
|
159 | + } |
|
160 | 160 | |
161 | - public function testCheckTokenPasswordAuthenticatedWrongShare(): void { |
|
162 | - $this->request->method('getPathInfo') |
|
163 | - ->willReturn('/dav/files/GX9HSGQrGE'); |
|
161 | + public function testCheckTokenPasswordAuthenticatedWrongShare(): void { |
|
162 | + $this->request->method('getPathInfo') |
|
163 | + ->willReturn('/dav/files/GX9HSGQrGE'); |
|
164 | 164 | |
165 | - $share = $this->createMock(IShare::class); |
|
166 | - $share->method('getPassword')->willReturn('password'); |
|
167 | - $share->method('getShareType')->willReturn(42); |
|
165 | + $share = $this->createMock(IShare::class); |
|
166 | + $share->method('getPassword')->willReturn('password'); |
|
167 | + $share->method('getShareType')->willReturn(42); |
|
168 | 168 | |
169 | - $this->shareManager->expects($this->once()) |
|
170 | - ->method('getShareByToken') |
|
171 | - ->with('GX9HSGQrGE') |
|
172 | - ->willReturn($share); |
|
169 | + $this->shareManager->expects($this->once()) |
|
170 | + ->method('getShareByToken') |
|
171 | + ->with('GX9HSGQrGE') |
|
172 | + ->willReturn($share); |
|
173 | 173 | |
174 | - $this->session->method('exists')->with('public_link_authenticated')->willReturn(false); |
|
175 | - $this->session->method('get')->with('public_link_authenticated')->willReturn('43'); |
|
174 | + $this->session->method('exists')->with('public_link_authenticated')->willReturn(false); |
|
175 | + $this->session->method('get')->with('public_link_authenticated')->willReturn('43'); |
|
176 | 176 | |
177 | - $this->expectException(\Sabre\DAV\Exception\NotAuthenticated::class); |
|
178 | - self::invokePrivate($this->auth, 'checkToken'); |
|
179 | - } |
|
177 | + $this->expectException(\Sabre\DAV\Exception\NotAuthenticated::class); |
|
178 | + self::invokePrivate($this->auth, 'checkToken'); |
|
179 | + } |
|
180 | 180 | |
181 | - public function testNoShare(): void { |
|
182 | - $this->request->method('getPathInfo') |
|
183 | - ->willReturn('/dav/files/GX9HSGQrGE'); |
|
181 | + public function testNoShare(): void { |
|
182 | + $this->request->method('getPathInfo') |
|
183 | + ->willReturn('/dav/files/GX9HSGQrGE'); |
|
184 | 184 | |
185 | - $this->shareManager->expects($this->once()) |
|
186 | - ->method('getShareByToken') |
|
187 | - ->with('GX9HSGQrGE') |
|
188 | - ->willThrowException(new ShareNotFound()); |
|
185 | + $this->shareManager->expects($this->once()) |
|
186 | + ->method('getShareByToken') |
|
187 | + ->with('GX9HSGQrGE') |
|
188 | + ->willThrowException(new ShareNotFound()); |
|
189 | 189 | |
190 | - $result = self::invokePrivate($this->auth, 'validateUserPass', ['username', 'password']); |
|
190 | + $result = self::invokePrivate($this->auth, 'validateUserPass', ['username', 'password']); |
|
191 | 191 | |
192 | - $this->assertFalse($result); |
|
193 | - } |
|
192 | + $this->assertFalse($result); |
|
193 | + } |
|
194 | 194 | |
195 | - public function testShareNoPassword(): void { |
|
196 | - $this->request->method('getPathInfo') |
|
197 | - ->willReturn('/dav/files/GX9HSGQrGE'); |
|
195 | + public function testShareNoPassword(): void { |
|
196 | + $this->request->method('getPathInfo') |
|
197 | + ->willReturn('/dav/files/GX9HSGQrGE'); |
|
198 | 198 | |
199 | - $share = $this->createMock(IShare::class); |
|
200 | - $share->method('getPassword')->willReturn(null); |
|
199 | + $share = $this->createMock(IShare::class); |
|
200 | + $share->method('getPassword')->willReturn(null); |
|
201 | 201 | |
202 | - $this->shareManager->expects($this->once()) |
|
203 | - ->method('getShareByToken') |
|
204 | - ->with('GX9HSGQrGE') |
|
205 | - ->willReturn($share); |
|
202 | + $this->shareManager->expects($this->once()) |
|
203 | + ->method('getShareByToken') |
|
204 | + ->with('GX9HSGQrGE') |
|
205 | + ->willReturn($share); |
|
206 | 206 | |
207 | - $result = self::invokePrivate($this->auth, 'validateUserPass', ['username', 'password']); |
|
207 | + $result = self::invokePrivate($this->auth, 'validateUserPass', ['username', 'password']); |
|
208 | 208 | |
209 | - $this->assertTrue($result); |
|
210 | - } |
|
209 | + $this->assertTrue($result); |
|
210 | + } |
|
211 | 211 | |
212 | - public function testSharePasswordFancyShareType(): void { |
|
213 | - $this->request->method('getPathInfo') |
|
214 | - ->willReturn('/dav/files/GX9HSGQrGE'); |
|
212 | + public function testSharePasswordFancyShareType(): void { |
|
213 | + $this->request->method('getPathInfo') |
|
214 | + ->willReturn('/dav/files/GX9HSGQrGE'); |
|
215 | 215 | |
216 | - $share = $this->createMock(IShare::class); |
|
217 | - $share->method('getPassword')->willReturn('password'); |
|
218 | - $share->method('getShareType')->willReturn(42); |
|
216 | + $share = $this->createMock(IShare::class); |
|
217 | + $share->method('getPassword')->willReturn('password'); |
|
218 | + $share->method('getShareType')->willReturn(42); |
|
219 | 219 | |
220 | - $this->shareManager->expects($this->once()) |
|
221 | - ->method('getShareByToken') |
|
222 | - ->with('GX9HSGQrGE') |
|
223 | - ->willReturn($share); |
|
220 | + $this->shareManager->expects($this->once()) |
|
221 | + ->method('getShareByToken') |
|
222 | + ->with('GX9HSGQrGE') |
|
223 | + ->willReturn($share); |
|
224 | 224 | |
225 | - $result = self::invokePrivate($this->auth, 'validateUserPass', ['username', 'password']); |
|
225 | + $result = self::invokePrivate($this->auth, 'validateUserPass', ['username', 'password']); |
|
226 | 226 | |
227 | - $this->assertFalse($result); |
|
228 | - } |
|
227 | + $this->assertFalse($result); |
|
228 | + } |
|
229 | 229 | |
230 | 230 | |
231 | - public function testSharePasswordRemote(): void { |
|
232 | - $this->request->method('getPathInfo') |
|
233 | - ->willReturn('/dav/files/GX9HSGQrGE'); |
|
231 | + public function testSharePasswordRemote(): void { |
|
232 | + $this->request->method('getPathInfo') |
|
233 | + ->willReturn('/dav/files/GX9HSGQrGE'); |
|
234 | 234 | |
235 | - $share = $this->createMock(IShare::class); |
|
236 | - $share->method('getPassword')->willReturn('password'); |
|
237 | - $share->method('getShareType')->willReturn(IShare::TYPE_REMOTE); |
|
235 | + $share = $this->createMock(IShare::class); |
|
236 | + $share->method('getPassword')->willReturn('password'); |
|
237 | + $share->method('getShareType')->willReturn(IShare::TYPE_REMOTE); |
|
238 | 238 | |
239 | - $this->shareManager->expects($this->once()) |
|
240 | - ->method('getShareByToken') |
|
241 | - ->with('GX9HSGQrGE') |
|
242 | - ->willReturn($share); |
|
239 | + $this->shareManager->expects($this->once()) |
|
240 | + ->method('getShareByToken') |
|
241 | + ->with('GX9HSGQrGE') |
|
242 | + ->willReturn($share); |
|
243 | 243 | |
244 | - $result = self::invokePrivate($this->auth, 'validateUserPass', ['username', 'password']); |
|
244 | + $result = self::invokePrivate($this->auth, 'validateUserPass', ['username', 'password']); |
|
245 | 245 | |
246 | - $this->assertTrue($result); |
|
247 | - } |
|
246 | + $this->assertTrue($result); |
|
247 | + } |
|
248 | 248 | |
249 | - public function testSharePasswordLinkValidPassword(): void { |
|
250 | - $this->request->method('getPathInfo') |
|
251 | - ->willReturn('/dav/files/GX9HSGQrGE'); |
|
249 | + public function testSharePasswordLinkValidPassword(): void { |
|
250 | + $this->request->method('getPathInfo') |
|
251 | + ->willReturn('/dav/files/GX9HSGQrGE'); |
|
252 | 252 | |
253 | - $share = $this->createMock(IShare::class); |
|
254 | - $share->method('getPassword')->willReturn('password'); |
|
255 | - $share->method('getShareType')->willReturn(IShare::TYPE_LINK); |
|
253 | + $share = $this->createMock(IShare::class); |
|
254 | + $share->method('getPassword')->willReturn('password'); |
|
255 | + $share->method('getShareType')->willReturn(IShare::TYPE_LINK); |
|
256 | 256 | |
257 | - $this->shareManager->expects($this->once()) |
|
258 | - ->method('getShareByToken') |
|
259 | - ->with('GX9HSGQrGE') |
|
260 | - ->willReturn($share); |
|
257 | + $this->shareManager->expects($this->once()) |
|
258 | + ->method('getShareByToken') |
|
259 | + ->with('GX9HSGQrGE') |
|
260 | + ->willReturn($share); |
|
261 | 261 | |
262 | - $this->shareManager->expects($this->once()) |
|
263 | - ->method('checkPassword')->with( |
|
264 | - $this->equalTo($share), |
|
265 | - $this->equalTo('password') |
|
266 | - )->willReturn(true); |
|
262 | + $this->shareManager->expects($this->once()) |
|
263 | + ->method('checkPassword')->with( |
|
264 | + $this->equalTo($share), |
|
265 | + $this->equalTo('password') |
|
266 | + )->willReturn(true); |
|
267 | 267 | |
268 | - $result = self::invokePrivate($this->auth, 'validateUserPass', ['username', 'password']); |
|
268 | + $result = self::invokePrivate($this->auth, 'validateUserPass', ['username', 'password']); |
|
269 | 269 | |
270 | - $this->assertTrue($result); |
|
271 | - } |
|
270 | + $this->assertTrue($result); |
|
271 | + } |
|
272 | 272 | |
273 | - public function testSharePasswordMailValidPassword(): void { |
|
274 | - $this->request->method('getPathInfo') |
|
275 | - ->willReturn('/dav/files/GX9HSGQrGE'); |
|
273 | + public function testSharePasswordMailValidPassword(): void { |
|
274 | + $this->request->method('getPathInfo') |
|
275 | + ->willReturn('/dav/files/GX9HSGQrGE'); |
|
276 | 276 | |
277 | - $share = $this->createMock(IShare::class); |
|
278 | - $share->method('getPassword')->willReturn('password'); |
|
279 | - $share->method('getShareType')->willReturn(IShare::TYPE_EMAIL); |
|
277 | + $share = $this->createMock(IShare::class); |
|
278 | + $share->method('getPassword')->willReturn('password'); |
|
279 | + $share->method('getShareType')->willReturn(IShare::TYPE_EMAIL); |
|
280 | 280 | |
281 | - $this->shareManager->expects($this->once()) |
|
282 | - ->method('getShareByToken') |
|
283 | - ->with('GX9HSGQrGE') |
|
284 | - ->willReturn($share); |
|
281 | + $this->shareManager->expects($this->once()) |
|
282 | + ->method('getShareByToken') |
|
283 | + ->with('GX9HSGQrGE') |
|
284 | + ->willReturn($share); |
|
285 | 285 | |
286 | - $this->shareManager->expects($this->once()) |
|
287 | - ->method('checkPassword')->with( |
|
288 | - $this->equalTo($share), |
|
289 | - $this->equalTo('password') |
|
290 | - )->willReturn(true); |
|
286 | + $this->shareManager->expects($this->once()) |
|
287 | + ->method('checkPassword')->with( |
|
288 | + $this->equalTo($share), |
|
289 | + $this->equalTo('password') |
|
290 | + )->willReturn(true); |
|
291 | 291 | |
292 | - $result = self::invokePrivate($this->auth, 'validateUserPass', ['username', 'password']); |
|
292 | + $result = self::invokePrivate($this->auth, 'validateUserPass', ['username', 'password']); |
|
293 | 293 | |
294 | - $this->assertTrue($result); |
|
295 | - } |
|
294 | + $this->assertTrue($result); |
|
295 | + } |
|
296 | 296 | |
297 | - public function testInvalidSharePasswordLinkValidSession(): void { |
|
298 | - $this->request->method('getPathInfo') |
|
299 | - ->willReturn('/dav/files/GX9HSGQrGE'); |
|
297 | + public function testInvalidSharePasswordLinkValidSession(): void { |
|
298 | + $this->request->method('getPathInfo') |
|
299 | + ->willReturn('/dav/files/GX9HSGQrGE'); |
|
300 | 300 | |
301 | - $share = $this->createMock(IShare::class); |
|
302 | - $share->method('getPassword')->willReturn('password'); |
|
303 | - $share->method('getShareType')->willReturn(IShare::TYPE_LINK); |
|
304 | - $share->method('getId')->willReturn('42'); |
|
301 | + $share = $this->createMock(IShare::class); |
|
302 | + $share->method('getPassword')->willReturn('password'); |
|
303 | + $share->method('getShareType')->willReturn(IShare::TYPE_LINK); |
|
304 | + $share->method('getId')->willReturn('42'); |
|
305 | 305 | |
306 | - $this->shareManager->expects($this->once()) |
|
307 | - ->method('getShareByToken') |
|
308 | - ->with('GX9HSGQrGE') |
|
309 | - ->willReturn($share); |
|
306 | + $this->shareManager->expects($this->once()) |
|
307 | + ->method('getShareByToken') |
|
308 | + ->with('GX9HSGQrGE') |
|
309 | + ->willReturn($share); |
|
310 | 310 | |
311 | - $this->shareManager->expects($this->once()) |
|
312 | - ->method('checkPassword') |
|
313 | - ->with( |
|
314 | - $this->equalTo($share), |
|
315 | - $this->equalTo('password') |
|
316 | - )->willReturn(false); |
|
311 | + $this->shareManager->expects($this->once()) |
|
312 | + ->method('checkPassword') |
|
313 | + ->with( |
|
314 | + $this->equalTo($share), |
|
315 | + $this->equalTo('password') |
|
316 | + )->willReturn(false); |
|
317 | 317 | |
318 | - $this->session->method('exists')->with('public_link_authenticated')->willReturn(true); |
|
319 | - $this->session->method('get')->with('public_link_authenticated')->willReturn('42'); |
|
318 | + $this->session->method('exists')->with('public_link_authenticated')->willReturn(true); |
|
319 | + $this->session->method('get')->with('public_link_authenticated')->willReturn('42'); |
|
320 | 320 | |
321 | - $result = self::invokePrivate($this->auth, 'validateUserPass', ['username', 'password']); |
|
321 | + $result = self::invokePrivate($this->auth, 'validateUserPass', ['username', 'password']); |
|
322 | 322 | |
323 | - $this->assertTrue($result); |
|
324 | - } |
|
323 | + $this->assertTrue($result); |
|
324 | + } |
|
325 | 325 | |
326 | - public function testSharePasswordLinkInvalidSession(): void { |
|
327 | - $this->request->method('getPathInfo') |
|
328 | - ->willReturn('/dav/files/GX9HSGQrGE'); |
|
326 | + public function testSharePasswordLinkInvalidSession(): void { |
|
327 | + $this->request->method('getPathInfo') |
|
328 | + ->willReturn('/dav/files/GX9HSGQrGE'); |
|
329 | 329 | |
330 | - $share = $this->createMock(IShare::class); |
|
331 | - $share->method('getPassword')->willReturn('password'); |
|
332 | - $share->method('getShareType')->willReturn(IShare::TYPE_LINK); |
|
333 | - $share->method('getId')->willReturn('42'); |
|
330 | + $share = $this->createMock(IShare::class); |
|
331 | + $share->method('getPassword')->willReturn('password'); |
|
332 | + $share->method('getShareType')->willReturn(IShare::TYPE_LINK); |
|
333 | + $share->method('getId')->willReturn('42'); |
|
334 | 334 | |
335 | - $this->shareManager->expects($this->once()) |
|
336 | - ->method('getShareByToken') |
|
337 | - ->with('GX9HSGQrGE') |
|
338 | - ->willReturn($share); |
|
335 | + $this->shareManager->expects($this->once()) |
|
336 | + ->method('getShareByToken') |
|
337 | + ->with('GX9HSGQrGE') |
|
338 | + ->willReturn($share); |
|
339 | 339 | |
340 | - $this->shareManager->expects($this->once()) |
|
341 | - ->method('checkPassword') |
|
342 | - ->with( |
|
343 | - $this->equalTo($share), |
|
344 | - $this->equalTo('password') |
|
345 | - )->willReturn(false); |
|
340 | + $this->shareManager->expects($this->once()) |
|
341 | + ->method('checkPassword') |
|
342 | + ->with( |
|
343 | + $this->equalTo($share), |
|
344 | + $this->equalTo('password') |
|
345 | + )->willReturn(false); |
|
346 | 346 | |
347 | - $this->session->method('exists')->with('public_link_authenticated')->willReturn(true); |
|
348 | - $this->session->method('get')->with('public_link_authenticated')->willReturn('43'); |
|
347 | + $this->session->method('exists')->with('public_link_authenticated')->willReturn(true); |
|
348 | + $this->session->method('get')->with('public_link_authenticated')->willReturn('43'); |
|
349 | 349 | |
350 | - $result = self::invokePrivate($this->auth, 'validateUserPass', ['username', 'password']); |
|
350 | + $result = self::invokePrivate($this->auth, 'validateUserPass', ['username', 'password']); |
|
351 | 351 | |
352 | - $this->assertFalse($result); |
|
353 | - } |
|
352 | + $this->assertFalse($result); |
|
353 | + } |
|
354 | 354 | |
355 | 355 | |
356 | - public function testSharePasswordMailInvalidSession(): void { |
|
357 | - $this->request->method('getPathInfo') |
|
358 | - ->willReturn('/dav/files/GX9HSGQrGE'); |
|
356 | + public function testSharePasswordMailInvalidSession(): void { |
|
357 | + $this->request->method('getPathInfo') |
|
358 | + ->willReturn('/dav/files/GX9HSGQrGE'); |
|
359 | 359 | |
360 | - $share = $this->createMock(IShare::class); |
|
361 | - $share->method('getPassword')->willReturn('password'); |
|
362 | - $share->method('getShareType')->willReturn(IShare::TYPE_EMAIL); |
|
363 | - $share->method('getId')->willReturn('42'); |
|
360 | + $share = $this->createMock(IShare::class); |
|
361 | + $share->method('getPassword')->willReturn('password'); |
|
362 | + $share->method('getShareType')->willReturn(IShare::TYPE_EMAIL); |
|
363 | + $share->method('getId')->willReturn('42'); |
|
364 | 364 | |
365 | - $this->shareManager->expects($this->once()) |
|
366 | - ->method('getShareByToken') |
|
367 | - ->with('GX9HSGQrGE') |
|
368 | - ->willReturn($share); |
|
365 | + $this->shareManager->expects($this->once()) |
|
366 | + ->method('getShareByToken') |
|
367 | + ->with('GX9HSGQrGE') |
|
368 | + ->willReturn($share); |
|
369 | 369 | |
370 | - $this->shareManager->expects($this->once()) |
|
371 | - ->method('checkPassword') |
|
372 | - ->with( |
|
373 | - $this->equalTo($share), |
|
374 | - $this->equalTo('password') |
|
375 | - )->willReturn(false); |
|
370 | + $this->shareManager->expects($this->once()) |
|
371 | + ->method('checkPassword') |
|
372 | + ->with( |
|
373 | + $this->equalTo($share), |
|
374 | + $this->equalTo('password') |
|
375 | + )->willReturn(false); |
|
376 | 376 | |
377 | - $this->session->method('exists')->with('public_link_authenticated')->willReturn(true); |
|
378 | - $this->session->method('get')->with('public_link_authenticated')->willReturn('43'); |
|
377 | + $this->session->method('exists')->with('public_link_authenticated')->willReturn(true); |
|
378 | + $this->session->method('get')->with('public_link_authenticated')->willReturn('43'); |
|
379 | 379 | |
380 | - $result = self::invokePrivate($this->auth, 'validateUserPass', ['username', 'password']); |
|
380 | + $result = self::invokePrivate($this->auth, 'validateUserPass', ['username', 'password']); |
|
381 | 381 | |
382 | - $this->assertFalse($result); |
|
383 | - } |
|
382 | + $this->assertFalse($result); |
|
383 | + } |
|
384 | 384 | } |
@@ -36,7 +36,7 @@ |
||
36 | 36 | private IURLGenerator&MockObject $urlGenerator; |
37 | 37 | private PublicAuth $auth; |
38 | 38 | |
39 | - private bool|string $oldUser; |
|
39 | + private bool | string $oldUser; |
|
40 | 40 | |
41 | 41 | protected function setUp(): void { |
42 | 42 | parent::setUp(); |
@@ -33,247 +33,247 @@ |
||
33 | 33 | * @package OCA\DAV\Tests\unit\Connector\Sabre |
34 | 34 | */ |
35 | 35 | class NodeTest extends \Test\TestCase { |
36 | - public static function davPermissionsProvider(): array { |
|
37 | - return [ |
|
38 | - [Constants::PERMISSION_ALL, 'file', false, Constants::PERMISSION_ALL, false, 'test', 'RGDNVW'], |
|
39 | - [Constants::PERMISSION_ALL, 'dir', false, Constants::PERMISSION_ALL, false, 'test', 'RGDNVCK'], |
|
40 | - [Constants::PERMISSION_ALL, 'file', true, Constants::PERMISSION_ALL, false, 'test', 'SRGDNVW'], |
|
41 | - [Constants::PERMISSION_ALL, 'file', true, Constants::PERMISSION_ALL, true, 'test', 'SRMGDNVW'], |
|
42 | - [Constants::PERMISSION_ALL, 'file', true, Constants::PERMISSION_ALL, true, '' , 'SRMGDNVW'], |
|
43 | - [Constants::PERMISSION_ALL, 'file', true, Constants::PERMISSION_ALL - Constants::PERMISSION_UPDATE, true, '' , 'SRMGDNV'], |
|
44 | - [Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE, 'file', true, Constants::PERMISSION_ALL, false, 'test', 'SGDNVW'], |
|
45 | - [Constants::PERMISSION_ALL - Constants::PERMISSION_UPDATE, 'file', false, Constants::PERMISSION_ALL, false, 'test', 'RGD'], |
|
46 | - [Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE, 'file', false, Constants::PERMISSION_ALL, false, 'test', 'RGNVW'], |
|
47 | - [Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE, 'file', false, Constants::PERMISSION_ALL, false, 'test', 'RGDNVW'], |
|
48 | - [Constants::PERMISSION_ALL - Constants::PERMISSION_READ, 'file', false, Constants::PERMISSION_ALL, false, 'test', 'RDNVW'], |
|
49 | - [Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE, 'dir', false, Constants::PERMISSION_ALL, false, 'test', 'RGDNV'], |
|
50 | - [Constants::PERMISSION_ALL - Constants::PERMISSION_READ, 'dir', false, Constants::PERMISSION_ALL, false, 'test', 'RDNVCK'], |
|
51 | - ]; |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * @dataProvider davPermissionsProvider |
|
56 | - */ |
|
57 | - public function testDavPermissions(int $permissions, string $type, bool $shared, int $shareRootPermissions, bool $mounted, string $internalPath, string $expected): void { |
|
58 | - $info = $this->getMockBuilder(FileInfo::class) |
|
59 | - ->disableOriginalConstructor() |
|
60 | - ->onlyMethods(['getPermissions', 'isShared', 'isMounted', 'getType', 'getInternalPath', 'getStorage', 'getMountPoint']) |
|
61 | - ->getMock(); |
|
62 | - $info->method('getPermissions') |
|
63 | - ->willReturn($permissions); |
|
64 | - $info->method('isShared') |
|
65 | - ->willReturn($shared); |
|
66 | - $info->method('isMounted') |
|
67 | - ->willReturn($mounted); |
|
68 | - $info->method('getType') |
|
69 | - ->willReturn($type); |
|
70 | - $info->method('getInternalPath') |
|
71 | - ->willReturn($internalPath); |
|
72 | - $info->method('getMountPoint') |
|
73 | - ->willReturnCallback(function () use ($shared) { |
|
74 | - if ($shared) { |
|
75 | - return $this->createMock(SharedMount::class); |
|
76 | - } else { |
|
77 | - return $this->createMock(MountPoint::class); |
|
78 | - } |
|
79 | - }); |
|
80 | - $storage = $this->createMock(IStorage::class); |
|
81 | - if ($shared) { |
|
82 | - $storage->method('instanceOfStorage') |
|
83 | - ->willReturn(true); |
|
84 | - $cache = $this->createMock(ICache::class); |
|
85 | - $storage->method('getCache') |
|
86 | - ->willReturn($cache); |
|
87 | - $shareRootEntry = $this->createMock(ICacheEntry::class); |
|
88 | - $cache->method('get') |
|
89 | - ->willReturn($shareRootEntry); |
|
90 | - $shareRootEntry->method('getPermissions') |
|
91 | - ->willReturn($shareRootPermissions); |
|
92 | - } else { |
|
93 | - $storage->method('instanceOfStorage') |
|
94 | - ->willReturn(false); |
|
95 | - } |
|
96 | - $info->method('getStorage') |
|
97 | - ->willReturn($storage); |
|
98 | - $view = $this->createMock(View::class); |
|
99 | - |
|
100 | - $node = new File($view, $info); |
|
101 | - $this->assertEquals($expected, $node->getDavPermissions()); |
|
102 | - } |
|
103 | - |
|
104 | - public static function sharePermissionsProvider(): array { |
|
105 | - return [ |
|
106 | - [\OCP\Files\FileInfo::TYPE_FILE, null, 1, 1], |
|
107 | - [\OCP\Files\FileInfo::TYPE_FILE, null, 3, 3], |
|
108 | - [\OCP\Files\FileInfo::TYPE_FILE, null, 5, 1], |
|
109 | - [\OCP\Files\FileInfo::TYPE_FILE, null, 7, 3], |
|
110 | - [\OCP\Files\FileInfo::TYPE_FILE, null, 9, 1], |
|
111 | - [\OCP\Files\FileInfo::TYPE_FILE, null, 11, 3], |
|
112 | - [\OCP\Files\FileInfo::TYPE_FILE, null, 13, 1], |
|
113 | - [\OCP\Files\FileInfo::TYPE_FILE, null, 15, 3], |
|
114 | - [\OCP\Files\FileInfo::TYPE_FILE, null, 17, 17], |
|
115 | - [\OCP\Files\FileInfo::TYPE_FILE, null, 19, 19], |
|
116 | - [\OCP\Files\FileInfo::TYPE_FILE, null, 21, 17], |
|
117 | - [\OCP\Files\FileInfo::TYPE_FILE, null, 23, 19], |
|
118 | - [\OCP\Files\FileInfo::TYPE_FILE, null, 25, 17], |
|
119 | - [\OCP\Files\FileInfo::TYPE_FILE, null, 27, 19], |
|
120 | - [\OCP\Files\FileInfo::TYPE_FILE, null, 29, 17], |
|
121 | - [\OCP\Files\FileInfo::TYPE_FILE, null, 30, 18], |
|
122 | - [\OCP\Files\FileInfo::TYPE_FILE, null, 31, 19], |
|
123 | - [\OCP\Files\FileInfo::TYPE_FOLDER, null, 1, 1], |
|
124 | - [\OCP\Files\FileInfo::TYPE_FOLDER, null, 3, 3], |
|
125 | - [\OCP\Files\FileInfo::TYPE_FOLDER, null, 5, 5], |
|
126 | - [\OCP\Files\FileInfo::TYPE_FOLDER, null, 7, 7], |
|
127 | - [\OCP\Files\FileInfo::TYPE_FOLDER, null, 9, 9], |
|
128 | - [\OCP\Files\FileInfo::TYPE_FOLDER, null, 11, 11], |
|
129 | - [\OCP\Files\FileInfo::TYPE_FOLDER, null, 13, 13], |
|
130 | - [\OCP\Files\FileInfo::TYPE_FOLDER, null, 15, 15], |
|
131 | - [\OCP\Files\FileInfo::TYPE_FOLDER, null, 17, 17], |
|
132 | - [\OCP\Files\FileInfo::TYPE_FOLDER, null, 19, 19], |
|
133 | - [\OCP\Files\FileInfo::TYPE_FOLDER, null, 21, 21], |
|
134 | - [\OCP\Files\FileInfo::TYPE_FOLDER, null, 23, 23], |
|
135 | - [\OCP\Files\FileInfo::TYPE_FOLDER, null, 25, 25], |
|
136 | - [\OCP\Files\FileInfo::TYPE_FOLDER, null, 27, 27], |
|
137 | - [\OCP\Files\FileInfo::TYPE_FOLDER, null, 29, 29], |
|
138 | - [\OCP\Files\FileInfo::TYPE_FOLDER, null, 30, 30], |
|
139 | - [\OCP\Files\FileInfo::TYPE_FOLDER, null, 31, 31], |
|
140 | - [\OCP\Files\FileInfo::TYPE_FOLDER, 'shareToken', 7, 7], |
|
141 | - ]; |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * @dataProvider sharePermissionsProvider |
|
146 | - */ |
|
147 | - public function testSharePermissions(string $type, ?string $user, int $permissions, int $expected): void { |
|
148 | - $storage = $this->createMock(IStorage::class); |
|
149 | - $storage->method('getPermissions')->willReturn($permissions); |
|
150 | - |
|
151 | - $mountpoint = $this->createMock(IMountPoint::class); |
|
152 | - $mountpoint->method('getMountPoint')->willReturn('myPath'); |
|
153 | - $shareManager = $this->createMock(IManager::class); |
|
154 | - $share = $this->createMock(IShare::class); |
|
155 | - |
|
156 | - if ($user === null) { |
|
157 | - $shareManager->expects($this->never())->method('getShareByToken'); |
|
158 | - $share->expects($this->never())->method('getPermissions'); |
|
159 | - } else { |
|
160 | - $shareManager->expects($this->once())->method('getShareByToken')->with($user) |
|
161 | - ->willReturn($share); |
|
162 | - $share->expects($this->once())->method('getPermissions')->willReturn($permissions); |
|
163 | - } |
|
164 | - |
|
165 | - $info = $this->getMockBuilder(FileInfo::class) |
|
166 | - ->disableOriginalConstructor() |
|
167 | - ->onlyMethods(['getStorage', 'getType', 'getMountPoint', 'getPermissions']) |
|
168 | - ->getMock(); |
|
169 | - |
|
170 | - $info->method('getStorage')->willReturn($storage); |
|
171 | - $info->method('getType')->willReturn($type); |
|
172 | - $info->method('getMountPoint')->willReturn($mountpoint); |
|
173 | - $info->method('getPermissions')->willReturn($permissions); |
|
174 | - |
|
175 | - $view = $this->createMock(View::class); |
|
176 | - |
|
177 | - $node = new File($view, $info); |
|
178 | - $this->invokePrivate($node, 'shareManager', [$shareManager]); |
|
179 | - $this->assertEquals($expected, $node->getSharePermissions($user)); |
|
180 | - } |
|
181 | - |
|
182 | - public function testShareAttributes(): void { |
|
183 | - $storage = $this->getMockBuilder(SharedStorage::class) |
|
184 | - ->disableOriginalConstructor() |
|
185 | - ->onlyMethods(['getShare']) |
|
186 | - ->getMock(); |
|
187 | - |
|
188 | - $shareManager = $this->createMock(IManager::class); |
|
189 | - $share = $this->createMock(IShare::class); |
|
190 | - |
|
191 | - $storage->expects($this->once()) |
|
192 | - ->method('getShare') |
|
193 | - ->willReturn($share); |
|
194 | - |
|
195 | - $attributes = new ShareAttributes(); |
|
196 | - $attributes->setAttribute('permissions', 'download', false); |
|
197 | - |
|
198 | - $share->expects($this->once())->method('getAttributes')->willReturn($attributes); |
|
199 | - |
|
200 | - /** @var Folder&MockObject $info */ |
|
201 | - $info = $this->getMockBuilder(Folder::class) |
|
202 | - ->disableOriginalConstructor() |
|
203 | - ->onlyMethods(['getStorage', 'getType']) |
|
204 | - ->getMock(); |
|
205 | - |
|
206 | - $info->method('getStorage')->willReturn($storage); |
|
207 | - $info->method('getType')->willReturn(FileInfo::TYPE_FOLDER); |
|
208 | - |
|
209 | - /** @var View&MockObject $view */ |
|
210 | - $view = $this->createMock(View::class); |
|
211 | - |
|
212 | - $node = new File($view, $info); |
|
213 | - $this->invokePrivate($node, 'shareManager', [$shareManager]); |
|
214 | - $this->assertEquals($attributes->toArray(), $node->getShareAttributes()); |
|
215 | - } |
|
216 | - |
|
217 | - public function testShareAttributesNonShare(): void { |
|
218 | - $storage = $this->createMock(IStorage::class); |
|
219 | - $shareManager = $this->createMock(IManager::class); |
|
220 | - |
|
221 | - /** @var Folder&MockObject */ |
|
222 | - $info = $this->getMockBuilder(Folder::class) |
|
223 | - ->disableOriginalConstructor() |
|
224 | - ->onlyMethods(['getStorage', 'getType']) |
|
225 | - ->getMock(); |
|
226 | - |
|
227 | - $info->method('getStorage')->willReturn($storage); |
|
228 | - $info->method('getType')->willReturn(FileInfo::TYPE_FOLDER); |
|
229 | - |
|
230 | - /** @var View&MockObject */ |
|
231 | - $view = $this->createMock(View::class); |
|
232 | - |
|
233 | - $node = new File($view, $info); |
|
234 | - $this->invokePrivate($node, 'shareManager', [$shareManager]); |
|
235 | - $this->assertEquals([], $node->getShareAttributes()); |
|
236 | - } |
|
237 | - |
|
238 | - public static function sanitizeMtimeProvider(): array { |
|
239 | - return [ |
|
240 | - [123456789, 123456789], |
|
241 | - ['987654321', 987654321], |
|
242 | - ]; |
|
243 | - } |
|
244 | - |
|
245 | - /** |
|
246 | - * @dataProvider sanitizeMtimeProvider |
|
247 | - */ |
|
248 | - public function testSanitizeMtime(string|int $mtime, int $expected): void { |
|
249 | - $view = $this->getMockBuilder(View::class) |
|
250 | - ->disableOriginalConstructor() |
|
251 | - ->getMock(); |
|
252 | - $info = $this->getMockBuilder(FileInfo::class) |
|
253 | - ->disableOriginalConstructor() |
|
254 | - ->getMock(); |
|
255 | - |
|
256 | - $node = new File($view, $info); |
|
257 | - $result = $this->invokePrivate($node, 'sanitizeMtime', [$mtime]); |
|
258 | - $this->assertEquals($expected, $result); |
|
259 | - } |
|
260 | - |
|
261 | - public static function invalidSanitizeMtimeProvider(): array { |
|
262 | - return [ |
|
263 | - [-1337], [0], ['abcdef'], ['-1337'], ['0'], [12321], [24 * 60 * 60 - 1], |
|
264 | - ]; |
|
265 | - } |
|
266 | - |
|
267 | - /** |
|
268 | - * @dataProvider invalidSanitizeMtimeProvider |
|
269 | - */ |
|
270 | - public function testInvalidSanitizeMtime(int|string $mtime): void { |
|
271 | - $this->expectException(\InvalidArgumentException::class); |
|
272 | - |
|
273 | - $view = $this->createMock(View::class); |
|
274 | - $info = $this->createMock(FileInfo::class); |
|
275 | - |
|
276 | - $node = new File($view, $info); |
|
277 | - self::invokePrivate($node, 'sanitizeMtime', [$mtime]); |
|
278 | - } |
|
36 | + public static function davPermissionsProvider(): array { |
|
37 | + return [ |
|
38 | + [Constants::PERMISSION_ALL, 'file', false, Constants::PERMISSION_ALL, false, 'test', 'RGDNVW'], |
|
39 | + [Constants::PERMISSION_ALL, 'dir', false, Constants::PERMISSION_ALL, false, 'test', 'RGDNVCK'], |
|
40 | + [Constants::PERMISSION_ALL, 'file', true, Constants::PERMISSION_ALL, false, 'test', 'SRGDNVW'], |
|
41 | + [Constants::PERMISSION_ALL, 'file', true, Constants::PERMISSION_ALL, true, 'test', 'SRMGDNVW'], |
|
42 | + [Constants::PERMISSION_ALL, 'file', true, Constants::PERMISSION_ALL, true, '' , 'SRMGDNVW'], |
|
43 | + [Constants::PERMISSION_ALL, 'file', true, Constants::PERMISSION_ALL - Constants::PERMISSION_UPDATE, true, '' , 'SRMGDNV'], |
|
44 | + [Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE, 'file', true, Constants::PERMISSION_ALL, false, 'test', 'SGDNVW'], |
|
45 | + [Constants::PERMISSION_ALL - Constants::PERMISSION_UPDATE, 'file', false, Constants::PERMISSION_ALL, false, 'test', 'RGD'], |
|
46 | + [Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE, 'file', false, Constants::PERMISSION_ALL, false, 'test', 'RGNVW'], |
|
47 | + [Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE, 'file', false, Constants::PERMISSION_ALL, false, 'test', 'RGDNVW'], |
|
48 | + [Constants::PERMISSION_ALL - Constants::PERMISSION_READ, 'file', false, Constants::PERMISSION_ALL, false, 'test', 'RDNVW'], |
|
49 | + [Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE, 'dir', false, Constants::PERMISSION_ALL, false, 'test', 'RGDNV'], |
|
50 | + [Constants::PERMISSION_ALL - Constants::PERMISSION_READ, 'dir', false, Constants::PERMISSION_ALL, false, 'test', 'RDNVCK'], |
|
51 | + ]; |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * @dataProvider davPermissionsProvider |
|
56 | + */ |
|
57 | + public function testDavPermissions(int $permissions, string $type, bool $shared, int $shareRootPermissions, bool $mounted, string $internalPath, string $expected): void { |
|
58 | + $info = $this->getMockBuilder(FileInfo::class) |
|
59 | + ->disableOriginalConstructor() |
|
60 | + ->onlyMethods(['getPermissions', 'isShared', 'isMounted', 'getType', 'getInternalPath', 'getStorage', 'getMountPoint']) |
|
61 | + ->getMock(); |
|
62 | + $info->method('getPermissions') |
|
63 | + ->willReturn($permissions); |
|
64 | + $info->method('isShared') |
|
65 | + ->willReturn($shared); |
|
66 | + $info->method('isMounted') |
|
67 | + ->willReturn($mounted); |
|
68 | + $info->method('getType') |
|
69 | + ->willReturn($type); |
|
70 | + $info->method('getInternalPath') |
|
71 | + ->willReturn($internalPath); |
|
72 | + $info->method('getMountPoint') |
|
73 | + ->willReturnCallback(function () use ($shared) { |
|
74 | + if ($shared) { |
|
75 | + return $this->createMock(SharedMount::class); |
|
76 | + } else { |
|
77 | + return $this->createMock(MountPoint::class); |
|
78 | + } |
|
79 | + }); |
|
80 | + $storage = $this->createMock(IStorage::class); |
|
81 | + if ($shared) { |
|
82 | + $storage->method('instanceOfStorage') |
|
83 | + ->willReturn(true); |
|
84 | + $cache = $this->createMock(ICache::class); |
|
85 | + $storage->method('getCache') |
|
86 | + ->willReturn($cache); |
|
87 | + $shareRootEntry = $this->createMock(ICacheEntry::class); |
|
88 | + $cache->method('get') |
|
89 | + ->willReturn($shareRootEntry); |
|
90 | + $shareRootEntry->method('getPermissions') |
|
91 | + ->willReturn($shareRootPermissions); |
|
92 | + } else { |
|
93 | + $storage->method('instanceOfStorage') |
|
94 | + ->willReturn(false); |
|
95 | + } |
|
96 | + $info->method('getStorage') |
|
97 | + ->willReturn($storage); |
|
98 | + $view = $this->createMock(View::class); |
|
99 | + |
|
100 | + $node = new File($view, $info); |
|
101 | + $this->assertEquals($expected, $node->getDavPermissions()); |
|
102 | + } |
|
103 | + |
|
104 | + public static function sharePermissionsProvider(): array { |
|
105 | + return [ |
|
106 | + [\OCP\Files\FileInfo::TYPE_FILE, null, 1, 1], |
|
107 | + [\OCP\Files\FileInfo::TYPE_FILE, null, 3, 3], |
|
108 | + [\OCP\Files\FileInfo::TYPE_FILE, null, 5, 1], |
|
109 | + [\OCP\Files\FileInfo::TYPE_FILE, null, 7, 3], |
|
110 | + [\OCP\Files\FileInfo::TYPE_FILE, null, 9, 1], |
|
111 | + [\OCP\Files\FileInfo::TYPE_FILE, null, 11, 3], |
|
112 | + [\OCP\Files\FileInfo::TYPE_FILE, null, 13, 1], |
|
113 | + [\OCP\Files\FileInfo::TYPE_FILE, null, 15, 3], |
|
114 | + [\OCP\Files\FileInfo::TYPE_FILE, null, 17, 17], |
|
115 | + [\OCP\Files\FileInfo::TYPE_FILE, null, 19, 19], |
|
116 | + [\OCP\Files\FileInfo::TYPE_FILE, null, 21, 17], |
|
117 | + [\OCP\Files\FileInfo::TYPE_FILE, null, 23, 19], |
|
118 | + [\OCP\Files\FileInfo::TYPE_FILE, null, 25, 17], |
|
119 | + [\OCP\Files\FileInfo::TYPE_FILE, null, 27, 19], |
|
120 | + [\OCP\Files\FileInfo::TYPE_FILE, null, 29, 17], |
|
121 | + [\OCP\Files\FileInfo::TYPE_FILE, null, 30, 18], |
|
122 | + [\OCP\Files\FileInfo::TYPE_FILE, null, 31, 19], |
|
123 | + [\OCP\Files\FileInfo::TYPE_FOLDER, null, 1, 1], |
|
124 | + [\OCP\Files\FileInfo::TYPE_FOLDER, null, 3, 3], |
|
125 | + [\OCP\Files\FileInfo::TYPE_FOLDER, null, 5, 5], |
|
126 | + [\OCP\Files\FileInfo::TYPE_FOLDER, null, 7, 7], |
|
127 | + [\OCP\Files\FileInfo::TYPE_FOLDER, null, 9, 9], |
|
128 | + [\OCP\Files\FileInfo::TYPE_FOLDER, null, 11, 11], |
|
129 | + [\OCP\Files\FileInfo::TYPE_FOLDER, null, 13, 13], |
|
130 | + [\OCP\Files\FileInfo::TYPE_FOLDER, null, 15, 15], |
|
131 | + [\OCP\Files\FileInfo::TYPE_FOLDER, null, 17, 17], |
|
132 | + [\OCP\Files\FileInfo::TYPE_FOLDER, null, 19, 19], |
|
133 | + [\OCP\Files\FileInfo::TYPE_FOLDER, null, 21, 21], |
|
134 | + [\OCP\Files\FileInfo::TYPE_FOLDER, null, 23, 23], |
|
135 | + [\OCP\Files\FileInfo::TYPE_FOLDER, null, 25, 25], |
|
136 | + [\OCP\Files\FileInfo::TYPE_FOLDER, null, 27, 27], |
|
137 | + [\OCP\Files\FileInfo::TYPE_FOLDER, null, 29, 29], |
|
138 | + [\OCP\Files\FileInfo::TYPE_FOLDER, null, 30, 30], |
|
139 | + [\OCP\Files\FileInfo::TYPE_FOLDER, null, 31, 31], |
|
140 | + [\OCP\Files\FileInfo::TYPE_FOLDER, 'shareToken', 7, 7], |
|
141 | + ]; |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * @dataProvider sharePermissionsProvider |
|
146 | + */ |
|
147 | + public function testSharePermissions(string $type, ?string $user, int $permissions, int $expected): void { |
|
148 | + $storage = $this->createMock(IStorage::class); |
|
149 | + $storage->method('getPermissions')->willReturn($permissions); |
|
150 | + |
|
151 | + $mountpoint = $this->createMock(IMountPoint::class); |
|
152 | + $mountpoint->method('getMountPoint')->willReturn('myPath'); |
|
153 | + $shareManager = $this->createMock(IManager::class); |
|
154 | + $share = $this->createMock(IShare::class); |
|
155 | + |
|
156 | + if ($user === null) { |
|
157 | + $shareManager->expects($this->never())->method('getShareByToken'); |
|
158 | + $share->expects($this->never())->method('getPermissions'); |
|
159 | + } else { |
|
160 | + $shareManager->expects($this->once())->method('getShareByToken')->with($user) |
|
161 | + ->willReturn($share); |
|
162 | + $share->expects($this->once())->method('getPermissions')->willReturn($permissions); |
|
163 | + } |
|
164 | + |
|
165 | + $info = $this->getMockBuilder(FileInfo::class) |
|
166 | + ->disableOriginalConstructor() |
|
167 | + ->onlyMethods(['getStorage', 'getType', 'getMountPoint', 'getPermissions']) |
|
168 | + ->getMock(); |
|
169 | + |
|
170 | + $info->method('getStorage')->willReturn($storage); |
|
171 | + $info->method('getType')->willReturn($type); |
|
172 | + $info->method('getMountPoint')->willReturn($mountpoint); |
|
173 | + $info->method('getPermissions')->willReturn($permissions); |
|
174 | + |
|
175 | + $view = $this->createMock(View::class); |
|
176 | + |
|
177 | + $node = new File($view, $info); |
|
178 | + $this->invokePrivate($node, 'shareManager', [$shareManager]); |
|
179 | + $this->assertEquals($expected, $node->getSharePermissions($user)); |
|
180 | + } |
|
181 | + |
|
182 | + public function testShareAttributes(): void { |
|
183 | + $storage = $this->getMockBuilder(SharedStorage::class) |
|
184 | + ->disableOriginalConstructor() |
|
185 | + ->onlyMethods(['getShare']) |
|
186 | + ->getMock(); |
|
187 | + |
|
188 | + $shareManager = $this->createMock(IManager::class); |
|
189 | + $share = $this->createMock(IShare::class); |
|
190 | + |
|
191 | + $storage->expects($this->once()) |
|
192 | + ->method('getShare') |
|
193 | + ->willReturn($share); |
|
194 | + |
|
195 | + $attributes = new ShareAttributes(); |
|
196 | + $attributes->setAttribute('permissions', 'download', false); |
|
197 | + |
|
198 | + $share->expects($this->once())->method('getAttributes')->willReturn($attributes); |
|
199 | + |
|
200 | + /** @var Folder&MockObject $info */ |
|
201 | + $info = $this->getMockBuilder(Folder::class) |
|
202 | + ->disableOriginalConstructor() |
|
203 | + ->onlyMethods(['getStorage', 'getType']) |
|
204 | + ->getMock(); |
|
205 | + |
|
206 | + $info->method('getStorage')->willReturn($storage); |
|
207 | + $info->method('getType')->willReturn(FileInfo::TYPE_FOLDER); |
|
208 | + |
|
209 | + /** @var View&MockObject $view */ |
|
210 | + $view = $this->createMock(View::class); |
|
211 | + |
|
212 | + $node = new File($view, $info); |
|
213 | + $this->invokePrivate($node, 'shareManager', [$shareManager]); |
|
214 | + $this->assertEquals($attributes->toArray(), $node->getShareAttributes()); |
|
215 | + } |
|
216 | + |
|
217 | + public function testShareAttributesNonShare(): void { |
|
218 | + $storage = $this->createMock(IStorage::class); |
|
219 | + $shareManager = $this->createMock(IManager::class); |
|
220 | + |
|
221 | + /** @var Folder&MockObject */ |
|
222 | + $info = $this->getMockBuilder(Folder::class) |
|
223 | + ->disableOriginalConstructor() |
|
224 | + ->onlyMethods(['getStorage', 'getType']) |
|
225 | + ->getMock(); |
|
226 | + |
|
227 | + $info->method('getStorage')->willReturn($storage); |
|
228 | + $info->method('getType')->willReturn(FileInfo::TYPE_FOLDER); |
|
229 | + |
|
230 | + /** @var View&MockObject */ |
|
231 | + $view = $this->createMock(View::class); |
|
232 | + |
|
233 | + $node = new File($view, $info); |
|
234 | + $this->invokePrivate($node, 'shareManager', [$shareManager]); |
|
235 | + $this->assertEquals([], $node->getShareAttributes()); |
|
236 | + } |
|
237 | + |
|
238 | + public static function sanitizeMtimeProvider(): array { |
|
239 | + return [ |
|
240 | + [123456789, 123456789], |
|
241 | + ['987654321', 987654321], |
|
242 | + ]; |
|
243 | + } |
|
244 | + |
|
245 | + /** |
|
246 | + * @dataProvider sanitizeMtimeProvider |
|
247 | + */ |
|
248 | + public function testSanitizeMtime(string|int $mtime, int $expected): void { |
|
249 | + $view = $this->getMockBuilder(View::class) |
|
250 | + ->disableOriginalConstructor() |
|
251 | + ->getMock(); |
|
252 | + $info = $this->getMockBuilder(FileInfo::class) |
|
253 | + ->disableOriginalConstructor() |
|
254 | + ->getMock(); |
|
255 | + |
|
256 | + $node = new File($view, $info); |
|
257 | + $result = $this->invokePrivate($node, 'sanitizeMtime', [$mtime]); |
|
258 | + $this->assertEquals($expected, $result); |
|
259 | + } |
|
260 | + |
|
261 | + public static function invalidSanitizeMtimeProvider(): array { |
|
262 | + return [ |
|
263 | + [-1337], [0], ['abcdef'], ['-1337'], ['0'], [12321], [24 * 60 * 60 - 1], |
|
264 | + ]; |
|
265 | + } |
|
266 | + |
|
267 | + /** |
|
268 | + * @dataProvider invalidSanitizeMtimeProvider |
|
269 | + */ |
|
270 | + public function testInvalidSanitizeMtime(int|string $mtime): void { |
|
271 | + $this->expectException(\InvalidArgumentException::class); |
|
272 | + |
|
273 | + $view = $this->createMock(View::class); |
|
274 | + $info = $this->createMock(FileInfo::class); |
|
275 | + |
|
276 | + $node = new File($view, $info); |
|
277 | + self::invokePrivate($node, 'sanitizeMtime', [$mtime]); |
|
278 | + } |
|
279 | 279 | } |
@@ -39,8 +39,8 @@ discard block |
||
39 | 39 | [Constants::PERMISSION_ALL, 'dir', false, Constants::PERMISSION_ALL, false, 'test', 'RGDNVCK'], |
40 | 40 | [Constants::PERMISSION_ALL, 'file', true, Constants::PERMISSION_ALL, false, 'test', 'SRGDNVW'], |
41 | 41 | [Constants::PERMISSION_ALL, 'file', true, Constants::PERMISSION_ALL, true, 'test', 'SRMGDNVW'], |
42 | - [Constants::PERMISSION_ALL, 'file', true, Constants::PERMISSION_ALL, true, '' , 'SRMGDNVW'], |
|
43 | - [Constants::PERMISSION_ALL, 'file', true, Constants::PERMISSION_ALL - Constants::PERMISSION_UPDATE, true, '' , 'SRMGDNV'], |
|
42 | + [Constants::PERMISSION_ALL, 'file', true, Constants::PERMISSION_ALL, true, '', 'SRMGDNVW'], |
|
43 | + [Constants::PERMISSION_ALL, 'file', true, Constants::PERMISSION_ALL - Constants::PERMISSION_UPDATE, true, '', 'SRMGDNV'], |
|
44 | 44 | [Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE, 'file', true, Constants::PERMISSION_ALL, false, 'test', 'SGDNVW'], |
45 | 45 | [Constants::PERMISSION_ALL - Constants::PERMISSION_UPDATE, 'file', false, Constants::PERMISSION_ALL, false, 'test', 'RGD'], |
46 | 46 | [Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE, 'file', false, Constants::PERMISSION_ALL, false, 'test', 'RGNVW'], |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | $info->method('getInternalPath') |
71 | 71 | ->willReturn($internalPath); |
72 | 72 | $info->method('getMountPoint') |
73 | - ->willReturnCallback(function () use ($shared) { |
|
73 | + ->willReturnCallback(function() use ($shared) { |
|
74 | 74 | if ($shared) { |
75 | 75 | return $this->createMock(SharedMount::class); |
76 | 76 | } else { |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | /** |
246 | 246 | * @dataProvider sanitizeMtimeProvider |
247 | 247 | */ |
248 | - public function testSanitizeMtime(string|int $mtime, int $expected): void { |
|
248 | + public function testSanitizeMtime(string | int $mtime, int $expected): void { |
|
249 | 249 | $view = $this->getMockBuilder(View::class) |
250 | 250 | ->disableOriginalConstructor() |
251 | 251 | ->getMock(); |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | /** |
268 | 268 | * @dataProvider invalidSanitizeMtimeProvider |
269 | 269 | */ |
270 | - public function testInvalidSanitizeMtime(int|string $mtime): void { |
|
270 | + public function testInvalidSanitizeMtime(int | string $mtime): void { |
|
271 | 271 | $this->expectException(\InvalidArgumentException::class); |
272 | 272 | |
273 | 273 | $view = $this->createMock(View::class); |
@@ -19,105 +19,105 @@ |
||
19 | 19 | use Sabre\DAV\Server; |
20 | 20 | |
21 | 21 | class CommentsPropertiesPluginTest extends \Test\TestCase { |
22 | - protected CommentPropertiesPluginImplementation $plugin; |
|
23 | - protected ICommentsManager&MockObject $commentsManager; |
|
24 | - protected IUserSession&MockObject $userSession; |
|
25 | - protected Server&MockObject $server; |
|
26 | - |
|
27 | - protected function setUp(): void { |
|
28 | - parent::setUp(); |
|
29 | - |
|
30 | - $this->commentsManager = $this->createMock(ICommentsManager::class); |
|
31 | - $this->userSession = $this->createMock(IUserSession::class); |
|
32 | - $this->server = $this->createMock(Server::class); |
|
33 | - |
|
34 | - $this->plugin = new CommentPropertiesPluginImplementation($this->commentsManager, $this->userSession); |
|
35 | - $this->plugin->initialize($this->server); |
|
36 | - } |
|
37 | - |
|
38 | - public static function nodeProvider(): array { |
|
39 | - return [ |
|
40 | - [File::class, true], |
|
41 | - [Directory::class, true], |
|
42 | - [\Sabre\DAV\INode::class, false] |
|
43 | - ]; |
|
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * @dataProvider nodeProvider |
|
48 | - */ |
|
49 | - public function testHandleGetProperties(string $class, bool $expectedSuccessful): void { |
|
50 | - $propFind = $this->createMock(PropFind::class); |
|
51 | - |
|
52 | - if ($expectedSuccessful) { |
|
53 | - $propFind->expects($this->exactly(3)) |
|
54 | - ->method('handle'); |
|
55 | - } else { |
|
56 | - $propFind->expects($this->never()) |
|
57 | - ->method('handle'); |
|
58 | - } |
|
59 | - |
|
60 | - $node = $this->createMock($class); |
|
61 | - $this->plugin->handleGetProperties($propFind, $node); |
|
62 | - } |
|
63 | - |
|
64 | - public static function baseUriProvider(): array { |
|
65 | - return [ |
|
66 | - ['owncloud/remote.php/webdav/', '4567', 'owncloud/remote.php/dav/comments/files/4567'], |
|
67 | - ['owncloud/remote.php/files/', '4567', 'owncloud/remote.php/dav/comments/files/4567'], |
|
68 | - ['owncloud/wicked.php/files/', '4567', null] |
|
69 | - ]; |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * @dataProvider baseUriProvider |
|
74 | - */ |
|
75 | - public function testGetCommentsLink(string $baseUri, string $fid, ?string $expectedHref): void { |
|
76 | - $node = $this->createMock(File::class); |
|
77 | - $node->expects($this->any()) |
|
78 | - ->method('getId') |
|
79 | - ->willReturn($fid); |
|
80 | - |
|
81 | - $this->server->expects($this->once()) |
|
82 | - ->method('getBaseUri') |
|
83 | - ->willReturn($baseUri); |
|
84 | - |
|
85 | - $href = $this->plugin->getCommentsLink($node); |
|
86 | - $this->assertSame($expectedHref, $href); |
|
87 | - } |
|
88 | - |
|
89 | - public static function userProvider(): array { |
|
90 | - return [ |
|
91 | - [IUser::class], |
|
92 | - [null] |
|
93 | - ]; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * @dataProvider userProvider |
|
98 | - */ |
|
99 | - public function testGetUnreadCount(?string $user): void { |
|
100 | - $node = $this->createMock(File::class); |
|
101 | - $node->expects($this->any()) |
|
102 | - ->method('getId') |
|
103 | - ->willReturn('4567'); |
|
104 | - |
|
105 | - if ($user !== null) { |
|
106 | - $user = $this->createMock($user); |
|
107 | - } |
|
108 | - $this->userSession->expects($this->once()) |
|
109 | - ->method('getUser') |
|
110 | - ->willReturn($user); |
|
111 | - |
|
112 | - $this->commentsManager->expects($this->any()) |
|
113 | - ->method('getNumberOfCommentsForObject') |
|
114 | - ->willReturn(42); |
|
115 | - |
|
116 | - $unread = $this->plugin->getUnreadCount($node); |
|
117 | - if (is_null($user)) { |
|
118 | - $this->assertNull($unread); |
|
119 | - } else { |
|
120 | - $this->assertSame($unread, 42); |
|
121 | - } |
|
122 | - } |
|
22 | + protected CommentPropertiesPluginImplementation $plugin; |
|
23 | + protected ICommentsManager&MockObject $commentsManager; |
|
24 | + protected IUserSession&MockObject $userSession; |
|
25 | + protected Server&MockObject $server; |
|
26 | + |
|
27 | + protected function setUp(): void { |
|
28 | + parent::setUp(); |
|
29 | + |
|
30 | + $this->commentsManager = $this->createMock(ICommentsManager::class); |
|
31 | + $this->userSession = $this->createMock(IUserSession::class); |
|
32 | + $this->server = $this->createMock(Server::class); |
|
33 | + |
|
34 | + $this->plugin = new CommentPropertiesPluginImplementation($this->commentsManager, $this->userSession); |
|
35 | + $this->plugin->initialize($this->server); |
|
36 | + } |
|
37 | + |
|
38 | + public static function nodeProvider(): array { |
|
39 | + return [ |
|
40 | + [File::class, true], |
|
41 | + [Directory::class, true], |
|
42 | + [\Sabre\DAV\INode::class, false] |
|
43 | + ]; |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * @dataProvider nodeProvider |
|
48 | + */ |
|
49 | + public function testHandleGetProperties(string $class, bool $expectedSuccessful): void { |
|
50 | + $propFind = $this->createMock(PropFind::class); |
|
51 | + |
|
52 | + if ($expectedSuccessful) { |
|
53 | + $propFind->expects($this->exactly(3)) |
|
54 | + ->method('handle'); |
|
55 | + } else { |
|
56 | + $propFind->expects($this->never()) |
|
57 | + ->method('handle'); |
|
58 | + } |
|
59 | + |
|
60 | + $node = $this->createMock($class); |
|
61 | + $this->plugin->handleGetProperties($propFind, $node); |
|
62 | + } |
|
63 | + |
|
64 | + public static function baseUriProvider(): array { |
|
65 | + return [ |
|
66 | + ['owncloud/remote.php/webdav/', '4567', 'owncloud/remote.php/dav/comments/files/4567'], |
|
67 | + ['owncloud/remote.php/files/', '4567', 'owncloud/remote.php/dav/comments/files/4567'], |
|
68 | + ['owncloud/wicked.php/files/', '4567', null] |
|
69 | + ]; |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * @dataProvider baseUriProvider |
|
74 | + */ |
|
75 | + public function testGetCommentsLink(string $baseUri, string $fid, ?string $expectedHref): void { |
|
76 | + $node = $this->createMock(File::class); |
|
77 | + $node->expects($this->any()) |
|
78 | + ->method('getId') |
|
79 | + ->willReturn($fid); |
|
80 | + |
|
81 | + $this->server->expects($this->once()) |
|
82 | + ->method('getBaseUri') |
|
83 | + ->willReturn($baseUri); |
|
84 | + |
|
85 | + $href = $this->plugin->getCommentsLink($node); |
|
86 | + $this->assertSame($expectedHref, $href); |
|
87 | + } |
|
88 | + |
|
89 | + public static function userProvider(): array { |
|
90 | + return [ |
|
91 | + [IUser::class], |
|
92 | + [null] |
|
93 | + ]; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * @dataProvider userProvider |
|
98 | + */ |
|
99 | + public function testGetUnreadCount(?string $user): void { |
|
100 | + $node = $this->createMock(File::class); |
|
101 | + $node->expects($this->any()) |
|
102 | + ->method('getId') |
|
103 | + ->willReturn('4567'); |
|
104 | + |
|
105 | + if ($user !== null) { |
|
106 | + $user = $this->createMock($user); |
|
107 | + } |
|
108 | + $this->userSession->expects($this->once()) |
|
109 | + ->method('getUser') |
|
110 | + ->willReturn($user); |
|
111 | + |
|
112 | + $this->commentsManager->expects($this->any()) |
|
113 | + ->method('getNumberOfCommentsForObject') |
|
114 | + ->willReturn(42); |
|
115 | + |
|
116 | + $unread = $this->plugin->getUnreadCount($node); |
|
117 | + if (is_null($user)) { |
|
118 | + $this->assertNull($unread); |
|
119 | + } else { |
|
120 | + $this->assertSame($unread, 42); |
|
121 | + } |
|
122 | + } |
|
123 | 123 | } |
@@ -23,390 +23,390 @@ |
||
23 | 23 | use Sabre\DAV\Tree; |
24 | 24 | |
25 | 25 | class TagsPluginTest extends \Test\TestCase { |
26 | - public const TAGS_PROPERTYNAME = TagsPlugin::TAGS_PROPERTYNAME; |
|
27 | - public const FAVORITE_PROPERTYNAME = TagsPlugin::FAVORITE_PROPERTYNAME; |
|
28 | - public const TAG_FAVORITE = TagsPlugin::TAG_FAVORITE; |
|
29 | - |
|
30 | - private \Sabre\DAV\Server $server; |
|
31 | - private Tree&MockObject $tree; |
|
32 | - private ITagManager&MockObject $tagManager; |
|
33 | - private ITags&MockObject $tagger; |
|
34 | - private IEventDispatcher&MockObject $eventDispatcher; |
|
35 | - private IUserSession&MockObject $userSession; |
|
36 | - private TagsPlugin $plugin; |
|
37 | - |
|
38 | - protected function setUp(): void { |
|
39 | - parent::setUp(); |
|
40 | - |
|
41 | - $this->server = new \Sabre\DAV\Server(); |
|
42 | - $this->tree = $this->createMock(Tree::class); |
|
43 | - $this->tagger = $this->createMock(ITags::class); |
|
44 | - $this->tagManager = $this->createMock(ITagManager::class); |
|
45 | - $this->eventDispatcher = $this->createMock(IEventDispatcher::class); |
|
46 | - $user = $this->createMock(IUser::class); |
|
47 | - |
|
48 | - $this->userSession = $this->createMock(IUserSession::class); |
|
49 | - $this->userSession->expects($this->any()) |
|
50 | - ->method('getUser') |
|
51 | - ->withAnyParameters() |
|
52 | - ->willReturn($user); |
|
53 | - $this->tagManager->expects($this->any()) |
|
54 | - ->method('load') |
|
55 | - ->with('files') |
|
56 | - ->willReturn($this->tagger); |
|
57 | - $this->plugin = new TagsPlugin($this->tree, $this->tagManager, $this->eventDispatcher, $this->userSession); |
|
58 | - $this->plugin->initialize($this->server); |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * @dataProvider tagsGetPropertiesDataProvider |
|
63 | - */ |
|
64 | - public function testGetProperties(array $tags, array $requestedProperties, array $expectedProperties): void { |
|
65 | - $node = $this->createMock(Node::class); |
|
66 | - $node->expects($this->any()) |
|
67 | - ->method('getId') |
|
68 | - ->willReturn(123); |
|
69 | - |
|
70 | - $expectedCallCount = 0; |
|
71 | - if (count($requestedProperties) > 0) { |
|
72 | - $expectedCallCount = 1; |
|
73 | - } |
|
74 | - |
|
75 | - $this->tagger->expects($this->exactly($expectedCallCount)) |
|
76 | - ->method('getTagsForObjects') |
|
77 | - ->with($this->equalTo([123])) |
|
78 | - ->willReturn([123 => $tags]); |
|
79 | - |
|
80 | - $propFind = new \Sabre\DAV\PropFind( |
|
81 | - '/dummyPath', |
|
82 | - $requestedProperties, |
|
83 | - 0 |
|
84 | - ); |
|
85 | - |
|
86 | - $this->plugin->handleGetProperties( |
|
87 | - $propFind, |
|
88 | - $node |
|
89 | - ); |
|
90 | - |
|
91 | - $result = $propFind->getResultForMultiStatus(); |
|
92 | - |
|
93 | - $this->assertEmpty($result[404]); |
|
94 | - unset($result[404]); |
|
95 | - $this->assertEquals($expectedProperties, $result); |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * @dataProvider tagsGetPropertiesDataProvider |
|
100 | - */ |
|
101 | - public function testPreloadThenGetProperties(array $tags, array $requestedProperties, array $expectedProperties): void { |
|
102 | - $node1 = $this->createMock(File::class); |
|
103 | - $node1->expects($this->any()) |
|
104 | - ->method('getId') |
|
105 | - ->willReturn(111); |
|
106 | - $node2 = $this->createMock(File::class); |
|
107 | - $node2->expects($this->any()) |
|
108 | - ->method('getId') |
|
109 | - ->willReturn(222); |
|
110 | - |
|
111 | - $expectedCallCount = 0; |
|
112 | - if (count($requestedProperties) > 0) { |
|
113 | - // this guarantees that getTagsForObjects |
|
114 | - // is only called once and then the tags |
|
115 | - // are cached |
|
116 | - $expectedCallCount = 1; |
|
117 | - } |
|
118 | - |
|
119 | - $node = $this->createMock(Directory::class); |
|
120 | - $node->expects($this->any()) |
|
121 | - ->method('getId') |
|
122 | - ->willReturn(123); |
|
123 | - $node->expects($this->exactly($expectedCallCount)) |
|
124 | - ->method('getChildren') |
|
125 | - ->willReturn([$node1, $node2]); |
|
126 | - |
|
127 | - $this->tagger->expects($this->exactly($expectedCallCount)) |
|
128 | - ->method('getTagsForObjects') |
|
129 | - ->with($this->equalTo([123, 111, 222])) |
|
130 | - ->willReturn( |
|
131 | - [ |
|
132 | - 111 => $tags, |
|
133 | - 123 => $tags |
|
134 | - ] |
|
135 | - ); |
|
136 | - |
|
137 | - // simulate sabre recursive PROPFIND traversal |
|
138 | - $propFindRoot = new \Sabre\DAV\PropFind( |
|
139 | - '/subdir', |
|
140 | - $requestedProperties, |
|
141 | - 1 |
|
142 | - ); |
|
143 | - $propFind1 = new \Sabre\DAV\PropFind( |
|
144 | - '/subdir/test.txt', |
|
145 | - $requestedProperties, |
|
146 | - 0 |
|
147 | - ); |
|
148 | - $propFind2 = new \Sabre\DAV\PropFind( |
|
149 | - '/subdir/test2.txt', |
|
150 | - $requestedProperties, |
|
151 | - 0 |
|
152 | - ); |
|
153 | - |
|
154 | - $this->plugin->handleGetProperties( |
|
155 | - $propFindRoot, |
|
156 | - $node |
|
157 | - ); |
|
158 | - $this->plugin->handleGetProperties( |
|
159 | - $propFind1, |
|
160 | - $node1 |
|
161 | - ); |
|
162 | - $this->plugin->handleGetProperties( |
|
163 | - $propFind2, |
|
164 | - $node2 |
|
165 | - ); |
|
166 | - |
|
167 | - $result = $propFind1->getResultForMultiStatus(); |
|
168 | - |
|
169 | - $this->assertEmpty($result[404]); |
|
170 | - unset($result[404]); |
|
171 | - $this->assertEquals($expectedProperties, $result); |
|
172 | - } |
|
173 | - |
|
174 | - public static function tagsGetPropertiesDataProvider(): array { |
|
175 | - return [ |
|
176 | - // request both, receive both |
|
177 | - [ |
|
178 | - ['tag1', 'tag2', self::TAG_FAVORITE], |
|
179 | - [self::TAGS_PROPERTYNAME, self::FAVORITE_PROPERTYNAME], |
|
180 | - [ |
|
181 | - 200 => [ |
|
182 | - self::TAGS_PROPERTYNAME => new TagList(['tag1', 'tag2']), |
|
183 | - self::FAVORITE_PROPERTYNAME => true, |
|
184 | - ] |
|
185 | - ] |
|
186 | - ], |
|
187 | - // request tags alone |
|
188 | - [ |
|
189 | - ['tag1', 'tag2', self::TAG_FAVORITE], |
|
190 | - [self::TAGS_PROPERTYNAME], |
|
191 | - [ |
|
192 | - 200 => [ |
|
193 | - self::TAGS_PROPERTYNAME => new TagList(['tag1', 'tag2']), |
|
194 | - ] |
|
195 | - ] |
|
196 | - ], |
|
197 | - // request fav alone |
|
198 | - [ |
|
199 | - ['tag1', 'tag2', self::TAG_FAVORITE], |
|
200 | - [self::FAVORITE_PROPERTYNAME], |
|
201 | - [ |
|
202 | - 200 => [ |
|
203 | - self::FAVORITE_PROPERTYNAME => true, |
|
204 | - ] |
|
205 | - ] |
|
206 | - ], |
|
207 | - // request none |
|
208 | - [ |
|
209 | - ['tag1', 'tag2', self::TAG_FAVORITE], |
|
210 | - [], |
|
211 | - [ |
|
212 | - 200 => [] |
|
213 | - ], |
|
214 | - ], |
|
215 | - // request both with none set, receive both |
|
216 | - [ |
|
217 | - [], |
|
218 | - [self::TAGS_PROPERTYNAME, self::FAVORITE_PROPERTYNAME], |
|
219 | - [ |
|
220 | - 200 => [ |
|
221 | - self::TAGS_PROPERTYNAME => new TagList([]), |
|
222 | - self::FAVORITE_PROPERTYNAME => false, |
|
223 | - ] |
|
224 | - ] |
|
225 | - ], |
|
226 | - ]; |
|
227 | - } |
|
228 | - |
|
229 | - public function testGetPropertiesSkipChunks(): void { |
|
230 | - $sabreNode = $this->createMock(UploadFile::class); |
|
231 | - |
|
232 | - $propFind = new \Sabre\DAV\PropFind( |
|
233 | - '/dummyPath', |
|
234 | - [self::TAGS_PROPERTYNAME, self::TAG_FAVORITE], |
|
235 | - 0 |
|
236 | - ); |
|
237 | - |
|
238 | - $this->plugin->handleGetProperties( |
|
239 | - $propFind, |
|
240 | - $sabreNode |
|
241 | - ); |
|
242 | - |
|
243 | - $result = $propFind->getResultForMultiStatus(); |
|
244 | - $this->assertCount(2, $result[404]); |
|
245 | - } |
|
246 | - |
|
247 | - public function testUpdateTags(): void { |
|
248 | - // this test will replace the existing tags "tagremove" with "tag1" and "tag2" |
|
249 | - // and keep "tagkeep" |
|
250 | - $node = $this->createMock(Node::class); |
|
251 | - $node->expects($this->any()) |
|
252 | - ->method('getId') |
|
253 | - ->willReturn(123); |
|
254 | - |
|
255 | - $this->tree->expects($this->any()) |
|
256 | - ->method('getNodeForPath') |
|
257 | - ->with('/dummypath') |
|
258 | - ->willReturn($node); |
|
259 | - |
|
260 | - $this->tagger->expects($this->once()) |
|
261 | - ->method('getTagsForObjects') |
|
262 | - ->with($this->equalTo([123])) |
|
263 | - ->willReturn([123 => ['tagkeep', 'tagremove', self::TAG_FAVORITE]]); |
|
264 | - |
|
265 | - // then tag as tag1 and tag2 |
|
266 | - $calls = [ |
|
267 | - [123, 'tag1'], |
|
268 | - [123, 'tag2'], |
|
269 | - ]; |
|
270 | - $this->tagger->expects($this->exactly(count($calls))) |
|
271 | - ->method('tagAs') |
|
272 | - ->willReturnCallback(function () use (&$calls) { |
|
273 | - $expected = array_shift($calls); |
|
274 | - $this->assertEquals($expected, func_get_args()); |
|
275 | - }); |
|
276 | - |
|
277 | - // it will untag tag3 |
|
278 | - $this->tagger->expects($this->once()) |
|
279 | - ->method('unTag') |
|
280 | - ->with(123, 'tagremove'); |
|
281 | - |
|
282 | - // properties to set |
|
283 | - $propPatch = new \Sabre\DAV\PropPatch([ |
|
284 | - self::TAGS_PROPERTYNAME => new TagList(['tag1', 'tag2', 'tagkeep']) |
|
285 | - ]); |
|
286 | - |
|
287 | - $this->plugin->handleUpdateProperties( |
|
288 | - '/dummypath', |
|
289 | - $propPatch |
|
290 | - ); |
|
291 | - |
|
292 | - $propPatch->commit(); |
|
293 | - |
|
294 | - // all requested properties removed, as they were processed already |
|
295 | - $this->assertEmpty($propPatch->getRemainingMutations()); |
|
296 | - |
|
297 | - $result = $propPatch->getResult(); |
|
298 | - $this->assertEquals(200, $result[self::TAGS_PROPERTYNAME]); |
|
299 | - $this->assertArrayNotHasKey(self::FAVORITE_PROPERTYNAME, $result); |
|
300 | - } |
|
301 | - |
|
302 | - public function testUpdateTagsFromScratch(): void { |
|
303 | - $node = $this->createMock(Node::class); |
|
304 | - $node->expects($this->any()) |
|
305 | - ->method('getId') |
|
306 | - ->willReturn(123); |
|
307 | - |
|
308 | - $this->tree->expects($this->any()) |
|
309 | - ->method('getNodeForPath') |
|
310 | - ->with('/dummypath') |
|
311 | - ->willReturn($node); |
|
312 | - |
|
313 | - $this->tagger->expects($this->once()) |
|
314 | - ->method('getTagsForObjects') |
|
315 | - ->with($this->equalTo([123])) |
|
316 | - ->willReturn([]); |
|
317 | - |
|
318 | - // then tag as tag1 and tag2 |
|
319 | - $calls = [ |
|
320 | - [123, 'tag1'], |
|
321 | - [123, 'tag2'], |
|
322 | - ]; |
|
323 | - $this->tagger->expects($this->exactly(count($calls))) |
|
324 | - ->method('tagAs') |
|
325 | - ->willReturnCallback(function () use (&$calls) { |
|
326 | - $expected = array_shift($calls); |
|
327 | - $this->assertEquals($expected, func_get_args()); |
|
328 | - }); |
|
329 | - |
|
330 | - // properties to set |
|
331 | - $propPatch = new \Sabre\DAV\PropPatch([ |
|
332 | - self::TAGS_PROPERTYNAME => new TagList(['tag1', 'tag2']) |
|
333 | - ]); |
|
334 | - |
|
335 | - $this->plugin->handleUpdateProperties( |
|
336 | - '/dummypath', |
|
337 | - $propPatch |
|
338 | - ); |
|
339 | - |
|
340 | - $propPatch->commit(); |
|
341 | - |
|
342 | - // all requested properties removed, as they were processed already |
|
343 | - $this->assertEmpty($propPatch->getRemainingMutations()); |
|
344 | - |
|
345 | - $result = $propPatch->getResult(); |
|
346 | - $this->assertEquals(200, $result[self::TAGS_PROPERTYNAME]); |
|
347 | - $this->assertArrayNotHasKey(self::FAVORITE_PROPERTYNAME, $result); |
|
348 | - } |
|
349 | - |
|
350 | - public function testUpdateFav(): void { |
|
351 | - // this test will replace the existing tags "tagremove" with "tag1" and "tag2" |
|
352 | - // and keep "tagkeep" |
|
353 | - $node = $this->createMock(Node::class); |
|
354 | - $node->expects($this->any()) |
|
355 | - ->method('getId') |
|
356 | - ->willReturn(123); |
|
357 | - |
|
358 | - $this->tree->expects($this->any()) |
|
359 | - ->method('getNodeForPath') |
|
360 | - ->with('/dummypath') |
|
361 | - ->willReturn($node); |
|
362 | - |
|
363 | - // set favorite tag |
|
364 | - $this->tagger->expects($this->once()) |
|
365 | - ->method('tagAs') |
|
366 | - ->with(123, self::TAG_FAVORITE); |
|
367 | - |
|
368 | - // properties to set |
|
369 | - $propPatch = new \Sabre\DAV\PropPatch([ |
|
370 | - self::FAVORITE_PROPERTYNAME => true |
|
371 | - ]); |
|
372 | - |
|
373 | - $this->plugin->handleUpdateProperties( |
|
374 | - '/dummypath', |
|
375 | - $propPatch |
|
376 | - ); |
|
377 | - |
|
378 | - $propPatch->commit(); |
|
379 | - |
|
380 | - // all requested properties removed, as they were processed already |
|
381 | - $this->assertEmpty($propPatch->getRemainingMutations()); |
|
382 | - |
|
383 | - $result = $propPatch->getResult(); |
|
384 | - $this->assertArrayNotHasKey(self::TAGS_PROPERTYNAME, $result); |
|
385 | - $this->assertEquals(200, $result[self::FAVORITE_PROPERTYNAME]); |
|
386 | - |
|
387 | - // unfavorite now |
|
388 | - // set favorite tag |
|
389 | - $this->tagger->expects($this->once()) |
|
390 | - ->method('unTag') |
|
391 | - ->with(123, self::TAG_FAVORITE); |
|
392 | - |
|
393 | - // properties to set |
|
394 | - $propPatch = new \Sabre\DAV\PropPatch([ |
|
395 | - self::FAVORITE_PROPERTYNAME => false |
|
396 | - ]); |
|
397 | - |
|
398 | - $this->plugin->handleUpdateProperties( |
|
399 | - '/dummypath', |
|
400 | - $propPatch |
|
401 | - ); |
|
402 | - |
|
403 | - $propPatch->commit(); |
|
404 | - |
|
405 | - // all requested properties removed, as they were processed already |
|
406 | - $this->assertEmpty($propPatch->getRemainingMutations()); |
|
407 | - |
|
408 | - $result = $propPatch->getResult(); |
|
409 | - $this->assertArrayNotHasKey(self::TAGS_PROPERTYNAME, $result); |
|
410 | - $this->assertEquals(200, $result[self::FAVORITE_PROPERTYNAME]); |
|
411 | - } |
|
26 | + public const TAGS_PROPERTYNAME = TagsPlugin::TAGS_PROPERTYNAME; |
|
27 | + public const FAVORITE_PROPERTYNAME = TagsPlugin::FAVORITE_PROPERTYNAME; |
|
28 | + public const TAG_FAVORITE = TagsPlugin::TAG_FAVORITE; |
|
29 | + |
|
30 | + private \Sabre\DAV\Server $server; |
|
31 | + private Tree&MockObject $tree; |
|
32 | + private ITagManager&MockObject $tagManager; |
|
33 | + private ITags&MockObject $tagger; |
|
34 | + private IEventDispatcher&MockObject $eventDispatcher; |
|
35 | + private IUserSession&MockObject $userSession; |
|
36 | + private TagsPlugin $plugin; |
|
37 | + |
|
38 | + protected function setUp(): void { |
|
39 | + parent::setUp(); |
|
40 | + |
|
41 | + $this->server = new \Sabre\DAV\Server(); |
|
42 | + $this->tree = $this->createMock(Tree::class); |
|
43 | + $this->tagger = $this->createMock(ITags::class); |
|
44 | + $this->tagManager = $this->createMock(ITagManager::class); |
|
45 | + $this->eventDispatcher = $this->createMock(IEventDispatcher::class); |
|
46 | + $user = $this->createMock(IUser::class); |
|
47 | + |
|
48 | + $this->userSession = $this->createMock(IUserSession::class); |
|
49 | + $this->userSession->expects($this->any()) |
|
50 | + ->method('getUser') |
|
51 | + ->withAnyParameters() |
|
52 | + ->willReturn($user); |
|
53 | + $this->tagManager->expects($this->any()) |
|
54 | + ->method('load') |
|
55 | + ->with('files') |
|
56 | + ->willReturn($this->tagger); |
|
57 | + $this->plugin = new TagsPlugin($this->tree, $this->tagManager, $this->eventDispatcher, $this->userSession); |
|
58 | + $this->plugin->initialize($this->server); |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * @dataProvider tagsGetPropertiesDataProvider |
|
63 | + */ |
|
64 | + public function testGetProperties(array $tags, array $requestedProperties, array $expectedProperties): void { |
|
65 | + $node = $this->createMock(Node::class); |
|
66 | + $node->expects($this->any()) |
|
67 | + ->method('getId') |
|
68 | + ->willReturn(123); |
|
69 | + |
|
70 | + $expectedCallCount = 0; |
|
71 | + if (count($requestedProperties) > 0) { |
|
72 | + $expectedCallCount = 1; |
|
73 | + } |
|
74 | + |
|
75 | + $this->tagger->expects($this->exactly($expectedCallCount)) |
|
76 | + ->method('getTagsForObjects') |
|
77 | + ->with($this->equalTo([123])) |
|
78 | + ->willReturn([123 => $tags]); |
|
79 | + |
|
80 | + $propFind = new \Sabre\DAV\PropFind( |
|
81 | + '/dummyPath', |
|
82 | + $requestedProperties, |
|
83 | + 0 |
|
84 | + ); |
|
85 | + |
|
86 | + $this->plugin->handleGetProperties( |
|
87 | + $propFind, |
|
88 | + $node |
|
89 | + ); |
|
90 | + |
|
91 | + $result = $propFind->getResultForMultiStatus(); |
|
92 | + |
|
93 | + $this->assertEmpty($result[404]); |
|
94 | + unset($result[404]); |
|
95 | + $this->assertEquals($expectedProperties, $result); |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * @dataProvider tagsGetPropertiesDataProvider |
|
100 | + */ |
|
101 | + public function testPreloadThenGetProperties(array $tags, array $requestedProperties, array $expectedProperties): void { |
|
102 | + $node1 = $this->createMock(File::class); |
|
103 | + $node1->expects($this->any()) |
|
104 | + ->method('getId') |
|
105 | + ->willReturn(111); |
|
106 | + $node2 = $this->createMock(File::class); |
|
107 | + $node2->expects($this->any()) |
|
108 | + ->method('getId') |
|
109 | + ->willReturn(222); |
|
110 | + |
|
111 | + $expectedCallCount = 0; |
|
112 | + if (count($requestedProperties) > 0) { |
|
113 | + // this guarantees that getTagsForObjects |
|
114 | + // is only called once and then the tags |
|
115 | + // are cached |
|
116 | + $expectedCallCount = 1; |
|
117 | + } |
|
118 | + |
|
119 | + $node = $this->createMock(Directory::class); |
|
120 | + $node->expects($this->any()) |
|
121 | + ->method('getId') |
|
122 | + ->willReturn(123); |
|
123 | + $node->expects($this->exactly($expectedCallCount)) |
|
124 | + ->method('getChildren') |
|
125 | + ->willReturn([$node1, $node2]); |
|
126 | + |
|
127 | + $this->tagger->expects($this->exactly($expectedCallCount)) |
|
128 | + ->method('getTagsForObjects') |
|
129 | + ->with($this->equalTo([123, 111, 222])) |
|
130 | + ->willReturn( |
|
131 | + [ |
|
132 | + 111 => $tags, |
|
133 | + 123 => $tags |
|
134 | + ] |
|
135 | + ); |
|
136 | + |
|
137 | + // simulate sabre recursive PROPFIND traversal |
|
138 | + $propFindRoot = new \Sabre\DAV\PropFind( |
|
139 | + '/subdir', |
|
140 | + $requestedProperties, |
|
141 | + 1 |
|
142 | + ); |
|
143 | + $propFind1 = new \Sabre\DAV\PropFind( |
|
144 | + '/subdir/test.txt', |
|
145 | + $requestedProperties, |
|
146 | + 0 |
|
147 | + ); |
|
148 | + $propFind2 = new \Sabre\DAV\PropFind( |
|
149 | + '/subdir/test2.txt', |
|
150 | + $requestedProperties, |
|
151 | + 0 |
|
152 | + ); |
|
153 | + |
|
154 | + $this->plugin->handleGetProperties( |
|
155 | + $propFindRoot, |
|
156 | + $node |
|
157 | + ); |
|
158 | + $this->plugin->handleGetProperties( |
|
159 | + $propFind1, |
|
160 | + $node1 |
|
161 | + ); |
|
162 | + $this->plugin->handleGetProperties( |
|
163 | + $propFind2, |
|
164 | + $node2 |
|
165 | + ); |
|
166 | + |
|
167 | + $result = $propFind1->getResultForMultiStatus(); |
|
168 | + |
|
169 | + $this->assertEmpty($result[404]); |
|
170 | + unset($result[404]); |
|
171 | + $this->assertEquals($expectedProperties, $result); |
|
172 | + } |
|
173 | + |
|
174 | + public static function tagsGetPropertiesDataProvider(): array { |
|
175 | + return [ |
|
176 | + // request both, receive both |
|
177 | + [ |
|
178 | + ['tag1', 'tag2', self::TAG_FAVORITE], |
|
179 | + [self::TAGS_PROPERTYNAME, self::FAVORITE_PROPERTYNAME], |
|
180 | + [ |
|
181 | + 200 => [ |
|
182 | + self::TAGS_PROPERTYNAME => new TagList(['tag1', 'tag2']), |
|
183 | + self::FAVORITE_PROPERTYNAME => true, |
|
184 | + ] |
|
185 | + ] |
|
186 | + ], |
|
187 | + // request tags alone |
|
188 | + [ |
|
189 | + ['tag1', 'tag2', self::TAG_FAVORITE], |
|
190 | + [self::TAGS_PROPERTYNAME], |
|
191 | + [ |
|
192 | + 200 => [ |
|
193 | + self::TAGS_PROPERTYNAME => new TagList(['tag1', 'tag2']), |
|
194 | + ] |
|
195 | + ] |
|
196 | + ], |
|
197 | + // request fav alone |
|
198 | + [ |
|
199 | + ['tag1', 'tag2', self::TAG_FAVORITE], |
|
200 | + [self::FAVORITE_PROPERTYNAME], |
|
201 | + [ |
|
202 | + 200 => [ |
|
203 | + self::FAVORITE_PROPERTYNAME => true, |
|
204 | + ] |
|
205 | + ] |
|
206 | + ], |
|
207 | + // request none |
|
208 | + [ |
|
209 | + ['tag1', 'tag2', self::TAG_FAVORITE], |
|
210 | + [], |
|
211 | + [ |
|
212 | + 200 => [] |
|
213 | + ], |
|
214 | + ], |
|
215 | + // request both with none set, receive both |
|
216 | + [ |
|
217 | + [], |
|
218 | + [self::TAGS_PROPERTYNAME, self::FAVORITE_PROPERTYNAME], |
|
219 | + [ |
|
220 | + 200 => [ |
|
221 | + self::TAGS_PROPERTYNAME => new TagList([]), |
|
222 | + self::FAVORITE_PROPERTYNAME => false, |
|
223 | + ] |
|
224 | + ] |
|
225 | + ], |
|
226 | + ]; |
|
227 | + } |
|
228 | + |
|
229 | + public function testGetPropertiesSkipChunks(): void { |
|
230 | + $sabreNode = $this->createMock(UploadFile::class); |
|
231 | + |
|
232 | + $propFind = new \Sabre\DAV\PropFind( |
|
233 | + '/dummyPath', |
|
234 | + [self::TAGS_PROPERTYNAME, self::TAG_FAVORITE], |
|
235 | + 0 |
|
236 | + ); |
|
237 | + |
|
238 | + $this->plugin->handleGetProperties( |
|
239 | + $propFind, |
|
240 | + $sabreNode |
|
241 | + ); |
|
242 | + |
|
243 | + $result = $propFind->getResultForMultiStatus(); |
|
244 | + $this->assertCount(2, $result[404]); |
|
245 | + } |
|
246 | + |
|
247 | + public function testUpdateTags(): void { |
|
248 | + // this test will replace the existing tags "tagremove" with "tag1" and "tag2" |
|
249 | + // and keep "tagkeep" |
|
250 | + $node = $this->createMock(Node::class); |
|
251 | + $node->expects($this->any()) |
|
252 | + ->method('getId') |
|
253 | + ->willReturn(123); |
|
254 | + |
|
255 | + $this->tree->expects($this->any()) |
|
256 | + ->method('getNodeForPath') |
|
257 | + ->with('/dummypath') |
|
258 | + ->willReturn($node); |
|
259 | + |
|
260 | + $this->tagger->expects($this->once()) |
|
261 | + ->method('getTagsForObjects') |
|
262 | + ->with($this->equalTo([123])) |
|
263 | + ->willReturn([123 => ['tagkeep', 'tagremove', self::TAG_FAVORITE]]); |
|
264 | + |
|
265 | + // then tag as tag1 and tag2 |
|
266 | + $calls = [ |
|
267 | + [123, 'tag1'], |
|
268 | + [123, 'tag2'], |
|
269 | + ]; |
|
270 | + $this->tagger->expects($this->exactly(count($calls))) |
|
271 | + ->method('tagAs') |
|
272 | + ->willReturnCallback(function () use (&$calls) { |
|
273 | + $expected = array_shift($calls); |
|
274 | + $this->assertEquals($expected, func_get_args()); |
|
275 | + }); |
|
276 | + |
|
277 | + // it will untag tag3 |
|
278 | + $this->tagger->expects($this->once()) |
|
279 | + ->method('unTag') |
|
280 | + ->with(123, 'tagremove'); |
|
281 | + |
|
282 | + // properties to set |
|
283 | + $propPatch = new \Sabre\DAV\PropPatch([ |
|
284 | + self::TAGS_PROPERTYNAME => new TagList(['tag1', 'tag2', 'tagkeep']) |
|
285 | + ]); |
|
286 | + |
|
287 | + $this->plugin->handleUpdateProperties( |
|
288 | + '/dummypath', |
|
289 | + $propPatch |
|
290 | + ); |
|
291 | + |
|
292 | + $propPatch->commit(); |
|
293 | + |
|
294 | + // all requested properties removed, as they were processed already |
|
295 | + $this->assertEmpty($propPatch->getRemainingMutations()); |
|
296 | + |
|
297 | + $result = $propPatch->getResult(); |
|
298 | + $this->assertEquals(200, $result[self::TAGS_PROPERTYNAME]); |
|
299 | + $this->assertArrayNotHasKey(self::FAVORITE_PROPERTYNAME, $result); |
|
300 | + } |
|
301 | + |
|
302 | + public function testUpdateTagsFromScratch(): void { |
|
303 | + $node = $this->createMock(Node::class); |
|
304 | + $node->expects($this->any()) |
|
305 | + ->method('getId') |
|
306 | + ->willReturn(123); |
|
307 | + |
|
308 | + $this->tree->expects($this->any()) |
|
309 | + ->method('getNodeForPath') |
|
310 | + ->with('/dummypath') |
|
311 | + ->willReturn($node); |
|
312 | + |
|
313 | + $this->tagger->expects($this->once()) |
|
314 | + ->method('getTagsForObjects') |
|
315 | + ->with($this->equalTo([123])) |
|
316 | + ->willReturn([]); |
|
317 | + |
|
318 | + // then tag as tag1 and tag2 |
|
319 | + $calls = [ |
|
320 | + [123, 'tag1'], |
|
321 | + [123, 'tag2'], |
|
322 | + ]; |
|
323 | + $this->tagger->expects($this->exactly(count($calls))) |
|
324 | + ->method('tagAs') |
|
325 | + ->willReturnCallback(function () use (&$calls) { |
|
326 | + $expected = array_shift($calls); |
|
327 | + $this->assertEquals($expected, func_get_args()); |
|
328 | + }); |
|
329 | + |
|
330 | + // properties to set |
|
331 | + $propPatch = new \Sabre\DAV\PropPatch([ |
|
332 | + self::TAGS_PROPERTYNAME => new TagList(['tag1', 'tag2']) |
|
333 | + ]); |
|
334 | + |
|
335 | + $this->plugin->handleUpdateProperties( |
|
336 | + '/dummypath', |
|
337 | + $propPatch |
|
338 | + ); |
|
339 | + |
|
340 | + $propPatch->commit(); |
|
341 | + |
|
342 | + // all requested properties removed, as they were processed already |
|
343 | + $this->assertEmpty($propPatch->getRemainingMutations()); |
|
344 | + |
|
345 | + $result = $propPatch->getResult(); |
|
346 | + $this->assertEquals(200, $result[self::TAGS_PROPERTYNAME]); |
|
347 | + $this->assertArrayNotHasKey(self::FAVORITE_PROPERTYNAME, $result); |
|
348 | + } |
|
349 | + |
|
350 | + public function testUpdateFav(): void { |
|
351 | + // this test will replace the existing tags "tagremove" with "tag1" and "tag2" |
|
352 | + // and keep "tagkeep" |
|
353 | + $node = $this->createMock(Node::class); |
|
354 | + $node->expects($this->any()) |
|
355 | + ->method('getId') |
|
356 | + ->willReturn(123); |
|
357 | + |
|
358 | + $this->tree->expects($this->any()) |
|
359 | + ->method('getNodeForPath') |
|
360 | + ->with('/dummypath') |
|
361 | + ->willReturn($node); |
|
362 | + |
|
363 | + // set favorite tag |
|
364 | + $this->tagger->expects($this->once()) |
|
365 | + ->method('tagAs') |
|
366 | + ->with(123, self::TAG_FAVORITE); |
|
367 | + |
|
368 | + // properties to set |
|
369 | + $propPatch = new \Sabre\DAV\PropPatch([ |
|
370 | + self::FAVORITE_PROPERTYNAME => true |
|
371 | + ]); |
|
372 | + |
|
373 | + $this->plugin->handleUpdateProperties( |
|
374 | + '/dummypath', |
|
375 | + $propPatch |
|
376 | + ); |
|
377 | + |
|
378 | + $propPatch->commit(); |
|
379 | + |
|
380 | + // all requested properties removed, as they were processed already |
|
381 | + $this->assertEmpty($propPatch->getRemainingMutations()); |
|
382 | + |
|
383 | + $result = $propPatch->getResult(); |
|
384 | + $this->assertArrayNotHasKey(self::TAGS_PROPERTYNAME, $result); |
|
385 | + $this->assertEquals(200, $result[self::FAVORITE_PROPERTYNAME]); |
|
386 | + |
|
387 | + // unfavorite now |
|
388 | + // set favorite tag |
|
389 | + $this->tagger->expects($this->once()) |
|
390 | + ->method('unTag') |
|
391 | + ->with(123, self::TAG_FAVORITE); |
|
392 | + |
|
393 | + // properties to set |
|
394 | + $propPatch = new \Sabre\DAV\PropPatch([ |
|
395 | + self::FAVORITE_PROPERTYNAME => false |
|
396 | + ]); |
|
397 | + |
|
398 | + $this->plugin->handleUpdateProperties( |
|
399 | + '/dummypath', |
|
400 | + $propPatch |
|
401 | + ); |
|
402 | + |
|
403 | + $propPatch->commit(); |
|
404 | + |
|
405 | + // all requested properties removed, as they were processed already |
|
406 | + $this->assertEmpty($propPatch->getRemainingMutations()); |
|
407 | + |
|
408 | + $result = $propPatch->getResult(); |
|
409 | + $this->assertArrayNotHasKey(self::TAGS_PROPERTYNAME, $result); |
|
410 | + $this->assertEquals(200, $result[self::FAVORITE_PROPERTYNAME]); |
|
411 | + } |
|
412 | 412 | } |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | ]; |
270 | 270 | $this->tagger->expects($this->exactly(count($calls))) |
271 | 271 | ->method('tagAs') |
272 | - ->willReturnCallback(function () use (&$calls) { |
|
272 | + ->willReturnCallback(function() use (&$calls) { |
|
273 | 273 | $expected = array_shift($calls); |
274 | 274 | $this->assertEquals($expected, func_get_args()); |
275 | 275 | }); |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | ]; |
323 | 323 | $this->tagger->expects($this->exactly(count($calls))) |
324 | 324 | ->method('tagAs') |
325 | - ->willReturnCallback(function () use (&$calls) { |
|
325 | + ->willReturnCallback(function() use (&$calls) { |
|
326 | 326 | $expected = array_shift($calls); |
327 | 327 | $this->assertEquals($expected, func_get_args()); |
328 | 328 | }); |
@@ -20,38 +20,38 @@ |
||
20 | 20 | * @package OCA\DAV\Tests\unit\Connector\Sabre |
21 | 21 | */ |
22 | 22 | class DummyGetResponsePluginTest extends TestCase { |
23 | - private DummyGetResponsePlugin $dummyGetResponsePlugin; |
|
24 | - |
|
25 | - protected function setUp(): void { |
|
26 | - parent::setUp(); |
|
27 | - |
|
28 | - $this->dummyGetResponsePlugin = new DummyGetResponsePlugin(); |
|
29 | - } |
|
30 | - |
|
31 | - public function testInitialize(): void { |
|
32 | - $server = $this->createMock(Server::class); |
|
33 | - $server |
|
34 | - ->expects($this->once()) |
|
35 | - ->method('on') |
|
36 | - ->with('method:GET', [$this->dummyGetResponsePlugin, 'httpGet'], 200); |
|
37 | - |
|
38 | - $this->dummyGetResponsePlugin->initialize($server); |
|
39 | - } |
|
40 | - |
|
41 | - |
|
42 | - public function testHttpGet(): void { |
|
43 | - /** @var \Sabre\HTTP\RequestInterface $request */ |
|
44 | - $request = $this->createMock(RequestInterface::class); |
|
45 | - /** @var \Sabre\HTTP\ResponseInterface $response */ |
|
46 | - $response = $this->createMock(ResponseInterface::class); |
|
47 | - $response |
|
48 | - ->expects($this->once()) |
|
49 | - ->method('setBody'); |
|
50 | - $response |
|
51 | - ->expects($this->once()) |
|
52 | - ->method('setStatus') |
|
53 | - ->with(200); |
|
54 | - |
|
55 | - $this->assertSame(false, $this->dummyGetResponsePlugin->httpGet($request, $response)); |
|
56 | - } |
|
23 | + private DummyGetResponsePlugin $dummyGetResponsePlugin; |
|
24 | + |
|
25 | + protected function setUp(): void { |
|
26 | + parent::setUp(); |
|
27 | + |
|
28 | + $this->dummyGetResponsePlugin = new DummyGetResponsePlugin(); |
|
29 | + } |
|
30 | + |
|
31 | + public function testInitialize(): void { |
|
32 | + $server = $this->createMock(Server::class); |
|
33 | + $server |
|
34 | + ->expects($this->once()) |
|
35 | + ->method('on') |
|
36 | + ->with('method:GET', [$this->dummyGetResponsePlugin, 'httpGet'], 200); |
|
37 | + |
|
38 | + $this->dummyGetResponsePlugin->initialize($server); |
|
39 | + } |
|
40 | + |
|
41 | + |
|
42 | + public function testHttpGet(): void { |
|
43 | + /** @var \Sabre\HTTP\RequestInterface $request */ |
|
44 | + $request = $this->createMock(RequestInterface::class); |
|
45 | + /** @var \Sabre\HTTP\ResponseInterface $response */ |
|
46 | + $response = $this->createMock(ResponseInterface::class); |
|
47 | + $response |
|
48 | + ->expects($this->once()) |
|
49 | + ->method('setBody'); |
|
50 | + $response |
|
51 | + ->expects($this->once()) |
|
52 | + ->method('setStatus') |
|
53 | + ->with(200); |
|
54 | + |
|
55 | + $this->assertSame(false, $this->dummyGetResponsePlugin->httpGet($request, $response)); |
|
56 | + } |
|
57 | 57 | } |
@@ -28,222 +28,222 @@ |
||
28 | 28 | * @package OCA\DAV\Tests\Unit\Connector\Sabre |
29 | 29 | */ |
30 | 30 | class ObjectTreeTest extends \Test\TestCase { |
31 | - public static function copyDataProvider(): array { |
|
32 | - return [ |
|
33 | - // copy into same dir |
|
34 | - ['a', 'b', ''], |
|
35 | - // copy into same dir |
|
36 | - ['a/a', 'a/b', 'a'], |
|
37 | - // copy into another dir |
|
38 | - ['a', 'sub/a', 'sub'], |
|
39 | - ]; |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * @dataProvider copyDataProvider |
|
44 | - */ |
|
45 | - public function testCopy(string $sourcePath, string $targetPath, string $targetParent): void { |
|
46 | - $view = $this->createMock(View::class); |
|
47 | - $view->expects($this->once()) |
|
48 | - ->method('verifyPath') |
|
49 | - ->with($targetParent); |
|
50 | - $view->expects($this->once()) |
|
51 | - ->method('file_exists') |
|
52 | - ->with($targetPath) |
|
53 | - ->willReturn(false); |
|
54 | - $view->expects($this->once()) |
|
55 | - ->method('copy') |
|
56 | - ->with($sourcePath, $targetPath) |
|
57 | - ->willReturn(true); |
|
58 | - |
|
59 | - $info = $this->createMock(FileInfo::class); |
|
60 | - $info->expects($this->once()) |
|
61 | - ->method('isCreatable') |
|
62 | - ->willReturn(true); |
|
63 | - |
|
64 | - $view->expects($this->once()) |
|
65 | - ->method('getFileInfo') |
|
66 | - ->with($targetParent === '' ? '.' : $targetParent) |
|
67 | - ->willReturn($info); |
|
68 | - |
|
69 | - $rootDir = new Directory($view, $info); |
|
70 | - $objectTree = $this->getMockBuilder(ObjectTree::class) |
|
71 | - ->onlyMethods(['nodeExists', 'getNodeForPath']) |
|
72 | - ->setConstructorArgs([$rootDir, $view]) |
|
73 | - ->getMock(); |
|
74 | - |
|
75 | - $objectTree->expects($this->once()) |
|
76 | - ->method('getNodeForPath') |
|
77 | - ->with($this->identicalTo($sourcePath)) |
|
78 | - ->willReturn(false); |
|
79 | - |
|
80 | - /** @var ObjectTree $objectTree */ |
|
81 | - $mountManager = Filesystem::getMountManager(); |
|
82 | - $objectTree->init($rootDir, $view, $mountManager); |
|
83 | - $objectTree->copy($sourcePath, $targetPath); |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * @dataProvider copyDataProvider |
|
88 | - */ |
|
89 | - public function testCopyFailNotCreatable($sourcePath, $targetPath, $targetParent): void { |
|
90 | - $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
91 | - |
|
92 | - $view = $this->createMock(View::class); |
|
93 | - $view->expects($this->never()) |
|
94 | - ->method('verifyPath'); |
|
95 | - $view->expects($this->once()) |
|
96 | - ->method('file_exists') |
|
97 | - ->with($targetPath) |
|
98 | - ->willReturn(false); |
|
99 | - $view->expects($this->never()) |
|
100 | - ->method('copy'); |
|
101 | - |
|
102 | - $info = $this->createMock(FileInfo::class); |
|
103 | - $info->expects($this->once()) |
|
104 | - ->method('isCreatable') |
|
105 | - ->willReturn(false); |
|
106 | - |
|
107 | - $view->expects($this->once()) |
|
108 | - ->method('getFileInfo') |
|
109 | - ->with($targetParent === '' ? '.' : $targetParent) |
|
110 | - ->willReturn($info); |
|
111 | - |
|
112 | - $rootDir = new Directory($view, $info); |
|
113 | - $objectTree = $this->getMockBuilder(ObjectTree::class) |
|
114 | - ->onlyMethods(['nodeExists', 'getNodeForPath']) |
|
115 | - ->setConstructorArgs([$rootDir, $view]) |
|
116 | - ->getMock(); |
|
117 | - |
|
118 | - $objectTree->expects($this->never()) |
|
119 | - ->method('getNodeForPath'); |
|
120 | - |
|
121 | - /** @var ObjectTree $objectTree */ |
|
122 | - $mountManager = Filesystem::getMountManager(); |
|
123 | - $objectTree->init($rootDir, $view, $mountManager); |
|
124 | - $objectTree->copy($sourcePath, $targetPath); |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * @dataProvider nodeForPathProvider |
|
129 | - */ |
|
130 | - public function testGetNodeForPath( |
|
131 | - string $inputFileName, |
|
132 | - string $fileInfoQueryPath, |
|
133 | - string $outputFileName, |
|
134 | - string $type, |
|
135 | - ): void { |
|
136 | - $rootNode = $this->createMock(Directory::class); |
|
137 | - $mountManager = $this->createMock(Manager::class); |
|
138 | - $view = $this->createMock(View::class); |
|
139 | - $fileInfo = $this->createMock(FileInfo::class); |
|
140 | - $fileInfo->method('getType') |
|
141 | - ->willReturn($type); |
|
142 | - $fileInfo->method('getName') |
|
143 | - ->willReturn($outputFileName); |
|
144 | - $fileInfo->method('getStorage') |
|
145 | - ->willReturn($this->createMock(Common::class)); |
|
146 | - |
|
147 | - $view->method('getFileInfo') |
|
148 | - ->with($fileInfoQueryPath) |
|
149 | - ->willReturn($fileInfo); |
|
150 | - |
|
151 | - $tree = new ObjectTree(); |
|
152 | - $tree->init($rootNode, $view, $mountManager); |
|
153 | - |
|
154 | - $node = $tree->getNodeForPath($inputFileName); |
|
155 | - |
|
156 | - $this->assertNotNull($node); |
|
157 | - $this->assertEquals($outputFileName, $node->getName()); |
|
158 | - |
|
159 | - if ($type === 'file') { |
|
160 | - $this->assertInstanceOf(File::class, $node); |
|
161 | - } else { |
|
162 | - $this->assertInstanceOf(Directory::class, $node); |
|
163 | - } |
|
164 | - } |
|
165 | - |
|
166 | - public static function nodeForPathProvider(): array { |
|
167 | - return [ |
|
168 | - // regular file |
|
169 | - [ |
|
170 | - 'regularfile.txt', |
|
171 | - 'regularfile.txt', |
|
172 | - 'regularfile.txt', |
|
173 | - 'file', |
|
174 | - ], |
|
175 | - // regular directory |
|
176 | - [ |
|
177 | - 'regulardir', |
|
178 | - 'regulardir', |
|
179 | - 'regulardir', |
|
180 | - 'dir', |
|
181 | - ], |
|
182 | - // regular file in subdir |
|
183 | - [ |
|
184 | - 'subdir/regularfile.txt', |
|
185 | - 'subdir/regularfile.txt', |
|
186 | - 'regularfile.txt', |
|
187 | - 'file', |
|
188 | - ], |
|
189 | - // regular directory in subdir |
|
190 | - [ |
|
191 | - 'subdir/regulardir', |
|
192 | - 'subdir/regulardir', |
|
193 | - 'regulardir', |
|
194 | - 'dir', |
|
195 | - ], |
|
196 | - ]; |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - public function testGetNodeForPathInvalidPath(): void { |
|
201 | - $this->expectException(InvalidPath::class); |
|
202 | - |
|
203 | - $path = '/foo\bar'; |
|
204 | - |
|
205 | - |
|
206 | - $storage = new Temporary([]); |
|
207 | - |
|
208 | - $view = $this->getMockBuilder(View::class) |
|
209 | - ->onlyMethods(['resolvePath']) |
|
210 | - ->getMock(); |
|
211 | - $view->expects($this->once()) |
|
212 | - ->method('resolvePath') |
|
213 | - ->willReturnCallback(function ($path) use ($storage) { |
|
214 | - return [$storage, ltrim($path, '/')]; |
|
215 | - }); |
|
216 | - |
|
217 | - $rootNode = $this->createMock(Directory::class); |
|
218 | - $mountManager = $this->createMock(IMountManager::class); |
|
219 | - |
|
220 | - $tree = new ObjectTree(); |
|
221 | - $tree->init($rootNode, $view, $mountManager); |
|
222 | - |
|
223 | - $tree->getNodeForPath($path); |
|
224 | - } |
|
225 | - |
|
226 | - public function testGetNodeForPathRoot(): void { |
|
227 | - $path = '/'; |
|
228 | - |
|
229 | - |
|
230 | - $storage = new Temporary([]); |
|
231 | - |
|
232 | - $view = $this->getMockBuilder(View::class) |
|
233 | - ->onlyMethods(['resolvePath']) |
|
234 | - ->getMock(); |
|
235 | - $view->expects($this->any()) |
|
236 | - ->method('resolvePath') |
|
237 | - ->willReturnCallback(function ($path) use ($storage) { |
|
238 | - return [$storage, ltrim($path, '/')]; |
|
239 | - }); |
|
240 | - |
|
241 | - $rootNode = $this->createMock(Directory::class); |
|
242 | - $mountManager = $this->createMock(IMountManager::class); |
|
243 | - |
|
244 | - $tree = new ObjectTree(); |
|
245 | - $tree->init($rootNode, $view, $mountManager); |
|
246 | - |
|
247 | - $this->assertInstanceOf('\Sabre\DAV\INode', $tree->getNodeForPath($path)); |
|
248 | - } |
|
31 | + public static function copyDataProvider(): array { |
|
32 | + return [ |
|
33 | + // copy into same dir |
|
34 | + ['a', 'b', ''], |
|
35 | + // copy into same dir |
|
36 | + ['a/a', 'a/b', 'a'], |
|
37 | + // copy into another dir |
|
38 | + ['a', 'sub/a', 'sub'], |
|
39 | + ]; |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * @dataProvider copyDataProvider |
|
44 | + */ |
|
45 | + public function testCopy(string $sourcePath, string $targetPath, string $targetParent): void { |
|
46 | + $view = $this->createMock(View::class); |
|
47 | + $view->expects($this->once()) |
|
48 | + ->method('verifyPath') |
|
49 | + ->with($targetParent); |
|
50 | + $view->expects($this->once()) |
|
51 | + ->method('file_exists') |
|
52 | + ->with($targetPath) |
|
53 | + ->willReturn(false); |
|
54 | + $view->expects($this->once()) |
|
55 | + ->method('copy') |
|
56 | + ->with($sourcePath, $targetPath) |
|
57 | + ->willReturn(true); |
|
58 | + |
|
59 | + $info = $this->createMock(FileInfo::class); |
|
60 | + $info->expects($this->once()) |
|
61 | + ->method('isCreatable') |
|
62 | + ->willReturn(true); |
|
63 | + |
|
64 | + $view->expects($this->once()) |
|
65 | + ->method('getFileInfo') |
|
66 | + ->with($targetParent === '' ? '.' : $targetParent) |
|
67 | + ->willReturn($info); |
|
68 | + |
|
69 | + $rootDir = new Directory($view, $info); |
|
70 | + $objectTree = $this->getMockBuilder(ObjectTree::class) |
|
71 | + ->onlyMethods(['nodeExists', 'getNodeForPath']) |
|
72 | + ->setConstructorArgs([$rootDir, $view]) |
|
73 | + ->getMock(); |
|
74 | + |
|
75 | + $objectTree->expects($this->once()) |
|
76 | + ->method('getNodeForPath') |
|
77 | + ->with($this->identicalTo($sourcePath)) |
|
78 | + ->willReturn(false); |
|
79 | + |
|
80 | + /** @var ObjectTree $objectTree */ |
|
81 | + $mountManager = Filesystem::getMountManager(); |
|
82 | + $objectTree->init($rootDir, $view, $mountManager); |
|
83 | + $objectTree->copy($sourcePath, $targetPath); |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * @dataProvider copyDataProvider |
|
88 | + */ |
|
89 | + public function testCopyFailNotCreatable($sourcePath, $targetPath, $targetParent): void { |
|
90 | + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
91 | + |
|
92 | + $view = $this->createMock(View::class); |
|
93 | + $view->expects($this->never()) |
|
94 | + ->method('verifyPath'); |
|
95 | + $view->expects($this->once()) |
|
96 | + ->method('file_exists') |
|
97 | + ->with($targetPath) |
|
98 | + ->willReturn(false); |
|
99 | + $view->expects($this->never()) |
|
100 | + ->method('copy'); |
|
101 | + |
|
102 | + $info = $this->createMock(FileInfo::class); |
|
103 | + $info->expects($this->once()) |
|
104 | + ->method('isCreatable') |
|
105 | + ->willReturn(false); |
|
106 | + |
|
107 | + $view->expects($this->once()) |
|
108 | + ->method('getFileInfo') |
|
109 | + ->with($targetParent === '' ? '.' : $targetParent) |
|
110 | + ->willReturn($info); |
|
111 | + |
|
112 | + $rootDir = new Directory($view, $info); |
|
113 | + $objectTree = $this->getMockBuilder(ObjectTree::class) |
|
114 | + ->onlyMethods(['nodeExists', 'getNodeForPath']) |
|
115 | + ->setConstructorArgs([$rootDir, $view]) |
|
116 | + ->getMock(); |
|
117 | + |
|
118 | + $objectTree->expects($this->never()) |
|
119 | + ->method('getNodeForPath'); |
|
120 | + |
|
121 | + /** @var ObjectTree $objectTree */ |
|
122 | + $mountManager = Filesystem::getMountManager(); |
|
123 | + $objectTree->init($rootDir, $view, $mountManager); |
|
124 | + $objectTree->copy($sourcePath, $targetPath); |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * @dataProvider nodeForPathProvider |
|
129 | + */ |
|
130 | + public function testGetNodeForPath( |
|
131 | + string $inputFileName, |
|
132 | + string $fileInfoQueryPath, |
|
133 | + string $outputFileName, |
|
134 | + string $type, |
|
135 | + ): void { |
|
136 | + $rootNode = $this->createMock(Directory::class); |
|
137 | + $mountManager = $this->createMock(Manager::class); |
|
138 | + $view = $this->createMock(View::class); |
|
139 | + $fileInfo = $this->createMock(FileInfo::class); |
|
140 | + $fileInfo->method('getType') |
|
141 | + ->willReturn($type); |
|
142 | + $fileInfo->method('getName') |
|
143 | + ->willReturn($outputFileName); |
|
144 | + $fileInfo->method('getStorage') |
|
145 | + ->willReturn($this->createMock(Common::class)); |
|
146 | + |
|
147 | + $view->method('getFileInfo') |
|
148 | + ->with($fileInfoQueryPath) |
|
149 | + ->willReturn($fileInfo); |
|
150 | + |
|
151 | + $tree = new ObjectTree(); |
|
152 | + $tree->init($rootNode, $view, $mountManager); |
|
153 | + |
|
154 | + $node = $tree->getNodeForPath($inputFileName); |
|
155 | + |
|
156 | + $this->assertNotNull($node); |
|
157 | + $this->assertEquals($outputFileName, $node->getName()); |
|
158 | + |
|
159 | + if ($type === 'file') { |
|
160 | + $this->assertInstanceOf(File::class, $node); |
|
161 | + } else { |
|
162 | + $this->assertInstanceOf(Directory::class, $node); |
|
163 | + } |
|
164 | + } |
|
165 | + |
|
166 | + public static function nodeForPathProvider(): array { |
|
167 | + return [ |
|
168 | + // regular file |
|
169 | + [ |
|
170 | + 'regularfile.txt', |
|
171 | + 'regularfile.txt', |
|
172 | + 'regularfile.txt', |
|
173 | + 'file', |
|
174 | + ], |
|
175 | + // regular directory |
|
176 | + [ |
|
177 | + 'regulardir', |
|
178 | + 'regulardir', |
|
179 | + 'regulardir', |
|
180 | + 'dir', |
|
181 | + ], |
|
182 | + // regular file in subdir |
|
183 | + [ |
|
184 | + 'subdir/regularfile.txt', |
|
185 | + 'subdir/regularfile.txt', |
|
186 | + 'regularfile.txt', |
|
187 | + 'file', |
|
188 | + ], |
|
189 | + // regular directory in subdir |
|
190 | + [ |
|
191 | + 'subdir/regulardir', |
|
192 | + 'subdir/regulardir', |
|
193 | + 'regulardir', |
|
194 | + 'dir', |
|
195 | + ], |
|
196 | + ]; |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + public function testGetNodeForPathInvalidPath(): void { |
|
201 | + $this->expectException(InvalidPath::class); |
|
202 | + |
|
203 | + $path = '/foo\bar'; |
|
204 | + |
|
205 | + |
|
206 | + $storage = new Temporary([]); |
|
207 | + |
|
208 | + $view = $this->getMockBuilder(View::class) |
|
209 | + ->onlyMethods(['resolvePath']) |
|
210 | + ->getMock(); |
|
211 | + $view->expects($this->once()) |
|
212 | + ->method('resolvePath') |
|
213 | + ->willReturnCallback(function ($path) use ($storage) { |
|
214 | + return [$storage, ltrim($path, '/')]; |
|
215 | + }); |
|
216 | + |
|
217 | + $rootNode = $this->createMock(Directory::class); |
|
218 | + $mountManager = $this->createMock(IMountManager::class); |
|
219 | + |
|
220 | + $tree = new ObjectTree(); |
|
221 | + $tree->init($rootNode, $view, $mountManager); |
|
222 | + |
|
223 | + $tree->getNodeForPath($path); |
|
224 | + } |
|
225 | + |
|
226 | + public function testGetNodeForPathRoot(): void { |
|
227 | + $path = '/'; |
|
228 | + |
|
229 | + |
|
230 | + $storage = new Temporary([]); |
|
231 | + |
|
232 | + $view = $this->getMockBuilder(View::class) |
|
233 | + ->onlyMethods(['resolvePath']) |
|
234 | + ->getMock(); |
|
235 | + $view->expects($this->any()) |
|
236 | + ->method('resolvePath') |
|
237 | + ->willReturnCallback(function ($path) use ($storage) { |
|
238 | + return [$storage, ltrim($path, '/')]; |
|
239 | + }); |
|
240 | + |
|
241 | + $rootNode = $this->createMock(Directory::class); |
|
242 | + $mountManager = $this->createMock(IMountManager::class); |
|
243 | + |
|
244 | + $tree = new ObjectTree(); |
|
245 | + $tree->init($rootNode, $view, $mountManager); |
|
246 | + |
|
247 | + $this->assertInstanceOf('\Sabre\DAV\INode', $tree->getNodeForPath($path)); |
|
248 | + } |
|
249 | 249 | } |
@@ -22,264 +22,264 @@ |
||
22 | 22 | use Sabre\DAV\Tree; |
23 | 23 | |
24 | 24 | class SharesPluginTest extends \Test\TestCase { |
25 | - public const SHARETYPES_PROPERTYNAME = SharesPlugin::SHARETYPES_PROPERTYNAME; |
|
26 | - |
|
27 | - private \Sabre\DAV\Server $server; |
|
28 | - private \Sabre\DAV\Tree&MockObject $tree; |
|
29 | - private \OCP\Share\IManager&MockObject $shareManager; |
|
30 | - private Folder&MockObject $userFolder; |
|
31 | - private SharesPlugin $plugin; |
|
32 | - |
|
33 | - protected function setUp(): void { |
|
34 | - parent::setUp(); |
|
35 | - $this->server = new \Sabre\DAV\Server(); |
|
36 | - $this->tree = $this->createMock(Tree::class); |
|
37 | - $this->shareManager = $this->createMock(IManager::class); |
|
38 | - $user = $this->createMock(IUser::class); |
|
39 | - $user->expects($this->once()) |
|
40 | - ->method('getUID') |
|
41 | - ->willReturn('user1'); |
|
42 | - $userSession = $this->createMock(IUserSession::class); |
|
43 | - $userSession->expects($this->once()) |
|
44 | - ->method('getUser') |
|
45 | - ->willReturn($user); |
|
46 | - $this->userFolder = $this->createMock(Folder::class); |
|
47 | - |
|
48 | - $this->plugin = new SharesPlugin( |
|
49 | - $this->tree, |
|
50 | - $userSession, |
|
51 | - $this->userFolder, |
|
52 | - $this->shareManager |
|
53 | - ); |
|
54 | - $this->plugin->initialize($this->server); |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @dataProvider sharesGetPropertiesDataProvider |
|
59 | - */ |
|
60 | - public function testGetProperties(array $shareTypes): void { |
|
61 | - $sabreNode = $this->createMock(Node::class); |
|
62 | - $sabreNode->expects($this->any()) |
|
63 | - ->method('getId') |
|
64 | - ->willReturn(123); |
|
65 | - $sabreNode->expects($this->any()) |
|
66 | - ->method('getPath') |
|
67 | - ->willReturn('/subdir'); |
|
68 | - |
|
69 | - // node API nodes |
|
70 | - $node = $this->createMock(Folder::class); |
|
71 | - |
|
72 | - $sabreNode->method('getNode') |
|
73 | - ->willReturn($node); |
|
74 | - |
|
75 | - $this->shareManager->expects($this->any()) |
|
76 | - ->method('getSharesBy') |
|
77 | - ->with( |
|
78 | - $this->equalTo('user1'), |
|
79 | - $this->anything(), |
|
80 | - $this->equalTo($node), |
|
81 | - $this->equalTo(false), |
|
82 | - $this->equalTo(-1) |
|
83 | - ) |
|
84 | - ->willReturnCallback(function ($userId, $requestedShareType, $node, $flag, $limit) use ($shareTypes) { |
|
85 | - if (in_array($requestedShareType, $shareTypes)) { |
|
86 | - $share = $this->createMock(IShare::class); |
|
87 | - $share->method('getShareType') |
|
88 | - ->willReturn($requestedShareType); |
|
89 | - return [$share]; |
|
90 | - } |
|
91 | - return []; |
|
92 | - }); |
|
93 | - |
|
94 | - $this->shareManager->expects($this->any()) |
|
95 | - ->method('getSharedWith') |
|
96 | - ->with( |
|
97 | - $this->equalTo('user1'), |
|
98 | - $this->anything(), |
|
99 | - $this->equalTo($node), |
|
100 | - $this->equalTo(-1) |
|
101 | - ) |
|
102 | - ->willReturn([]); |
|
103 | - |
|
104 | - $propFind = new \Sabre\DAV\PropFind( |
|
105 | - '/dummyPath', |
|
106 | - [self::SHARETYPES_PROPERTYNAME], |
|
107 | - 0 |
|
108 | - ); |
|
109 | - |
|
110 | - $this->plugin->handleGetProperties( |
|
111 | - $propFind, |
|
112 | - $sabreNode |
|
113 | - ); |
|
114 | - |
|
115 | - $result = $propFind->getResultForMultiStatus(); |
|
116 | - |
|
117 | - $this->assertEmpty($result[404]); |
|
118 | - unset($result[404]); |
|
119 | - $this->assertEquals($shareTypes, $result[200][self::SHARETYPES_PROPERTYNAME]->getShareTypes()); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * @dataProvider sharesGetPropertiesDataProvider |
|
124 | - */ |
|
125 | - public function testPreloadThenGetProperties(array $shareTypes): void { |
|
126 | - $sabreNode1 = $this->createMock(File::class); |
|
127 | - $sabreNode1->method('getId') |
|
128 | - ->willReturn(111); |
|
129 | - $sabreNode2 = $this->createMock(File::class); |
|
130 | - $sabreNode2->method('getId') |
|
131 | - ->willReturn(222); |
|
132 | - $sabreNode2->method('getPath') |
|
133 | - ->willReturn('/subdir/foo'); |
|
134 | - |
|
135 | - $sabreNode = $this->createMock(Directory::class); |
|
136 | - $sabreNode->method('getId') |
|
137 | - ->willReturn(123); |
|
138 | - // never, because we use getDirectoryListing from the Node API instead |
|
139 | - $sabreNode->expects($this->never()) |
|
140 | - ->method('getChildren'); |
|
141 | - $sabreNode->expects($this->any()) |
|
142 | - ->method('getPath') |
|
143 | - ->willReturn('/subdir'); |
|
144 | - |
|
145 | - // node API nodes |
|
146 | - $node = $this->createMock(Folder::class); |
|
147 | - $node->method('getId') |
|
148 | - ->willReturn(123); |
|
149 | - $node1 = $this->createMock(\OC\Files\Node\File::class); |
|
150 | - $node1->method('getId') |
|
151 | - ->willReturn(111); |
|
152 | - $node2 = $this->createMock(\OC\Files\Node\File::class); |
|
153 | - $node2->method('getId') |
|
154 | - ->willReturn(222); |
|
155 | - |
|
156 | - $sabreNode->method('getNode') |
|
157 | - ->willReturn($node); |
|
158 | - $sabreNode1->method('getNode') |
|
159 | - ->willReturn($node1); |
|
160 | - $sabreNode2->method('getNode') |
|
161 | - ->willReturn($node2); |
|
162 | - |
|
163 | - $dummyShares = array_map(function ($type) { |
|
164 | - $share = $this->createMock(IShare::class); |
|
165 | - $share->expects($this->any()) |
|
166 | - ->method('getShareType') |
|
167 | - ->willReturn($type); |
|
168 | - return $share; |
|
169 | - }, $shareTypes); |
|
170 | - |
|
171 | - $this->shareManager->expects($this->any()) |
|
172 | - ->method('getSharesBy') |
|
173 | - ->with( |
|
174 | - $this->equalTo('user1'), |
|
175 | - $this->anything(), |
|
176 | - $this->anything(), |
|
177 | - $this->equalTo(false), |
|
178 | - $this->equalTo(-1) |
|
179 | - ) |
|
180 | - ->willReturnCallback(function ($userId, $requestedShareType, $node, $flag, $limit) use ($shareTypes, $dummyShares) { |
|
181 | - if ($node->getId() === 111 && in_array($requestedShareType, $shareTypes)) { |
|
182 | - foreach ($dummyShares as $dummyShare) { |
|
183 | - if ($dummyShare->getShareType() === $requestedShareType) { |
|
184 | - return [$dummyShare]; |
|
185 | - } |
|
186 | - } |
|
187 | - } |
|
188 | - |
|
189 | - return []; |
|
190 | - }); |
|
191 | - |
|
192 | - $this->shareManager->expects($this->any()) |
|
193 | - ->method('getSharedWith') |
|
194 | - ->with( |
|
195 | - $this->equalTo('user1'), |
|
196 | - $this->anything(), |
|
197 | - $this->equalTo($node), |
|
198 | - $this->equalTo(-1) |
|
199 | - ) |
|
200 | - ->willReturn([]); |
|
201 | - |
|
202 | - $this->shareManager->expects($this->any()) |
|
203 | - ->method('getSharesInFolder') |
|
204 | - ->with( |
|
205 | - $this->equalTo('user1'), |
|
206 | - $this->anything(), |
|
207 | - $this->equalTo(true) |
|
208 | - ) |
|
209 | - ->willReturnCallback(function ($userId, $node, $flag) use ($shareTypes, $dummyShares) { |
|
210 | - return [111 => $dummyShares]; |
|
211 | - }); |
|
212 | - |
|
213 | - // simulate sabre recursive PROPFIND traversal |
|
214 | - $propFindRoot = new \Sabre\DAV\PropFind( |
|
215 | - '/subdir', |
|
216 | - [self::SHARETYPES_PROPERTYNAME], |
|
217 | - 1 |
|
218 | - ); |
|
219 | - $propFind1 = new \Sabre\DAV\PropFind( |
|
220 | - '/subdir/test.txt', |
|
221 | - [self::SHARETYPES_PROPERTYNAME], |
|
222 | - 0 |
|
223 | - ); |
|
224 | - $propFind2 = new \Sabre\DAV\PropFind( |
|
225 | - '/subdir/test2.txt', |
|
226 | - [self::SHARETYPES_PROPERTYNAME], |
|
227 | - 0 |
|
228 | - ); |
|
229 | - |
|
230 | - $this->plugin->handleGetProperties( |
|
231 | - $propFindRoot, |
|
232 | - $sabreNode |
|
233 | - ); |
|
234 | - $this->plugin->handleGetProperties( |
|
235 | - $propFind1, |
|
236 | - $sabreNode1 |
|
237 | - ); |
|
238 | - $this->plugin->handleGetProperties( |
|
239 | - $propFind2, |
|
240 | - $sabreNode2 |
|
241 | - ); |
|
242 | - |
|
243 | - $result = $propFind1->getResultForMultiStatus(); |
|
244 | - |
|
245 | - $this->assertEmpty($result[404]); |
|
246 | - unset($result[404]); |
|
247 | - $this->assertEquals($shareTypes, $result[200][self::SHARETYPES_PROPERTYNAME]->getShareTypes()); |
|
248 | - } |
|
249 | - |
|
250 | - public static function sharesGetPropertiesDataProvider(): array { |
|
251 | - return [ |
|
252 | - [[]], |
|
253 | - [[IShare::TYPE_USER]], |
|
254 | - [[IShare::TYPE_GROUP]], |
|
255 | - [[IShare::TYPE_LINK]], |
|
256 | - [[IShare::TYPE_REMOTE]], |
|
257 | - [[IShare::TYPE_ROOM]], |
|
258 | - [[IShare::TYPE_DECK]], |
|
259 | - [[IShare::TYPE_SCIENCEMESH]], |
|
260 | - [[IShare::TYPE_USER, IShare::TYPE_GROUP]], |
|
261 | - [[IShare::TYPE_USER, IShare::TYPE_GROUP, IShare::TYPE_LINK]], |
|
262 | - [[IShare::TYPE_USER, IShare::TYPE_LINK]], |
|
263 | - [[IShare::TYPE_GROUP, IShare::TYPE_LINK]], |
|
264 | - [[IShare::TYPE_USER, IShare::TYPE_REMOTE]], |
|
265 | - ]; |
|
266 | - } |
|
267 | - |
|
268 | - public function testGetPropertiesSkipChunks(): void { |
|
269 | - $sabreNode = $this->createMock(UploadFile::class); |
|
270 | - |
|
271 | - $propFind = new \Sabre\DAV\PropFind( |
|
272 | - '/dummyPath', |
|
273 | - [self::SHARETYPES_PROPERTYNAME], |
|
274 | - 0 |
|
275 | - ); |
|
276 | - |
|
277 | - $this->plugin->handleGetProperties( |
|
278 | - $propFind, |
|
279 | - $sabreNode |
|
280 | - ); |
|
281 | - |
|
282 | - $result = $propFind->getResultForMultiStatus(); |
|
283 | - $this->assertCount(1, $result[404]); |
|
284 | - } |
|
25 | + public const SHARETYPES_PROPERTYNAME = SharesPlugin::SHARETYPES_PROPERTYNAME; |
|
26 | + |
|
27 | + private \Sabre\DAV\Server $server; |
|
28 | + private \Sabre\DAV\Tree&MockObject $tree; |
|
29 | + private \OCP\Share\IManager&MockObject $shareManager; |
|
30 | + private Folder&MockObject $userFolder; |
|
31 | + private SharesPlugin $plugin; |
|
32 | + |
|
33 | + protected function setUp(): void { |
|
34 | + parent::setUp(); |
|
35 | + $this->server = new \Sabre\DAV\Server(); |
|
36 | + $this->tree = $this->createMock(Tree::class); |
|
37 | + $this->shareManager = $this->createMock(IManager::class); |
|
38 | + $user = $this->createMock(IUser::class); |
|
39 | + $user->expects($this->once()) |
|
40 | + ->method('getUID') |
|
41 | + ->willReturn('user1'); |
|
42 | + $userSession = $this->createMock(IUserSession::class); |
|
43 | + $userSession->expects($this->once()) |
|
44 | + ->method('getUser') |
|
45 | + ->willReturn($user); |
|
46 | + $this->userFolder = $this->createMock(Folder::class); |
|
47 | + |
|
48 | + $this->plugin = new SharesPlugin( |
|
49 | + $this->tree, |
|
50 | + $userSession, |
|
51 | + $this->userFolder, |
|
52 | + $this->shareManager |
|
53 | + ); |
|
54 | + $this->plugin->initialize($this->server); |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @dataProvider sharesGetPropertiesDataProvider |
|
59 | + */ |
|
60 | + public function testGetProperties(array $shareTypes): void { |
|
61 | + $sabreNode = $this->createMock(Node::class); |
|
62 | + $sabreNode->expects($this->any()) |
|
63 | + ->method('getId') |
|
64 | + ->willReturn(123); |
|
65 | + $sabreNode->expects($this->any()) |
|
66 | + ->method('getPath') |
|
67 | + ->willReturn('/subdir'); |
|
68 | + |
|
69 | + // node API nodes |
|
70 | + $node = $this->createMock(Folder::class); |
|
71 | + |
|
72 | + $sabreNode->method('getNode') |
|
73 | + ->willReturn($node); |
|
74 | + |
|
75 | + $this->shareManager->expects($this->any()) |
|
76 | + ->method('getSharesBy') |
|
77 | + ->with( |
|
78 | + $this->equalTo('user1'), |
|
79 | + $this->anything(), |
|
80 | + $this->equalTo($node), |
|
81 | + $this->equalTo(false), |
|
82 | + $this->equalTo(-1) |
|
83 | + ) |
|
84 | + ->willReturnCallback(function ($userId, $requestedShareType, $node, $flag, $limit) use ($shareTypes) { |
|
85 | + if (in_array($requestedShareType, $shareTypes)) { |
|
86 | + $share = $this->createMock(IShare::class); |
|
87 | + $share->method('getShareType') |
|
88 | + ->willReturn($requestedShareType); |
|
89 | + return [$share]; |
|
90 | + } |
|
91 | + return []; |
|
92 | + }); |
|
93 | + |
|
94 | + $this->shareManager->expects($this->any()) |
|
95 | + ->method('getSharedWith') |
|
96 | + ->with( |
|
97 | + $this->equalTo('user1'), |
|
98 | + $this->anything(), |
|
99 | + $this->equalTo($node), |
|
100 | + $this->equalTo(-1) |
|
101 | + ) |
|
102 | + ->willReturn([]); |
|
103 | + |
|
104 | + $propFind = new \Sabre\DAV\PropFind( |
|
105 | + '/dummyPath', |
|
106 | + [self::SHARETYPES_PROPERTYNAME], |
|
107 | + 0 |
|
108 | + ); |
|
109 | + |
|
110 | + $this->plugin->handleGetProperties( |
|
111 | + $propFind, |
|
112 | + $sabreNode |
|
113 | + ); |
|
114 | + |
|
115 | + $result = $propFind->getResultForMultiStatus(); |
|
116 | + |
|
117 | + $this->assertEmpty($result[404]); |
|
118 | + unset($result[404]); |
|
119 | + $this->assertEquals($shareTypes, $result[200][self::SHARETYPES_PROPERTYNAME]->getShareTypes()); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * @dataProvider sharesGetPropertiesDataProvider |
|
124 | + */ |
|
125 | + public function testPreloadThenGetProperties(array $shareTypes): void { |
|
126 | + $sabreNode1 = $this->createMock(File::class); |
|
127 | + $sabreNode1->method('getId') |
|
128 | + ->willReturn(111); |
|
129 | + $sabreNode2 = $this->createMock(File::class); |
|
130 | + $sabreNode2->method('getId') |
|
131 | + ->willReturn(222); |
|
132 | + $sabreNode2->method('getPath') |
|
133 | + ->willReturn('/subdir/foo'); |
|
134 | + |
|
135 | + $sabreNode = $this->createMock(Directory::class); |
|
136 | + $sabreNode->method('getId') |
|
137 | + ->willReturn(123); |
|
138 | + // never, because we use getDirectoryListing from the Node API instead |
|
139 | + $sabreNode->expects($this->never()) |
|
140 | + ->method('getChildren'); |
|
141 | + $sabreNode->expects($this->any()) |
|
142 | + ->method('getPath') |
|
143 | + ->willReturn('/subdir'); |
|
144 | + |
|
145 | + // node API nodes |
|
146 | + $node = $this->createMock(Folder::class); |
|
147 | + $node->method('getId') |
|
148 | + ->willReturn(123); |
|
149 | + $node1 = $this->createMock(\OC\Files\Node\File::class); |
|
150 | + $node1->method('getId') |
|
151 | + ->willReturn(111); |
|
152 | + $node2 = $this->createMock(\OC\Files\Node\File::class); |
|
153 | + $node2->method('getId') |
|
154 | + ->willReturn(222); |
|
155 | + |
|
156 | + $sabreNode->method('getNode') |
|
157 | + ->willReturn($node); |
|
158 | + $sabreNode1->method('getNode') |
|
159 | + ->willReturn($node1); |
|
160 | + $sabreNode2->method('getNode') |
|
161 | + ->willReturn($node2); |
|
162 | + |
|
163 | + $dummyShares = array_map(function ($type) { |
|
164 | + $share = $this->createMock(IShare::class); |
|
165 | + $share->expects($this->any()) |
|
166 | + ->method('getShareType') |
|
167 | + ->willReturn($type); |
|
168 | + return $share; |
|
169 | + }, $shareTypes); |
|
170 | + |
|
171 | + $this->shareManager->expects($this->any()) |
|
172 | + ->method('getSharesBy') |
|
173 | + ->with( |
|
174 | + $this->equalTo('user1'), |
|
175 | + $this->anything(), |
|
176 | + $this->anything(), |
|
177 | + $this->equalTo(false), |
|
178 | + $this->equalTo(-1) |
|
179 | + ) |
|
180 | + ->willReturnCallback(function ($userId, $requestedShareType, $node, $flag, $limit) use ($shareTypes, $dummyShares) { |
|
181 | + if ($node->getId() === 111 && in_array($requestedShareType, $shareTypes)) { |
|
182 | + foreach ($dummyShares as $dummyShare) { |
|
183 | + if ($dummyShare->getShareType() === $requestedShareType) { |
|
184 | + return [$dummyShare]; |
|
185 | + } |
|
186 | + } |
|
187 | + } |
|
188 | + |
|
189 | + return []; |
|
190 | + }); |
|
191 | + |
|
192 | + $this->shareManager->expects($this->any()) |
|
193 | + ->method('getSharedWith') |
|
194 | + ->with( |
|
195 | + $this->equalTo('user1'), |
|
196 | + $this->anything(), |
|
197 | + $this->equalTo($node), |
|
198 | + $this->equalTo(-1) |
|
199 | + ) |
|
200 | + ->willReturn([]); |
|
201 | + |
|
202 | + $this->shareManager->expects($this->any()) |
|
203 | + ->method('getSharesInFolder') |
|
204 | + ->with( |
|
205 | + $this->equalTo('user1'), |
|
206 | + $this->anything(), |
|
207 | + $this->equalTo(true) |
|
208 | + ) |
|
209 | + ->willReturnCallback(function ($userId, $node, $flag) use ($shareTypes, $dummyShares) { |
|
210 | + return [111 => $dummyShares]; |
|
211 | + }); |
|
212 | + |
|
213 | + // simulate sabre recursive PROPFIND traversal |
|
214 | + $propFindRoot = new \Sabre\DAV\PropFind( |
|
215 | + '/subdir', |
|
216 | + [self::SHARETYPES_PROPERTYNAME], |
|
217 | + 1 |
|
218 | + ); |
|
219 | + $propFind1 = new \Sabre\DAV\PropFind( |
|
220 | + '/subdir/test.txt', |
|
221 | + [self::SHARETYPES_PROPERTYNAME], |
|
222 | + 0 |
|
223 | + ); |
|
224 | + $propFind2 = new \Sabre\DAV\PropFind( |
|
225 | + '/subdir/test2.txt', |
|
226 | + [self::SHARETYPES_PROPERTYNAME], |
|
227 | + 0 |
|
228 | + ); |
|
229 | + |
|
230 | + $this->plugin->handleGetProperties( |
|
231 | + $propFindRoot, |
|
232 | + $sabreNode |
|
233 | + ); |
|
234 | + $this->plugin->handleGetProperties( |
|
235 | + $propFind1, |
|
236 | + $sabreNode1 |
|
237 | + ); |
|
238 | + $this->plugin->handleGetProperties( |
|
239 | + $propFind2, |
|
240 | + $sabreNode2 |
|
241 | + ); |
|
242 | + |
|
243 | + $result = $propFind1->getResultForMultiStatus(); |
|
244 | + |
|
245 | + $this->assertEmpty($result[404]); |
|
246 | + unset($result[404]); |
|
247 | + $this->assertEquals($shareTypes, $result[200][self::SHARETYPES_PROPERTYNAME]->getShareTypes()); |
|
248 | + } |
|
249 | + |
|
250 | + public static function sharesGetPropertiesDataProvider(): array { |
|
251 | + return [ |
|
252 | + [[]], |
|
253 | + [[IShare::TYPE_USER]], |
|
254 | + [[IShare::TYPE_GROUP]], |
|
255 | + [[IShare::TYPE_LINK]], |
|
256 | + [[IShare::TYPE_REMOTE]], |
|
257 | + [[IShare::TYPE_ROOM]], |
|
258 | + [[IShare::TYPE_DECK]], |
|
259 | + [[IShare::TYPE_SCIENCEMESH]], |
|
260 | + [[IShare::TYPE_USER, IShare::TYPE_GROUP]], |
|
261 | + [[IShare::TYPE_USER, IShare::TYPE_GROUP, IShare::TYPE_LINK]], |
|
262 | + [[IShare::TYPE_USER, IShare::TYPE_LINK]], |
|
263 | + [[IShare::TYPE_GROUP, IShare::TYPE_LINK]], |
|
264 | + [[IShare::TYPE_USER, IShare::TYPE_REMOTE]], |
|
265 | + ]; |
|
266 | + } |
|
267 | + |
|
268 | + public function testGetPropertiesSkipChunks(): void { |
|
269 | + $sabreNode = $this->createMock(UploadFile::class); |
|
270 | + |
|
271 | + $propFind = new \Sabre\DAV\PropFind( |
|
272 | + '/dummyPath', |
|
273 | + [self::SHARETYPES_PROPERTYNAME], |
|
274 | + 0 |
|
275 | + ); |
|
276 | + |
|
277 | + $this->plugin->handleGetProperties( |
|
278 | + $propFind, |
|
279 | + $sabreNode |
|
280 | + ); |
|
281 | + |
|
282 | + $result = $propFind->getResultForMultiStatus(); |
|
283 | + $this->assertCount(1, $result[404]); |
|
284 | + } |
|
285 | 285 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | $this->equalTo(false), |
82 | 82 | $this->equalTo(-1) |
83 | 83 | ) |
84 | - ->willReturnCallback(function ($userId, $requestedShareType, $node, $flag, $limit) use ($shareTypes) { |
|
84 | + ->willReturnCallback(function($userId, $requestedShareType, $node, $flag, $limit) use ($shareTypes) { |
|
85 | 85 | if (in_array($requestedShareType, $shareTypes)) { |
86 | 86 | $share = $this->createMock(IShare::class); |
87 | 87 | $share->method('getShareType') |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | $sabreNode2->method('getNode') |
161 | 161 | ->willReturn($node2); |
162 | 162 | |
163 | - $dummyShares = array_map(function ($type) { |
|
163 | + $dummyShares = array_map(function($type) { |
|
164 | 164 | $share = $this->createMock(IShare::class); |
165 | 165 | $share->expects($this->any()) |
166 | 166 | ->method('getShareType') |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | $this->equalTo(false), |
178 | 178 | $this->equalTo(-1) |
179 | 179 | ) |
180 | - ->willReturnCallback(function ($userId, $requestedShareType, $node, $flag, $limit) use ($shareTypes, $dummyShares) { |
|
180 | + ->willReturnCallback(function($userId, $requestedShareType, $node, $flag, $limit) use ($shareTypes, $dummyShares) { |
|
181 | 181 | if ($node->getId() === 111 && in_array($requestedShareType, $shareTypes)) { |
182 | 182 | foreach ($dummyShares as $dummyShare) { |
183 | 183 | if ($dummyShare->getShareType() === $requestedShareType) { |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | $this->anything(), |
207 | 207 | $this->equalTo(true) |
208 | 208 | ) |
209 | - ->willReturnCallback(function ($userId, $node, $flag) use ($shareTypes, $dummyShares) { |
|
209 | + ->willReturnCallback(function($userId, $node, $flag) use ($shareTypes, $dummyShares) { |
|
210 | 210 | return [111 => $dummyShares]; |
211 | 211 | }); |
212 | 212 |
@@ -23,140 +23,140 @@ |
||
23 | 23 | * @package OCA\DAV\Tests\unit\Connector\Sabre |
24 | 24 | */ |
25 | 25 | class FakeLockerPluginTest extends TestCase { |
26 | - private FakeLockerPlugin $fakeLockerPlugin; |
|
27 | - |
|
28 | - protected function setUp(): void { |
|
29 | - parent::setUp(); |
|
30 | - $this->fakeLockerPlugin = new FakeLockerPlugin(); |
|
31 | - } |
|
32 | - |
|
33 | - public function testInitialize(): void { |
|
34 | - /** @var Server $server */ |
|
35 | - $server = $this->createMock(Server::class); |
|
36 | - $calls = [ |
|
37 | - ['method:LOCK', [$this->fakeLockerPlugin, 'fakeLockProvider'], 1], |
|
38 | - ['method:UNLOCK', [$this->fakeLockerPlugin, 'fakeUnlockProvider'], 1], |
|
39 | - ['propFind', [$this->fakeLockerPlugin, 'propFind'], 100], |
|
40 | - ['validateTokens', [$this->fakeLockerPlugin, 'validateTokens'], 100], |
|
41 | - ]; |
|
42 | - $server->expects($this->exactly(count($calls))) |
|
43 | - ->method('on') |
|
44 | - ->willReturnCallback(function () use (&$calls) { |
|
45 | - $expected = array_shift($calls); |
|
46 | - $this->assertEquals($expected, func_get_args()); |
|
47 | - }); |
|
48 | - |
|
49 | - $this->fakeLockerPlugin->initialize($server); |
|
50 | - } |
|
51 | - |
|
52 | - public function testGetHTTPMethods(): void { |
|
53 | - $expected = [ |
|
54 | - 'LOCK', |
|
55 | - 'UNLOCK', |
|
56 | - ]; |
|
57 | - $this->assertSame($expected, $this->fakeLockerPlugin->getHTTPMethods('Test')); |
|
58 | - } |
|
59 | - |
|
60 | - public function testGetFeatures(): void { |
|
61 | - $expected = [ |
|
62 | - 2, |
|
63 | - ]; |
|
64 | - $this->assertSame($expected, $this->fakeLockerPlugin->getFeatures()); |
|
65 | - } |
|
66 | - |
|
67 | - public function testPropFind(): void { |
|
68 | - $propFind = $this->createMock(PropFind::class); |
|
69 | - $node = $this->createMock(INode::class); |
|
70 | - |
|
71 | - $calls = [ |
|
72 | - '{DAV:}supportedlock', |
|
73 | - '{DAV:}lockdiscovery', |
|
74 | - ]; |
|
75 | - $propFind->expects($this->exactly(count($calls))) |
|
76 | - ->method('handle') |
|
77 | - ->willReturnCallback(function ($propertyName) use (&$calls) { |
|
78 | - $expected = array_shift($calls); |
|
79 | - $this->assertEquals($expected, $propertyName); |
|
80 | - }); |
|
81 | - |
|
82 | - $this->fakeLockerPlugin->propFind($propFind, $node); |
|
83 | - } |
|
84 | - |
|
85 | - public static function tokenDataProvider(): array { |
|
86 | - return [ |
|
87 | - [ |
|
88 | - [ |
|
89 | - [ |
|
90 | - 'tokens' => [ |
|
91 | - [ |
|
92 | - 'token' => 'aToken', |
|
93 | - 'validToken' => false, |
|
94 | - ], |
|
95 | - [], |
|
96 | - [ |
|
97 | - 'token' => 'opaquelocktoken:asdf', |
|
98 | - 'validToken' => false, |
|
99 | - ] |
|
100 | - ], |
|
101 | - ] |
|
102 | - ], |
|
103 | - [ |
|
104 | - [ |
|
105 | - 'tokens' => [ |
|
106 | - [ |
|
107 | - 'token' => 'aToken', |
|
108 | - 'validToken' => false, |
|
109 | - ], |
|
110 | - [], |
|
111 | - [ |
|
112 | - 'token' => 'opaquelocktoken:asdf', |
|
113 | - 'validToken' => true, |
|
114 | - ] |
|
115 | - ], |
|
116 | - ] |
|
117 | - ], |
|
118 | - ] |
|
119 | - ]; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * @dataProvider tokenDataProvider |
|
124 | - */ |
|
125 | - public function testValidateTokens(array $input, array $expected): void { |
|
126 | - $request = $this->createMock(RequestInterface::class); |
|
127 | - $this->fakeLockerPlugin->validateTokens($request, $input); |
|
128 | - $this->assertSame($expected, $input); |
|
129 | - } |
|
130 | - |
|
131 | - public function testFakeLockProvider(): void { |
|
132 | - $request = $this->createMock(RequestInterface::class); |
|
133 | - $response = new Response(); |
|
134 | - $server = $this->getMockBuilder(Server::class) |
|
135 | - ->getMock(); |
|
136 | - $this->fakeLockerPlugin->initialize($server); |
|
137 | - |
|
138 | - $request->expects($this->exactly(2)) |
|
139 | - ->method('getPath') |
|
140 | - ->willReturn('MyPath'); |
|
141 | - |
|
142 | - $this->assertSame(false, $this->fakeLockerPlugin->fakeLockProvider($request, $response)); |
|
143 | - |
|
144 | - $expectedXml = '<?xml version="1.0" encoding="utf-8"?><d:prop xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns"><d:lockdiscovery><d:activelock><d:lockscope><d:exclusive/></d:lockscope><d:locktype><d:write/></d:locktype><d:lockroot><d:href>MyPath</d:href></d:lockroot><d:depth>infinity</d:depth><d:timeout>Second-1800</d:timeout><d:locktoken><d:href>opaquelocktoken:fe4f7f2437b151fbcb4e9f5c8118c6b1</d:href></d:locktoken></d:activelock></d:lockdiscovery></d:prop>'; |
|
145 | - |
|
146 | - $this->assertXmlStringEqualsXmlString($expectedXml, $response->getBody()); |
|
147 | - } |
|
148 | - |
|
149 | - public function testFakeUnlockProvider(): void { |
|
150 | - $request = $this->createMock(RequestInterface::class); |
|
151 | - $response = $this->createMock(ResponseInterface::class); |
|
152 | - |
|
153 | - $response->expects($this->once()) |
|
154 | - ->method('setStatus') |
|
155 | - ->with('204'); |
|
156 | - $response->expects($this->once()) |
|
157 | - ->method('setHeader') |
|
158 | - ->with('Content-Length', '0'); |
|
159 | - |
|
160 | - $this->assertSame(false, $this->fakeLockerPlugin->fakeUnlockProvider($request, $response)); |
|
161 | - } |
|
26 | + private FakeLockerPlugin $fakeLockerPlugin; |
|
27 | + |
|
28 | + protected function setUp(): void { |
|
29 | + parent::setUp(); |
|
30 | + $this->fakeLockerPlugin = new FakeLockerPlugin(); |
|
31 | + } |
|
32 | + |
|
33 | + public function testInitialize(): void { |
|
34 | + /** @var Server $server */ |
|
35 | + $server = $this->createMock(Server::class); |
|
36 | + $calls = [ |
|
37 | + ['method:LOCK', [$this->fakeLockerPlugin, 'fakeLockProvider'], 1], |
|
38 | + ['method:UNLOCK', [$this->fakeLockerPlugin, 'fakeUnlockProvider'], 1], |
|
39 | + ['propFind', [$this->fakeLockerPlugin, 'propFind'], 100], |
|
40 | + ['validateTokens', [$this->fakeLockerPlugin, 'validateTokens'], 100], |
|
41 | + ]; |
|
42 | + $server->expects($this->exactly(count($calls))) |
|
43 | + ->method('on') |
|
44 | + ->willReturnCallback(function () use (&$calls) { |
|
45 | + $expected = array_shift($calls); |
|
46 | + $this->assertEquals($expected, func_get_args()); |
|
47 | + }); |
|
48 | + |
|
49 | + $this->fakeLockerPlugin->initialize($server); |
|
50 | + } |
|
51 | + |
|
52 | + public function testGetHTTPMethods(): void { |
|
53 | + $expected = [ |
|
54 | + 'LOCK', |
|
55 | + 'UNLOCK', |
|
56 | + ]; |
|
57 | + $this->assertSame($expected, $this->fakeLockerPlugin->getHTTPMethods('Test')); |
|
58 | + } |
|
59 | + |
|
60 | + public function testGetFeatures(): void { |
|
61 | + $expected = [ |
|
62 | + 2, |
|
63 | + ]; |
|
64 | + $this->assertSame($expected, $this->fakeLockerPlugin->getFeatures()); |
|
65 | + } |
|
66 | + |
|
67 | + public function testPropFind(): void { |
|
68 | + $propFind = $this->createMock(PropFind::class); |
|
69 | + $node = $this->createMock(INode::class); |
|
70 | + |
|
71 | + $calls = [ |
|
72 | + '{DAV:}supportedlock', |
|
73 | + '{DAV:}lockdiscovery', |
|
74 | + ]; |
|
75 | + $propFind->expects($this->exactly(count($calls))) |
|
76 | + ->method('handle') |
|
77 | + ->willReturnCallback(function ($propertyName) use (&$calls) { |
|
78 | + $expected = array_shift($calls); |
|
79 | + $this->assertEquals($expected, $propertyName); |
|
80 | + }); |
|
81 | + |
|
82 | + $this->fakeLockerPlugin->propFind($propFind, $node); |
|
83 | + } |
|
84 | + |
|
85 | + public static function tokenDataProvider(): array { |
|
86 | + return [ |
|
87 | + [ |
|
88 | + [ |
|
89 | + [ |
|
90 | + 'tokens' => [ |
|
91 | + [ |
|
92 | + 'token' => 'aToken', |
|
93 | + 'validToken' => false, |
|
94 | + ], |
|
95 | + [], |
|
96 | + [ |
|
97 | + 'token' => 'opaquelocktoken:asdf', |
|
98 | + 'validToken' => false, |
|
99 | + ] |
|
100 | + ], |
|
101 | + ] |
|
102 | + ], |
|
103 | + [ |
|
104 | + [ |
|
105 | + 'tokens' => [ |
|
106 | + [ |
|
107 | + 'token' => 'aToken', |
|
108 | + 'validToken' => false, |
|
109 | + ], |
|
110 | + [], |
|
111 | + [ |
|
112 | + 'token' => 'opaquelocktoken:asdf', |
|
113 | + 'validToken' => true, |
|
114 | + ] |
|
115 | + ], |
|
116 | + ] |
|
117 | + ], |
|
118 | + ] |
|
119 | + ]; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * @dataProvider tokenDataProvider |
|
124 | + */ |
|
125 | + public function testValidateTokens(array $input, array $expected): void { |
|
126 | + $request = $this->createMock(RequestInterface::class); |
|
127 | + $this->fakeLockerPlugin->validateTokens($request, $input); |
|
128 | + $this->assertSame($expected, $input); |
|
129 | + } |
|
130 | + |
|
131 | + public function testFakeLockProvider(): void { |
|
132 | + $request = $this->createMock(RequestInterface::class); |
|
133 | + $response = new Response(); |
|
134 | + $server = $this->getMockBuilder(Server::class) |
|
135 | + ->getMock(); |
|
136 | + $this->fakeLockerPlugin->initialize($server); |
|
137 | + |
|
138 | + $request->expects($this->exactly(2)) |
|
139 | + ->method('getPath') |
|
140 | + ->willReturn('MyPath'); |
|
141 | + |
|
142 | + $this->assertSame(false, $this->fakeLockerPlugin->fakeLockProvider($request, $response)); |
|
143 | + |
|
144 | + $expectedXml = '<?xml version="1.0" encoding="utf-8"?><d:prop xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns"><d:lockdiscovery><d:activelock><d:lockscope><d:exclusive/></d:lockscope><d:locktype><d:write/></d:locktype><d:lockroot><d:href>MyPath</d:href></d:lockroot><d:depth>infinity</d:depth><d:timeout>Second-1800</d:timeout><d:locktoken><d:href>opaquelocktoken:fe4f7f2437b151fbcb4e9f5c8118c6b1</d:href></d:locktoken></d:activelock></d:lockdiscovery></d:prop>'; |
|
145 | + |
|
146 | + $this->assertXmlStringEqualsXmlString($expectedXml, $response->getBody()); |
|
147 | + } |
|
148 | + |
|
149 | + public function testFakeUnlockProvider(): void { |
|
150 | + $request = $this->createMock(RequestInterface::class); |
|
151 | + $response = $this->createMock(ResponseInterface::class); |
|
152 | + |
|
153 | + $response->expects($this->once()) |
|
154 | + ->method('setStatus') |
|
155 | + ->with('204'); |
|
156 | + $response->expects($this->once()) |
|
157 | + ->method('setHeader') |
|
158 | + ->with('Content-Length', '0'); |
|
159 | + |
|
160 | + $this->assertSame(false, $this->fakeLockerPlugin->fakeUnlockProvider($request, $response)); |
|
161 | + } |
|
162 | 162 | } |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | ]; |
42 | 42 | $server->expects($this->exactly(count($calls))) |
43 | 43 | ->method('on') |
44 | - ->willReturnCallback(function () use (&$calls) { |
|
44 | + ->willReturnCallback(function() use (&$calls) { |
|
45 | 45 | $expected = array_shift($calls); |
46 | 46 | $this->assertEquals($expected, func_get_args()); |
47 | 47 | }); |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | ]; |
75 | 75 | $propFind->expects($this->exactly(count($calls))) |
76 | 76 | ->method('handle') |
77 | - ->willReturnCallback(function ($propertyName) use (&$calls) { |
|
77 | + ->willReturnCallback(function($propertyName) use (&$calls) { |
|
78 | 78 | $expected = array_shift($calls); |
79 | 79 | $this->assertEquals($expected, $propertyName); |
80 | 80 | }); |
@@ -26,207 +26,207 @@ |
||
26 | 26 | * @package OCA\DAV\Tests\unit\Connector\Sabre |
27 | 27 | */ |
28 | 28 | class CustomPropertiesBackendTest extends \Test\TestCase { |
29 | - private \Sabre\DAV\Server $server; |
|
30 | - private \Sabre\DAV\Tree&MockObject $tree; |
|
31 | - private IUser&MockObject $user; |
|
32 | - private DefaultCalendarValidator&MockObject $defaultCalendarValidator; |
|
33 | - private CustomPropertiesBackend $plugin; |
|
34 | - |
|
35 | - protected function setUp(): void { |
|
36 | - parent::setUp(); |
|
37 | - |
|
38 | - $this->server = new \Sabre\DAV\Server(); |
|
39 | - $this->tree = $this->createMock(Tree::class); |
|
40 | - |
|
41 | - $userId = self::getUniqueID('testcustompropertiesuser'); |
|
42 | - |
|
43 | - $this->user = $this->createMock(IUser::class); |
|
44 | - $this->user->expects($this->any()) |
|
45 | - ->method('getUID') |
|
46 | - ->willReturn($userId); |
|
47 | - |
|
48 | - $this->defaultCalendarValidator = $this->createMock(DefaultCalendarValidator::class); |
|
49 | - |
|
50 | - $this->plugin = new CustomPropertiesBackend( |
|
51 | - $this->server, |
|
52 | - $this->tree, |
|
53 | - Server::get(IDBConnection::class), |
|
54 | - $this->user, |
|
55 | - $this->defaultCalendarValidator, |
|
56 | - ); |
|
57 | - } |
|
58 | - |
|
59 | - protected function tearDown(): void { |
|
60 | - $connection = Server::get(IDBConnection::class); |
|
61 | - $deleteStatement = $connection->prepare( |
|
62 | - 'DELETE FROM `*PREFIX*properties`' . |
|
63 | - ' WHERE `userid` = ?' |
|
64 | - ); |
|
65 | - $deleteStatement->execute( |
|
66 | - [ |
|
67 | - $this->user->getUID(), |
|
68 | - ] |
|
69 | - ); |
|
70 | - $deleteStatement->closeCursor(); |
|
71 | - |
|
72 | - parent::tearDown(); |
|
73 | - } |
|
74 | - |
|
75 | - private function createTestNode(string $class) { |
|
76 | - $node = $this->createMock($class); |
|
77 | - $node->expects($this->any()) |
|
78 | - ->method('getId') |
|
79 | - ->willReturn(123); |
|
80 | - |
|
81 | - $node->expects($this->any()) |
|
82 | - ->method('getPath') |
|
83 | - ->willReturn('/dummypath'); |
|
84 | - |
|
85 | - return $node; |
|
86 | - } |
|
87 | - |
|
88 | - private function applyDefaultProps($path = '/dummypath'): void { |
|
89 | - // properties to set |
|
90 | - $propPatch = new \Sabre\DAV\PropPatch([ |
|
91 | - 'customprop' => 'value1', |
|
92 | - 'customprop2' => 'value2', |
|
93 | - ]); |
|
94 | - |
|
95 | - $this->plugin->propPatch( |
|
96 | - $path, |
|
97 | - $propPatch |
|
98 | - ); |
|
99 | - |
|
100 | - $propPatch->commit(); |
|
101 | - |
|
102 | - $this->assertEmpty($propPatch->getRemainingMutations()); |
|
103 | - |
|
104 | - $result = $propPatch->getResult(); |
|
105 | - $this->assertEquals(200, $result['customprop']); |
|
106 | - $this->assertEquals(200, $result['customprop2']); |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Test that propFind on a missing file soft fails |
|
111 | - */ |
|
112 | - public function testPropFindMissingFileSoftFail(): void { |
|
113 | - $propFind = new \Sabre\DAV\PropFind( |
|
114 | - '/dummypath', |
|
115 | - [ |
|
116 | - 'customprop', |
|
117 | - 'customprop2', |
|
118 | - 'unsetprop', |
|
119 | - ], |
|
120 | - 0 |
|
121 | - ); |
|
122 | - |
|
123 | - $this->plugin->propFind( |
|
124 | - '/dummypath', |
|
125 | - $propFind |
|
126 | - ); |
|
127 | - |
|
128 | - $this->plugin->propFind( |
|
129 | - '/dummypath', |
|
130 | - $propFind |
|
131 | - ); |
|
132 | - |
|
133 | - // assert that the above didn't throw exceptions |
|
134 | - $this->assertTrue(true); |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Test setting/getting properties |
|
139 | - */ |
|
140 | - public function testSetGetPropertiesForFile(): void { |
|
141 | - $this->applyDefaultProps(); |
|
142 | - |
|
143 | - $propFind = new \Sabre\DAV\PropFind( |
|
144 | - '/dummypath', |
|
145 | - [ |
|
146 | - 'customprop', |
|
147 | - 'customprop2', |
|
148 | - 'unsetprop', |
|
149 | - ], |
|
150 | - 0 |
|
151 | - ); |
|
152 | - |
|
153 | - $this->plugin->propFind( |
|
154 | - '/dummypath', |
|
155 | - $propFind |
|
156 | - ); |
|
157 | - |
|
158 | - $this->assertEquals('value1', $propFind->get('customprop')); |
|
159 | - $this->assertEquals('value2', $propFind->get('customprop2')); |
|
160 | - $this->assertEquals(['unsetprop'], $propFind->get404Properties()); |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Test getting properties from directory |
|
165 | - */ |
|
166 | - public function testGetPropertiesForDirectory(): void { |
|
167 | - $this->applyDefaultProps('/dummypath'); |
|
168 | - $this->applyDefaultProps('/dummypath/test.txt'); |
|
169 | - |
|
170 | - $propNames = [ |
|
171 | - 'customprop', |
|
172 | - 'customprop2', |
|
173 | - 'unsetprop', |
|
174 | - ]; |
|
175 | - |
|
176 | - $propFindRoot = new \Sabre\DAV\PropFind( |
|
177 | - '/dummypath', |
|
178 | - $propNames, |
|
179 | - 1 |
|
180 | - ); |
|
181 | - |
|
182 | - $propFindSub = new \Sabre\DAV\PropFind( |
|
183 | - '/dummypath/test.txt', |
|
184 | - $propNames, |
|
185 | - 0 |
|
186 | - ); |
|
187 | - |
|
188 | - $this->plugin->propFind( |
|
189 | - '/dummypath', |
|
190 | - $propFindRoot |
|
191 | - ); |
|
192 | - |
|
193 | - $this->plugin->propFind( |
|
194 | - '/dummypath/test.txt', |
|
195 | - $propFindSub |
|
196 | - ); |
|
197 | - |
|
198 | - // TODO: find a way to assert that no additional SQL queries were |
|
199 | - // run while doing the second propFind |
|
200 | - |
|
201 | - $this->assertEquals('value1', $propFindRoot->get('customprop')); |
|
202 | - $this->assertEquals('value2', $propFindRoot->get('customprop2')); |
|
203 | - $this->assertEquals(['unsetprop'], $propFindRoot->get404Properties()); |
|
204 | - |
|
205 | - $this->assertEquals('value1', $propFindSub->get('customprop')); |
|
206 | - $this->assertEquals('value2', $propFindSub->get('customprop2')); |
|
207 | - $this->assertEquals(['unsetprop'], $propFindSub->get404Properties()); |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * Test delete property |
|
212 | - */ |
|
213 | - public function testDeleteProperty(): void { |
|
214 | - $this->applyDefaultProps(); |
|
215 | - |
|
216 | - $propPatch = new \Sabre\DAV\PropPatch([ |
|
217 | - 'customprop' => null, |
|
218 | - ]); |
|
219 | - |
|
220 | - $this->plugin->propPatch( |
|
221 | - '/dummypath', |
|
222 | - $propPatch |
|
223 | - ); |
|
224 | - |
|
225 | - $propPatch->commit(); |
|
226 | - |
|
227 | - $this->assertEmpty($propPatch->getRemainingMutations()); |
|
228 | - |
|
229 | - $result = $propPatch->getResult(); |
|
230 | - $this->assertEquals(204, $result['customprop']); |
|
231 | - } |
|
29 | + private \Sabre\DAV\Server $server; |
|
30 | + private \Sabre\DAV\Tree&MockObject $tree; |
|
31 | + private IUser&MockObject $user; |
|
32 | + private DefaultCalendarValidator&MockObject $defaultCalendarValidator; |
|
33 | + private CustomPropertiesBackend $plugin; |
|
34 | + |
|
35 | + protected function setUp(): void { |
|
36 | + parent::setUp(); |
|
37 | + |
|
38 | + $this->server = new \Sabre\DAV\Server(); |
|
39 | + $this->tree = $this->createMock(Tree::class); |
|
40 | + |
|
41 | + $userId = self::getUniqueID('testcustompropertiesuser'); |
|
42 | + |
|
43 | + $this->user = $this->createMock(IUser::class); |
|
44 | + $this->user->expects($this->any()) |
|
45 | + ->method('getUID') |
|
46 | + ->willReturn($userId); |
|
47 | + |
|
48 | + $this->defaultCalendarValidator = $this->createMock(DefaultCalendarValidator::class); |
|
49 | + |
|
50 | + $this->plugin = new CustomPropertiesBackend( |
|
51 | + $this->server, |
|
52 | + $this->tree, |
|
53 | + Server::get(IDBConnection::class), |
|
54 | + $this->user, |
|
55 | + $this->defaultCalendarValidator, |
|
56 | + ); |
|
57 | + } |
|
58 | + |
|
59 | + protected function tearDown(): void { |
|
60 | + $connection = Server::get(IDBConnection::class); |
|
61 | + $deleteStatement = $connection->prepare( |
|
62 | + 'DELETE FROM `*PREFIX*properties`' . |
|
63 | + ' WHERE `userid` = ?' |
|
64 | + ); |
|
65 | + $deleteStatement->execute( |
|
66 | + [ |
|
67 | + $this->user->getUID(), |
|
68 | + ] |
|
69 | + ); |
|
70 | + $deleteStatement->closeCursor(); |
|
71 | + |
|
72 | + parent::tearDown(); |
|
73 | + } |
|
74 | + |
|
75 | + private function createTestNode(string $class) { |
|
76 | + $node = $this->createMock($class); |
|
77 | + $node->expects($this->any()) |
|
78 | + ->method('getId') |
|
79 | + ->willReturn(123); |
|
80 | + |
|
81 | + $node->expects($this->any()) |
|
82 | + ->method('getPath') |
|
83 | + ->willReturn('/dummypath'); |
|
84 | + |
|
85 | + return $node; |
|
86 | + } |
|
87 | + |
|
88 | + private function applyDefaultProps($path = '/dummypath'): void { |
|
89 | + // properties to set |
|
90 | + $propPatch = new \Sabre\DAV\PropPatch([ |
|
91 | + 'customprop' => 'value1', |
|
92 | + 'customprop2' => 'value2', |
|
93 | + ]); |
|
94 | + |
|
95 | + $this->plugin->propPatch( |
|
96 | + $path, |
|
97 | + $propPatch |
|
98 | + ); |
|
99 | + |
|
100 | + $propPatch->commit(); |
|
101 | + |
|
102 | + $this->assertEmpty($propPatch->getRemainingMutations()); |
|
103 | + |
|
104 | + $result = $propPatch->getResult(); |
|
105 | + $this->assertEquals(200, $result['customprop']); |
|
106 | + $this->assertEquals(200, $result['customprop2']); |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Test that propFind on a missing file soft fails |
|
111 | + */ |
|
112 | + public function testPropFindMissingFileSoftFail(): void { |
|
113 | + $propFind = new \Sabre\DAV\PropFind( |
|
114 | + '/dummypath', |
|
115 | + [ |
|
116 | + 'customprop', |
|
117 | + 'customprop2', |
|
118 | + 'unsetprop', |
|
119 | + ], |
|
120 | + 0 |
|
121 | + ); |
|
122 | + |
|
123 | + $this->plugin->propFind( |
|
124 | + '/dummypath', |
|
125 | + $propFind |
|
126 | + ); |
|
127 | + |
|
128 | + $this->plugin->propFind( |
|
129 | + '/dummypath', |
|
130 | + $propFind |
|
131 | + ); |
|
132 | + |
|
133 | + // assert that the above didn't throw exceptions |
|
134 | + $this->assertTrue(true); |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Test setting/getting properties |
|
139 | + */ |
|
140 | + public function testSetGetPropertiesForFile(): void { |
|
141 | + $this->applyDefaultProps(); |
|
142 | + |
|
143 | + $propFind = new \Sabre\DAV\PropFind( |
|
144 | + '/dummypath', |
|
145 | + [ |
|
146 | + 'customprop', |
|
147 | + 'customprop2', |
|
148 | + 'unsetprop', |
|
149 | + ], |
|
150 | + 0 |
|
151 | + ); |
|
152 | + |
|
153 | + $this->plugin->propFind( |
|
154 | + '/dummypath', |
|
155 | + $propFind |
|
156 | + ); |
|
157 | + |
|
158 | + $this->assertEquals('value1', $propFind->get('customprop')); |
|
159 | + $this->assertEquals('value2', $propFind->get('customprop2')); |
|
160 | + $this->assertEquals(['unsetprop'], $propFind->get404Properties()); |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Test getting properties from directory |
|
165 | + */ |
|
166 | + public function testGetPropertiesForDirectory(): void { |
|
167 | + $this->applyDefaultProps('/dummypath'); |
|
168 | + $this->applyDefaultProps('/dummypath/test.txt'); |
|
169 | + |
|
170 | + $propNames = [ |
|
171 | + 'customprop', |
|
172 | + 'customprop2', |
|
173 | + 'unsetprop', |
|
174 | + ]; |
|
175 | + |
|
176 | + $propFindRoot = new \Sabre\DAV\PropFind( |
|
177 | + '/dummypath', |
|
178 | + $propNames, |
|
179 | + 1 |
|
180 | + ); |
|
181 | + |
|
182 | + $propFindSub = new \Sabre\DAV\PropFind( |
|
183 | + '/dummypath/test.txt', |
|
184 | + $propNames, |
|
185 | + 0 |
|
186 | + ); |
|
187 | + |
|
188 | + $this->plugin->propFind( |
|
189 | + '/dummypath', |
|
190 | + $propFindRoot |
|
191 | + ); |
|
192 | + |
|
193 | + $this->plugin->propFind( |
|
194 | + '/dummypath/test.txt', |
|
195 | + $propFindSub |
|
196 | + ); |
|
197 | + |
|
198 | + // TODO: find a way to assert that no additional SQL queries were |
|
199 | + // run while doing the second propFind |
|
200 | + |
|
201 | + $this->assertEquals('value1', $propFindRoot->get('customprop')); |
|
202 | + $this->assertEquals('value2', $propFindRoot->get('customprop2')); |
|
203 | + $this->assertEquals(['unsetprop'], $propFindRoot->get404Properties()); |
|
204 | + |
|
205 | + $this->assertEquals('value1', $propFindSub->get('customprop')); |
|
206 | + $this->assertEquals('value2', $propFindSub->get('customprop2')); |
|
207 | + $this->assertEquals(['unsetprop'], $propFindSub->get404Properties()); |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * Test delete property |
|
212 | + */ |
|
213 | + public function testDeleteProperty(): void { |
|
214 | + $this->applyDefaultProps(); |
|
215 | + |
|
216 | + $propPatch = new \Sabre\DAV\PropPatch([ |
|
217 | + 'customprop' => null, |
|
218 | + ]); |
|
219 | + |
|
220 | + $this->plugin->propPatch( |
|
221 | + '/dummypath', |
|
222 | + $propPatch |
|
223 | + ); |
|
224 | + |
|
225 | + $propPatch->commit(); |
|
226 | + |
|
227 | + $this->assertEmpty($propPatch->getRemainingMutations()); |
|
228 | + |
|
229 | + $result = $propPatch->getResult(); |
|
230 | + $this->assertEquals(204, $result['customprop']); |
|
231 | + } |
|
232 | 232 | } |