Skip to content

Commit c59d3a9

Browse files
committed
Add test for new middleware
1 parent c3b9738 commit c59d3a9

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
}

0 commit comments

Comments
 (0)