Path: blob/1.0-develop/tests/Unit/Http/Middleware/Api/Application/AuthenticateUserTest.php
7461 views
<?php12namespace Pterodactyl\Tests\Unit\Http\Middleware\Api\Application;34use Pterodactyl\Tests\Unit\Http\Middleware\MiddlewareTestCase;5use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;6use Pterodactyl\Http\Middleware\Api\Application\AuthenticateApplicationUser;78class AuthenticateUserTest extends MiddlewareTestCase9{10/**11* Test that no user defined results in an access denied exception.12*/13public function testNoUserDefined()14{15$this->expectException(AccessDeniedHttpException::class);1617$this->setRequestUserModel(null);1819$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());20}2122/**23* Test that a non-admin user results in an exception.24*/25public function testNonAdminUser()26{27$this->expectException(AccessDeniedHttpException::class);2829$this->generateRequestUserModel(['root_admin' => false]);3031$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());32}3334/**35* Test that an admin user continues though the middleware.36*/37public function testAdminUser()38{39$this->generateRequestUserModel(['root_admin' => true]);4041$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());42}4344/**45* Return an instance of the middleware for testing.46*/47private function getMiddleware(): AuthenticateApplicationUser48{49return new AuthenticateApplicationUser();50}51}525354