2018-01-19 03:41:45 +00:00
|
|
|
<?php
|
|
|
|
|
2021-01-23 20:09:16 +00:00
|
|
|
namespace Pterodactyl\Tests\Unit\Http\Middleware\Api\Application;
|
2018-01-19 03:41:45 +00:00
|
|
|
|
2021-01-23 20:09:16 +00:00
|
|
|
use Pterodactyl\Tests\Unit\Http\Middleware\MiddlewareTestCase;
|
2020-06-24 04:59:37 +00:00
|
|
|
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
2018-02-25 21:30:56 +00:00
|
|
|
use Pterodactyl\Http\Middleware\Api\Application\AuthenticateApplicationUser;
|
2018-01-19 03:41:45 +00:00
|
|
|
|
|
|
|
class AuthenticateUserTest extends MiddlewareTestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test that no user defined results in an access denied exception.
|
|
|
|
*/
|
|
|
|
public function testNoUserDefined()
|
|
|
|
{
|
2020-06-24 04:59:37 +00:00
|
|
|
$this->expectException(AccessDeniedHttpException::class);
|
|
|
|
|
2018-01-19 03:41:45 +00:00
|
|
|
$this->setRequestUserModel(null);
|
|
|
|
|
|
|
|
$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-10-14 16:59:20 +00:00
|
|
|
* Test that a non-admin user results in an exception.
|
2018-01-19 03:41:45 +00:00
|
|
|
*/
|
|
|
|
public function testNonAdminUser()
|
|
|
|
{
|
2020-06-24 04:59:37 +00:00
|
|
|
$this->expectException(AccessDeniedHttpException::class);
|
|
|
|
|
2018-01-19 03:41:45 +00:00
|
|
|
$this->generateRequestUserModel(['root_admin' => false]);
|
|
|
|
|
|
|
|
$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that an admin user continues though the middleware.
|
|
|
|
*/
|
|
|
|
public function testAdminUser()
|
|
|
|
{
|
|
|
|
$this->generateRequestUserModel(['root_admin' => true]);
|
|
|
|
|
|
|
|
$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an instance of the middleware for testing.
|
|
|
|
*/
|
2018-02-25 21:30:56 +00:00
|
|
|
private function getMiddleware(): AuthenticateApplicationUser
|
2018-01-19 03:41:45 +00:00
|
|
|
{
|
2021-01-23 20:33:34 +00:00
|
|
|
return new AuthenticateApplicationUser();
|
2018-01-19 03:41:45 +00:00
|
|
|
}
|
|
|
|
}
|