File tree Expand file tree Collapse file tree 1 file changed +53
-0
lines changed
tests/Unit/Http/Middleware/Api/Admin Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Tests \Unit \Http \Middleware \Api \Admin ;
4+
5+ use Tests \Unit \Http \Middleware \MiddlewareTestCase ;
6+ use Pterodactyl \Http \Middleware \Api \Admin \AuthenticateUser ;
7+
8+ class AuthenticateUserTest extends MiddlewareTestCase
9+ {
10+ /**
11+ * Test that no user defined results in an access denied exception.
12+ *
13+ * @expectedException \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
14+ */
15+ public function testNoUserDefined ()
16+ {
17+ $ this ->setRequestUserModel (null );
18+
19+ $ this ->getMiddleware ()->handle ($ this ->request , $ this ->getClosureAssertions ());
20+ }
21+
22+ /**
23+ * Test that a non-admin user results an an exception.
24+ *
25+ * @expectedException \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
26+ */
27+ public function testNonAdminUser ()
28+ {
29+ $ this ->generateRequestUserModel (['root_admin ' => false ]);
30+
31+ $ this ->getMiddleware ()->handle ($ this ->request , $ this ->getClosureAssertions ());
32+ }
33+
34+ /**
35+ * Test that an admin user continues though the middleware.
36+ */
37+ public function testAdminUser ()
38+ {
39+ $ this ->generateRequestUserModel (['root_admin ' => true ]);
40+
41+ $ this ->getMiddleware ()->handle ($ this ->request , $ this ->getClosureAssertions ());
42+ }
43+
44+ /**
45+ * Return an instance of the middleware for testing.
46+ *
47+ * @return \Pterodactyl\Http\Middleware\Api\Admin\AuthenticateUser
48+ */
49+ private function getMiddleware (): AuthenticateUser
50+ {
51+ return new AuthenticateUser ;
52+ }
53+ }
You can’t perform that action at this time.
0 commit comments