2018-01-18 21:41:45 -06:00
|
|
|
<?php
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
declare(strict_types=1);
|
2018-01-18 21:41:45 -06:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
namespace Pterodactyl\Tests\Pest\Unit\Http\Middleware\Api\Application\AuthenticateUserTest;
|
|
|
|
|
|
|
|
|
|
use Pterodactyl\Http\Middleware\Api\Application\AuthenticateApplicationUser;
|
2021-01-23 12:09:16 -08:00
|
|
|
use Pterodactyl\Tests\Unit\Http\Middleware\MiddlewareTestCase;
|
2020-06-23 21:59:37 -07:00
|
|
|
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
2018-01-18 21:41:45 -06:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
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
|
2018-01-18 21:41:45 -06:00
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
return new AuthenticateApplicationUser();
|
2018-01-18 21:41:45 -06:00
|
|
|
}
|