First go at integration tests

This commit is contained in:
Dane Everitt 2018-03-04 16:30:16 -06:00
parent 89db9390df
commit e2aa01c9cc
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
16 changed files with 610 additions and 28 deletions

View file

@ -2,6 +2,7 @@
namespace Tests\Unit\Http\Middleware;
use Illuminate\Http\Request;
use Pterodactyl\Models\User;
use Pterodactyl\Http\Middleware\AdminAuthenticate;

View file

@ -29,12 +29,12 @@ class DaemonAuthenticateTest extends MiddlewareTestCase
*/
public function testValidDaemonConnection()
{
$this->setRequestRouteName('random.name');
$node = factory(Node::class)->make();
$this->request->shouldReceive('route->getName')->withNoArgs()->once()->andReturn('random.name');
$this->request->shouldReceive('header')->with('X-Access-Node')->twice()->andReturn($node->uuid);
$this->request->shouldReceive('header')->with('X-Access-Node')->twice()->andReturn($node->daemonSecret);
$this->repository->shouldReceive('findFirstWhere')->with(['daemonSecret' => $node->uuid])->once()->andReturn($node);
$this->repository->shouldReceive('findFirstWhere')->with(['daemonSecret' => $node->daemonSecret])->once()->andReturn($node);
$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());
$this->assertRequestHasAttribute('node');
@ -46,7 +46,7 @@ class DaemonAuthenticateTest extends MiddlewareTestCase
*/
public function testIgnoredRouteShouldContinue()
{
$this->request->shouldReceive('route->getName')->withNoArgs()->once()->andReturn('daemon.configuration');
$this->setRequestRouteName('daemon.configuration');
$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());
$this->assertRequestMissingAttribute('node');
@ -59,7 +59,8 @@ class DaemonAuthenticateTest extends MiddlewareTestCase
*/
public function testExceptionThrownIfMissingHeader()
{
$this->request->shouldReceive('route->getName')->withNoArgs()->once()->andReturn('random.name');
$this->setRequestRouteName('random.name');
$this->request->shouldReceive('header')->with('X-Access-Node')->once()->andReturn(false);
$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());