More test suite coverage

This commit is contained in:
Dane Everitt 2017-09-26 22:16:26 -05:00
parent 8908a758ca
commit 774c9680a3
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
14 changed files with 373 additions and 46 deletions

View file

@ -83,7 +83,7 @@ class DaemonKeyProviderService
['server_id', '=', $server],
]);
if (! $updateIfExpired || max($this->carbon->now()->diffInSeconds($key->expires_at, false), 0) > 0) {
if (! $updateIfExpired || $this->carbon->now()->diffInSeconds($key->expires_at, false) > 0) {
return $key->secret;
}

View file

@ -10,22 +10,22 @@
namespace Pterodactyl\Services\Helpers;
use Illuminate\Contracts\Hashing\Hasher;
use Illuminate\Database\DatabaseManager;
use Illuminate\Config\Repository as ConfigRepository;
use Illuminate\Database\ConnectionInterface;
use Illuminate\Contracts\Config\Repository as ConfigRepository;
class TemporaryPasswordService
{
const HMAC_ALGO = 'sha256';
/**
* @var \Illuminate\Config\Repository
* @var \Illuminate\Contracts\Config\Repository
*/
protected $config;
/**
* @var \Illuminate\Database\DatabaseManager
* @var \Illuminate\Database\ConnectionInterface
*/
protected $database;
protected $connection;
/**
* @var \Illuminate\Contracts\Hashing\Hasher
@ -35,17 +35,17 @@ class TemporaryPasswordService
/**
* TemporaryPasswordService constructor.
*
* @param \Illuminate\Config\Repository $config
* @param \Illuminate\Database\DatabaseManager $database
* @param \Illuminate\Contracts\Hashing\Hasher $hasher
* @param \Illuminate\Contracts\Config\Repository $config
* @param \Illuminate\Database\ConnectionInterface $connection
* @param \Illuminate\Contracts\Hashing\Hasher $hasher
*/
public function __construct(
ConfigRepository $config,
DatabaseManager $database,
ConnectionInterface $connection,
Hasher $hasher
) {
$this->config = $config;
$this->database = $database;
$this->connection = $connection;
$this->hasher = $hasher;
}
@ -55,11 +55,11 @@ class TemporaryPasswordService
* @param string $email
* @return string
*/
public function generateReset($email)
public function handle($email)
{
$token = hash_hmac(self::HMAC_ALGO, str_random(40), $this->config->get('app.key'));
$this->database->table('password_resets')->insert([
$this->connection->table('password_resets')->insert([
'email' => $email,
'token' => $this->hasher->make($token),
]);

View file

@ -17,14 +17,24 @@ use Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface;
class ProcessScheduleService
{
/**
* @var \Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface
*/
protected $repository;
/**
* @var \Pterodactyl\Services\Schedules\Tasks\RunTaskService
*/
protected $runnerService;
public function __construct(
RunTaskService $runnerService,
ScheduleRepositoryInterface $repository
) {
/**
* ProcessScheduleService constructor.
*
* @param \Pterodactyl\Services\Schedules\Tasks\RunTaskService $runnerService
* @param \Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface $repository
*/
public function __construct(RunTaskService $runnerService, ScheduleRepositoryInterface $repository)
{
$this->repository = $repository;
$this->runnerService = $runnerService;
}

View file

@ -10,16 +10,13 @@
namespace Pterodactyl\Services\Schedules\Tasks;
use Pterodactyl\Models\Task;
use Illuminate\Contracts\Bus\Dispatcher;
use Pterodactyl\Jobs\Schedule\RunTaskJob;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Pterodactyl\Contracts\Repository\TaskRepositoryInterface;
class RunTaskService
{
/**
* @var \Illuminate\Contracts\Bus\Dispatcher
*/
protected $dispatcher;
use DispatchesJobs;
/**
* @var \Pterodactyl\Contracts\Repository\TaskRepositoryInterface
@ -29,14 +26,10 @@ class RunTaskService
/**
* RunTaskService constructor.
*
* @param \Illuminate\Contracts\Bus\Dispatcher $dispatcher
* @param \Pterodactyl\Contracts\Repository\TaskRepositoryInterface $repository
*/
public function __construct(
Dispatcher $dispatcher,
TaskRepositoryInterface $repository
) {
$this->dispatcher = $dispatcher;
public function __construct(TaskRepositoryInterface $repository)
{
$this->repository = $repository;
}
@ -55,6 +48,6 @@ class RunTaskService
}
$this->repository->update($task->id, ['is_queued' => true]);
$this->dispatcher->dispatch((new RunTaskJob($task->id, $task->schedule_id))->delay($task->time_offset));
$this->dispatch((new RunTaskJob($task->id, $task->schedule_id))->delay($task->time_offset));
}
}

View file

@ -93,7 +93,7 @@ class UserCreationService
$this->connection->beginTransaction();
if (! isset($data['password']) || empty($data['password'])) {
$data['password'] = $this->hasher->make(str_random(30));
$token = $this->passwordService->generateReset($data['email']);
$token = $this->passwordService->handle($data['email']);
}
$user = $this->repository->create($data);