2017-09-03 21:32:52 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Unit\Http\Controllers\Server\Files;
|
|
|
|
|
|
|
|
use Mockery as m;
|
|
|
|
use Pterodactyl\Models\Node;
|
2018-03-03 01:37:21 +00:00
|
|
|
use Tests\Traits\MocksUuids;
|
2017-09-03 21:32:52 +00:00
|
|
|
use Pterodactyl\Models\Server;
|
2017-09-03 21:41:03 +00:00
|
|
|
use Illuminate\Cache\Repository;
|
2017-11-03 21:43:28 +00:00
|
|
|
use Tests\Unit\Http\Controllers\ControllerTestCase;
|
2017-09-03 21:41:03 +00:00
|
|
|
use Pterodactyl\Http\Controllers\Server\Files\DownloadController;
|
2017-09-03 21:32:52 +00:00
|
|
|
|
2017-11-03 21:43:28 +00:00
|
|
|
class DownloadControllerTest extends ControllerTestCase
|
2017-09-03 21:32:52 +00:00
|
|
|
{
|
2018-03-03 01:37:21 +00:00
|
|
|
use MocksUuids;
|
2017-09-03 21:32:52 +00:00
|
|
|
|
|
|
|
/**
|
2017-11-03 21:43:28 +00:00
|
|
|
* @var \Illuminate\Cache\Repository|\Mockery\Mock
|
2017-09-03 21:32:52 +00:00
|
|
|
*/
|
|
|
|
protected $cache;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup tests.
|
|
|
|
*/
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->cache = m::mock(Repository::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the download controller redirects correctly.
|
|
|
|
*/
|
|
|
|
public function testIndexController()
|
|
|
|
{
|
2017-11-03 21:43:28 +00:00
|
|
|
$controller = $this->getController();
|
2017-09-03 21:32:52 +00:00
|
|
|
$server = factory(Server::class)->make();
|
2017-11-03 21:43:28 +00:00
|
|
|
$server->setRelation('node', factory(Node::class)->make());
|
2017-09-03 21:32:52 +00:00
|
|
|
|
2017-11-03 21:43:28 +00:00
|
|
|
$this->setRequestAttribute('server', $server);
|
|
|
|
|
|
|
|
$controller->shouldReceive('authorize')->with('download-files', $server)->once()->andReturnNull();
|
2017-09-03 21:32:52 +00:00
|
|
|
|
2018-03-03 01:37:21 +00:00
|
|
|
$this->cache->shouldReceive('put')
|
|
|
|
->once()
|
|
|
|
->with('Server:Downloads:' . $this->getKnownUuid(), ['server' => $server->uuid, 'path' => '/my/file.txt'], 5)
|
|
|
|
->andReturnNull();
|
2017-09-03 21:32:52 +00:00
|
|
|
|
2017-11-03 21:43:28 +00:00
|
|
|
$response = $controller->index($this->request, $server->uuidShort, '/my/file.txt');
|
2017-09-03 21:32:52 +00:00
|
|
|
$this->assertIsRedirectResponse($response);
|
|
|
|
$this->assertRedirectUrlEquals(sprintf(
|
2018-03-03 01:37:21 +00:00
|
|
|
'%s://%s:%s/v1/server/file/download/%s',
|
|
|
|
$server->node->scheme,
|
|
|
|
$server->node->fqdn,
|
|
|
|
$server->node->daemonListen,
|
|
|
|
$this->getKnownUuid()
|
2017-09-03 21:32:52 +00:00
|
|
|
), $response);
|
|
|
|
}
|
2017-11-03 21:43:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a mocked instance of the controller to allow access to authorization functionality.
|
|
|
|
*
|
|
|
|
* @return \Pterodactyl\Http\Controllers\Server\Files\DownloadController|\Mockery\Mock
|
|
|
|
*/
|
|
|
|
private function getController()
|
|
|
|
{
|
|
|
|
return $this->buildMockedController(DownloadController::class, [$this->cache]);
|
|
|
|
}
|
2017-09-03 21:32:52 +00:00
|
|
|
}
|