misc_pterodactyl-panel/tests/Unit/Http/Middleware/Api/Application/AuthenticateUserTest.php

54 lines
1.5 KiB
PHP
Raw Normal View History

2018-01-19 03:41:45 +00:00
<?php
2018-01-20 02:00:28 +00:00
namespace Tests\Unit\Http\Middleware\Api\Application;
2018-01-19 03:41:45 +00:00
use Tests\Unit\Http\Middleware\MiddlewareTestCase;
2018-01-20 01:58:57 +00:00
use Pterodactyl\Http\Middleware\Api\Application\AuthenticateUser;
2018-01-19 03:41:45 +00:00
class AuthenticateUserTest extends MiddlewareTestCase
{
/**
* Test that no user defined results in an access denied exception.
*
* @expectedException \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
*/
public function testNoUserDefined()
{
$this->setRequestUserModel(null);
$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());
}
/**
* Test that a non-admin user results an an exception.
*
* @expectedException \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
*/
public function testNonAdminUser()
{
$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-01-20 01:58:57 +00:00
* @return \Pterodactyl\Http\Middleware\Api\Application\AuthenticateUser
2018-01-19 03:41:45 +00:00
*/
private function getMiddleware(): AuthenticateUser
{
return new AuthenticateUser;
}
}