20
20
*
21
21
*/
22
22
23
- namespace Test \AppFramework \Middleware \Security ;
23
+ namespace lib \AppFramework \Middleware \Security ;
24
24
25
25
use OC \AppFramework \Http ;
26
26
use OC \AppFramework \Http \Request ;
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 ;
51
52
use OCP \ILogger ;
52
53
use OC \OCS \Result ;
53
54
54
- class SecurityMiddlewareTest extends TestCase {
55
+ class SecurityMiddlewareTest1 extends TestCase {
55
56
56
57
/** @var SecurityMiddleware */
57
58
private $ middleware ;
@@ -136,7 +137,7 @@ private function getMiddleware($isLoggedIn, $isAdminUser) {
136
137
* @PublicPage
137
138
* @NoCSRFRequired
138
139
* @throws SecurityException
139
- * @throws \ ReflectionException
140
+ * @throws ReflectionException
140
141
*/
141
142
public function testSetNavigationEntry () {
142
143
$ this ->navigationManager ->expects ($ this ->once ())
@@ -151,7 +152,7 @@ public function testSetNavigationEntry() {
151
152
* @param string $method
152
153
* @param string $test
153
154
* @param $status
154
- * @throws \ ReflectionException
155
+ * @throws ReflectionException
155
156
*/
156
157
private function ajaxExceptionStatus ($ method , $ test , $ status ) {
157
158
$ isLoggedIn = false ;
@@ -179,7 +180,7 @@ private function ajaxExceptionStatus($method, $test, $status) {
179
180
}
180
181
181
182
/**
182
- * @throws \ ReflectionException
183
+ * @throws ReflectionException
183
184
*/
184
185
public function testAjaxStatusLoggedInCheck () {
185
186
$ this ->ajaxExceptionStatus (
@@ -191,7 +192,7 @@ public function testAjaxStatusLoggedInCheck() {
191
192
192
193
/**
193
194
* @NoCSRFRequired
194
- * @throws \ ReflectionException
195
+ * @throws ReflectionException
195
196
*/
196
197
public function testAjaxNotAdminCheck () {
197
198
$ this ->ajaxExceptionStatus (
@@ -203,7 +204,7 @@ public function testAjaxNotAdminCheck() {
203
204
204
205
/**
205
206
* @PublicPage
206
- * @throws \ ReflectionException
207
+ * @throws ReflectionException
207
208
*/
208
209
public function testAjaxStatusCSRFCheck () {
209
210
$ this ->ajaxExceptionStatus (
@@ -216,10 +217,7 @@ public function testAjaxStatusCSRFCheck() {
216
217
/**
217
218
* @PublicPage
218
219
* @NoCSRFRequired
219
- * @throws \ReflectionException
220
- * @throws \ReflectionException
221
- * @throws \ReflectionException
222
- * @throws \ReflectionException
220
+ * @throws ReflectionException
223
221
*/
224
222
public function testAjaxStatusAllGood () {
225
223
$ this ->ajaxExceptionStatus (
@@ -248,7 +246,7 @@ public function testAjaxStatusAllGood() {
248
246
* @PublicPage
249
247
* @NoCSRFRequired
250
248
* @throws SecurityException
251
- * @throws \ ReflectionException
249
+ * @throws ReflectionException
252
250
*/
253
251
public function testNoChecks () {
254
252
$ this ->request ->expects ($ this ->never ())
@@ -266,7 +264,7 @@ public function testNoChecks() {
266
264
* @param string $expects
267
265
* @param bool $shouldFail
268
266
* @throws SecurityException
269
- * @throws \ ReflectionException
267
+ * @throws ReflectionException
270
268
*/
271
269
private function securityCheck ($ method , $ expects , $ shouldFail =false ) {
272
270
// admin check requires login
@@ -293,10 +291,10 @@ private function securityCheck($method, $expects, $shouldFail=false) {
293
291
/**
294
292
* @PublicPage
295
293
* @throws SecurityException
296
- * @throws \ ReflectionException
294
+ * @throws ReflectionException
297
295
*/
298
296
public function testCsrfCheck () {
299
- $ this ->expectException (\ OC \ AppFramework \ Middleware \ Security \ Exceptions \ CrossSiteRequestForgeryException::class);
297
+ $ this ->expectException (CrossSiteRequestForgeryException::class);
300
298
301
299
$ this ->request ->expects ($ this ->once ())
302
300
->method ('passesCSRFCheck ' )
@@ -310,7 +308,7 @@ public function testCsrfCheck() {
310
308
* @PublicPage
311
309
* @NoCSRFRequired
312
310
* @throws SecurityException
313
- * @throws \ ReflectionException
311
+ * @throws ReflectionException
314
312
*/
315
313
public function testNoCsrfCheck () {
316
314
$ this ->request ->expects ($ this ->never ())
@@ -324,7 +322,7 @@ public function testNoCsrfCheck() {
324
322
/**
325
323
* @PublicPage
326
324
* @throws SecurityException
327
- * @throws \ ReflectionException
325
+ * @throws ReflectionException
328
326
*/
329
327
public function testFailCsrfCheck () {
330
328
$ this ->request ->expects ($ this ->once ())
@@ -335,11 +333,29 @@ public function testFailCsrfCheck() {
335
333
$ this ->middleware ->beforeController (__CLASS__ , __FUNCTION__ );
336
334
}
337
335
336
+ /**
337
+ * @PublicPage
338
+ * @throws SecurityException
339
+ * @throws ReflectionException
340
+ */
341
+ public function testFailCsrfCheckWithoutAuthHeader (): void {
342
+ $ this ->expectException (CrossSiteRequestForgeryException::class);
343
+ $ this ->request ->expects ($ this ->once ())
344
+ ->method ('passesCSRFCheck ' )
345
+ ->willReturn (false );
346
+ $ this ->request
347
+ ->method ('getHeader ' )
348
+ ->willReturn ('' );
349
+
350
+ $ this ->reader ->reflect (__CLASS__ , __FUNCTION__ );
351
+ $ this ->middleware ->beforeController (__CLASS__ , __FUNCTION__ );
352
+ }
353
+
338
354
/**
339
355
* @NoCSRFRequired
340
356
* @NoAdminRequired
341
357
* @throws SecurityException
342
- * @throws \ ReflectionException
358
+ * @throws ReflectionException
343
359
*/
344
360
public function testLoggedInCheck () {
345
361
$ this ->securityCheck (__FUNCTION__ , 'isLoggedIn ' );
@@ -349,7 +365,7 @@ public function testLoggedInCheck() {
349
365
* @NoCSRFRequired
350
366
* @NoAdminRequired
351
367
* @throws SecurityException
352
- * @throws \ ReflectionException
368
+ * @throws ReflectionException
353
369
*/
354
370
public function testFailLoggedInCheck () {
355
371
$ this ->securityCheck (__FUNCTION__ , 'isLoggedIn ' , true );
@@ -358,7 +374,7 @@ public function testFailLoggedInCheck() {
358
374
/**
359
375
* @NoCSRFRequired
360
376
* @throws SecurityException
361
- * @throws \ ReflectionException
377
+ * @throws ReflectionException
362
378
*/
363
379
public function testIsAdminCheck () {
364
380
$ this ->securityCheck (__FUNCTION__ , 'isAdminUser ' );
@@ -367,7 +383,7 @@ public function testIsAdminCheck() {
367
383
/**
368
384
* @NoCSRFRequired
369
385
* @throws SecurityException
370
- * @throws \ ReflectionException
386
+ * @throws ReflectionException
371
387
*/
372
388
public function testFailIsAdminCheck () {
373
389
$ this ->securityCheck (__FUNCTION__ , 'isAdminUser ' , true );
0 commit comments