40
40
use OCP \ISession ;
41
41
use OCP \AppFramework \Controller ;
42
42
use OCP \IUserSession ;
43
+ use ReflectionException ;
43
44
use Test \TestCase ;
44
45
use OCP \AppFramework \Http \Response ;
45
46
use OCP \IConfig ;
@@ -135,7 +136,7 @@ private function getMiddleware($isLoggedIn, $isAdminUser) {
135
136
* @PublicPage
136
137
* @NoCSRFRequired
137
138
* @throws SecurityException
138
- * @throws \ ReflectionException
139
+ * @throws ReflectionException
139
140
*/
140
141
public function testSetNavigationEntry () {
141
142
$ this ->navigationManager ->expects ($ this ->once ())
@@ -150,7 +151,7 @@ public function testSetNavigationEntry() {
150
151
* @param string $method
151
152
* @param string $test
152
153
* @param $status
153
- * @throws \ ReflectionException
154
+ * @throws ReflectionException
154
155
*/
155
156
private function ajaxExceptionStatus ($ method , $ test , $ status ) {
156
157
$ isLoggedIn = false ;
@@ -178,7 +179,7 @@ private function ajaxExceptionStatus($method, $test, $status) {
178
179
}
179
180
180
181
/**
181
- * @throws \ ReflectionException
182
+ * @throws ReflectionException
182
183
*/
183
184
public function testAjaxStatusLoggedInCheck () {
184
185
$ this ->ajaxExceptionStatus (
@@ -190,7 +191,7 @@ public function testAjaxStatusLoggedInCheck() {
190
191
191
192
/**
192
193
* @NoCSRFRequired
193
- * @throws \ ReflectionException
194
+ * @throws ReflectionException
194
195
*/
195
196
public function testAjaxNotAdminCheck () {
196
197
$ this ->ajaxExceptionStatus (
@@ -202,7 +203,7 @@ public function testAjaxNotAdminCheck() {
202
203
203
204
/**
204
205
* @PublicPage
205
- * @throws \ ReflectionException
206
+ * @throws ReflectionException
206
207
*/
207
208
public function testAjaxStatusCSRFCheck () {
208
209
$ this ->ajaxExceptionStatus (
@@ -215,10 +216,10 @@ public function testAjaxStatusCSRFCheck() {
215
216
/**
216
217
* @PublicPage
217
218
* @NoCSRFRequired
218
- * @throws \ ReflectionException
219
- * @throws \ ReflectionException
220
- * @throws \ ReflectionException
221
- * @throws \ ReflectionException
219
+ * @throws ReflectionException
220
+ * @throws ReflectionException
221
+ * @throws ReflectionException
222
+ * @throws ReflectionException
222
223
*/
223
224
public function testAjaxStatusAllGood () {
224
225
$ this ->ajaxExceptionStatus (
@@ -247,7 +248,7 @@ public function testAjaxStatusAllGood() {
247
248
* @PublicPage
248
249
* @NoCSRFRequired
249
250
* @throws SecurityException
250
- * @throws \ ReflectionException
251
+ * @throws ReflectionException
251
252
*/
252
253
public function testNoChecks () {
253
254
$ this ->request ->expects ($ this ->never ())
@@ -265,7 +266,7 @@ public function testNoChecks() {
265
266
* @param string $expects
266
267
* @param bool $shouldFail
267
268
* @throws SecurityException
268
- * @throws \ ReflectionException
269
+ * @throws ReflectionException
269
270
*/
270
271
private function securityCheck ($ method , $ expects , $ shouldFail =false ) {
271
272
// admin check requires login
@@ -292,10 +293,10 @@ private function securityCheck($method, $expects, $shouldFail=false) {
292
293
/**
293
294
* @PublicPage
294
295
* @throws SecurityException
295
- * @throws \ ReflectionException
296
+ * @throws ReflectionException
296
297
*/
297
298
public function testCsrfCheck () {
298
- $ this ->expectException (\ OC \ AppFramework \ Middleware \ Security \ Exceptions \ CrossSiteRequestForgeryException::class);
299
+ $ this ->expectException (CrossSiteRequestForgeryException::class);
299
300
300
301
$ this ->request ->expects ($ this ->once ())
301
302
->method ('passesCSRFCheck ' )
@@ -309,7 +310,7 @@ public function testCsrfCheck() {
309
310
* @PublicPage
310
311
* @NoCSRFRequired
311
312
* @throws SecurityException
312
- * @throws \ ReflectionException
313
+ * @throws ReflectionException
313
314
*/
314
315
public function testNoCsrfCheck () {
315
316
$ this ->request ->expects ($ this ->never ())
@@ -323,7 +324,7 @@ public function testNoCsrfCheck() {
323
324
/**
324
325
* @PublicPage
325
326
* @throws SecurityException
326
- * @throws \ ReflectionException
327
+ * @throws ReflectionException
327
328
*/
328
329
public function testFailCsrfCheck () {
329
330
$ this ->request ->expects ($ this ->once ())
@@ -334,11 +335,30 @@ public function testFailCsrfCheck() {
334
335
$ this ->middleware ->beforeController (__CLASS__ , __FUNCTION__ );
335
336
}
336
337
338
+ /**
339
+ * @PublicPage
340
+ * @throws SecurityException
341
+ * @throws ReflectionException
342
+ */
343
+ public function testFailCsrfCheckWithoutAuthHeader (): void {
344
+ $ this ->expectException (CrossSiteRequestForgeryException::class);
345
+ $ this ->request ->expects ($ this ->once ())
346
+ ->method ('passesCSRFCheck ' )
347
+ ->willReturn (false );
348
+ $ this ->request ->expects ($ this ->once ())
349
+ ->method ('getHeader ' )
350
+ ->willReturn ('' );
351
+
352
+ $ this ->reader ->reflect (__CLASS__ , __FUNCTION__ );
353
+ $ this ->middleware ->beforeController (__CLASS__ , __FUNCTION__ );
354
+ }
355
+
356
+
337
357
/**
338
358
* @NoCSRFRequired
339
359
* @NoAdminRequired
340
360
* @throws SecurityException
341
- * @throws \ ReflectionException
361
+ * @throws ReflectionException
342
362
*/
343
363
public function testLoggedInCheck () {
344
364
$ this ->securityCheck (__FUNCTION__ , 'isLoggedIn ' );
@@ -348,7 +368,7 @@ public function testLoggedInCheck() {
348
368
* @NoCSRFRequired
349
369
* @NoAdminRequired
350
370
* @throws SecurityException
351
- * @throws \ ReflectionException
371
+ * @throws ReflectionException
352
372
*/
353
373
public function testFailLoggedInCheck () {
354
374
$ this ->securityCheck (__FUNCTION__ , 'isLoggedIn ' , true );
@@ -357,7 +377,7 @@ public function testFailLoggedInCheck() {
357
377
/**
358
378
* @NoCSRFRequired
359
379
* @throws SecurityException
360
- * @throws \ ReflectionException
380
+ * @throws ReflectionException
361
381
*/
362
382
public function testIsAdminCheck () {
363
383
$ this ->securityCheck (__FUNCTION__ , 'isAdminUser ' );
@@ -366,7 +386,7 @@ public function testIsAdminCheck() {
366
386
/**
367
387
* @NoCSRFRequired
368
388
* @throws SecurityException
369
- * @throws \ ReflectionException
389
+ * @throws ReflectionException
370
390
*/
371
391
public function testFailIsAdminCheck () {
372
392
$ this ->securityCheck (__FUNCTION__ , 'isAdminUser ' , true );
0 commit comments