Files
pterodactyl-panel/tests/Unit/Http/Middleware/Api/Application/AuthenticateUserTest.php
T
6c0413e39b Start 2.0 development
Co-authored-by: Anthony <anthony@infraly.co>
Co-authored-by: Sky Mulley <daniel.mulley@outlook.com>
2026-10-05 18:10:18 -04:00

33 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Pterodactyl\Tests\Pest\Unit\Http\Middleware\Api\Application\AuthenticateUserTest;
use Pterodactyl\Http\Middleware\Api\Application\AuthenticateApplicationUser;
use Pterodactyl\Tests\Unit\Http\Middleware\MiddlewareTestCase;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
uses(MiddlewareTestCase::class);
test('no user defined', function () {
$this->expectException(AccessDeniedHttpException::class);
$this->setRequestUserModel(null);
getMiddleware()->handle($this->request, $this->getClosureAssertions());
});
test('non admin user', function () {
$this->expectException(AccessDeniedHttpException::class);
$this->generateRequestUserModel(['root_admin' => false]);
getMiddleware()->handle($this->request, $this->getClosureAssertions());
});
test('admin user', function () {
$this->generateRequestUserModel(['root_admin' => true]);
getMiddleware()->handle($this->request, $this->getClosureAssertions());
});
/**
* Return an instance of the middleware for testing.
*/
function getMiddleware(): AuthenticateApplicationUser
{
return new AuthenticateApplicationUser();
}