Skip to content

Commit 0e58c58

Browse files
committed
test: add test back again
1 parent 3398ae0 commit 0e58c58

File tree

1 file changed

+37
-21
lines changed

1 file changed

+37
-21
lines changed

tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php

+37-21
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*
2121
*/
2222

23-
namespace Test\AppFramework\Middleware\Security;
23+
namespace lib\AppFramework\Middleware\Security;
2424

2525
use OC\AppFramework\Http;
2626
use OC\AppFramework\Http\Request;
@@ -40,6 +40,7 @@
4040
use OCP\ISession;
4141
use OCP\AppFramework\Controller;
4242
use OCP\IUserSession;
43+
use ReflectionException;
4344
use Test\TestCase;
4445
use OCP\AppFramework\Http\Response;
4546
use OCP\IConfig;
@@ -51,7 +52,7 @@
5152
use OCP\ILogger;
5253
use OC\OCS\Result;
5354

54-
class SecurityMiddlewareTest extends TestCase {
55+
class SecurityMiddlewareTest1 extends TestCase {
5556

5657
/** @var SecurityMiddleware */
5758
private $middleware;
@@ -136,7 +137,7 @@ private function getMiddleware($isLoggedIn, $isAdminUser) {
136137
* @PublicPage
137138
* @NoCSRFRequired
138139
* @throws SecurityException
139-
* @throws \ReflectionException
140+
* @throws ReflectionException
140141
*/
141142
public function testSetNavigationEntry() {
142143
$this->navigationManager->expects($this->once())
@@ -151,7 +152,7 @@ public function testSetNavigationEntry() {
151152
* @param string $method
152153
* @param string $test
153154
* @param $status
154-
* @throws \ReflectionException
155+
* @throws ReflectionException
155156
*/
156157
private function ajaxExceptionStatus($method, $test, $status) {
157158
$isLoggedIn = false;
@@ -179,7 +180,7 @@ private function ajaxExceptionStatus($method, $test, $status) {
179180
}
180181

181182
/**
182-
* @throws \ReflectionException
183+
* @throws ReflectionException
183184
*/
184185
public function testAjaxStatusLoggedInCheck() {
185186
$this->ajaxExceptionStatus(
@@ -191,7 +192,7 @@ public function testAjaxStatusLoggedInCheck() {
191192

192193
/**
193194
* @NoCSRFRequired
194-
* @throws \ReflectionException
195+
* @throws ReflectionException
195196
*/
196197
public function testAjaxNotAdminCheck() {
197198
$this->ajaxExceptionStatus(
@@ -203,7 +204,7 @@ public function testAjaxNotAdminCheck() {
203204

204205
/**
205206
* @PublicPage
206-
* @throws \ReflectionException
207+
* @throws ReflectionException
207208
*/
208209
public function testAjaxStatusCSRFCheck() {
209210
$this->ajaxExceptionStatus(
@@ -216,10 +217,7 @@ public function testAjaxStatusCSRFCheck() {
216217
/**
217218
* @PublicPage
218219
* @NoCSRFRequired
219-
* @throws \ReflectionException
220-
* @throws \ReflectionException
221-
* @throws \ReflectionException
222-
* @throws \ReflectionException
220+
* @throws ReflectionException
223221
*/
224222
public function testAjaxStatusAllGood() {
225223
$this->ajaxExceptionStatus(
@@ -248,7 +246,7 @@ public function testAjaxStatusAllGood() {
248246
* @PublicPage
249247
* @NoCSRFRequired
250248
* @throws SecurityException
251-
* @throws \ReflectionException
249+
* @throws ReflectionException
252250
*/
253251
public function testNoChecks() {
254252
$this->request->expects($this->never())
@@ -266,7 +264,7 @@ public function testNoChecks() {
266264
* @param string $expects
267265
* @param bool $shouldFail
268266
* @throws SecurityException
269-
* @throws \ReflectionException
267+
* @throws ReflectionException
270268
*/
271269
private function securityCheck($method, $expects, $shouldFail=false) {
272270
// admin check requires login
@@ -293,10 +291,10 @@ private function securityCheck($method, $expects, $shouldFail=false) {
293291
/**
294292
* @PublicPage
295293
* @throws SecurityException
296-
* @throws \ReflectionException
294+
* @throws ReflectionException
297295
*/
298296
public function testCsrfCheck() {
299-
$this->expectException(\OC\AppFramework\Middleware\Security\Exceptions\CrossSiteRequestForgeryException::class);
297+
$this->expectException(CrossSiteRequestForgeryException::class);
300298

301299
$this->request->expects($this->once())
302300
->method('passesCSRFCheck')
@@ -310,7 +308,7 @@ public function testCsrfCheck() {
310308
* @PublicPage
311309
* @NoCSRFRequired
312310
* @throws SecurityException
313-
* @throws \ReflectionException
311+
* @throws ReflectionException
314312
*/
315313
public function testNoCsrfCheck() {
316314
$this->request->expects($this->never())
@@ -324,7 +322,7 @@ public function testNoCsrfCheck() {
324322
/**
325323
* @PublicPage
326324
* @throws SecurityException
327-
* @throws \ReflectionException
325+
* @throws ReflectionException
328326
*/
329327
public function testFailCsrfCheck() {
330328
$this->request->expects($this->once())
@@ -335,11 +333,29 @@ public function testFailCsrfCheck() {
335333
$this->middleware->beforeController(__CLASS__, __FUNCTION__);
336334
}
337335

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+
338354
/**
339355
* @NoCSRFRequired
340356
* @NoAdminRequired
341357
* @throws SecurityException
342-
* @throws \ReflectionException
358+
* @throws ReflectionException
343359
*/
344360
public function testLoggedInCheck() {
345361
$this->securityCheck(__FUNCTION__, 'isLoggedIn');
@@ -349,7 +365,7 @@ public function testLoggedInCheck() {
349365
* @NoCSRFRequired
350366
* @NoAdminRequired
351367
* @throws SecurityException
352-
* @throws \ReflectionException
368+
* @throws ReflectionException
353369
*/
354370
public function testFailLoggedInCheck() {
355371
$this->securityCheck(__FUNCTION__, 'isLoggedIn', true);
@@ -358,7 +374,7 @@ public function testFailLoggedInCheck() {
358374
/**
359375
* @NoCSRFRequired
360376
* @throws SecurityException
361-
* @throws \ReflectionException
377+
* @throws ReflectionException
362378
*/
363379
public function testIsAdminCheck() {
364380
$this->securityCheck(__FUNCTION__, 'isAdminUser');
@@ -367,7 +383,7 @@ public function testIsAdminCheck() {
367383
/**
368384
* @NoCSRFRequired
369385
* @throws SecurityException
370-
* @throws \ReflectionException
386+
* @throws ReflectionException
371387
*/
372388
public function testFailIsAdminCheck() {
373389
$this->securityCheck(__FUNCTION__, 'isAdminUser', true);

0 commit comments

Comments
 (0)