2017-11-03 23:16:49 +00:00
|
|
|
<?php
|
|
|
|
|
2021-01-23 20:09:16 +00:00
|
|
|
namespace Pterodactyl\Tests\Unit\Http\Middleware;
|
2017-11-03 23:16:49 +00:00
|
|
|
|
2020-06-24 04:59:37 +00:00
|
|
|
use Illuminate\Auth\AuthenticationException;
|
2017-11-03 23:16:49 +00:00
|
|
|
use Pterodactyl\Http\Middleware\Authenticate;
|
|
|
|
|
|
|
|
class AuthenticateTest extends MiddlewareTestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test that a logged in user validates correctly.
|
|
|
|
*/
|
|
|
|
public function testLoggedInUser()
|
|
|
|
{
|
|
|
|
$this->request->shouldReceive('user')->withNoArgs()->once()->andReturn(true);
|
|
|
|
|
|
|
|
$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-11-05 18:38:39 +00:00
|
|
|
* Test that a logged out user results in an exception.
|
2017-11-03 23:16:49 +00:00
|
|
|
*/
|
2017-11-05 18:38:39 +00:00
|
|
|
public function testLoggedOutUser()
|
2017-11-03 23:16:49 +00:00
|
|
|
{
|
2020-06-24 04:59:37 +00:00
|
|
|
$this->expectException(AuthenticationException::class);
|
|
|
|
|
2017-11-03 23:16:49 +00:00
|
|
|
$this->request->shouldReceive('user')->withNoArgs()->once()->andReturnNull();
|
|
|
|
|
|
|
|
$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an instance of the middleware using mocked dependencies.
|
|
|
|
*
|
|
|
|
* @return \Pterodactyl\Http\Middleware\Authenticate
|
|
|
|
*/
|
|
|
|
private function getMiddleware(): Authenticate
|
|
|
|
{
|
|
|
|
return new Authenticate();
|
|
|
|
}
|
|
|
|
}
|