Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/tests/Unit/Http/Middleware/Api/Application/AuthenticateUserTest.php
7461 views
1
<?php
2
3
namespace Pterodactyl\Tests\Unit\Http\Middleware\Api\Application;
4
5
use Pterodactyl\Tests\Unit\Http\Middleware\MiddlewareTestCase;
6
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
7
use Pterodactyl\Http\Middleware\Api\Application\AuthenticateApplicationUser;
8
9
class AuthenticateUserTest extends MiddlewareTestCase
10
{
11
/**
12
* Test that no user defined results in an access denied exception.
13
*/
14
public function testNoUserDefined()
15
{
16
$this->expectException(AccessDeniedHttpException::class);
17
18
$this->setRequestUserModel(null);
19
20
$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());
21
}
22
23
/**
24
* Test that a non-admin user results in an exception.
25
*/
26
public function testNonAdminUser()
27
{
28
$this->expectException(AccessDeniedHttpException::class);
29
30
$this->generateRequestUserModel(['root_admin' => false]);
31
32
$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());
33
}
34
35
/**
36
* Test that an admin user continues though the middleware.
37
*/
38
public function testAdminUser()
39
{
40
$this->generateRequestUserModel(['root_admin' => true]);
41
42
$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());
43
}
44
45
/**
46
* Return an instance of the middleware for testing.
47
*/
48
private function getMiddleware(): AuthenticateApplicationUser
49
{
50
return new AuthenticateApplicationUser();
51
}
52
}
53
54