Fix test to run with new bootstrapping
This commit is contained in:
parent
e8ea218f20
commit
ac9f83a8fe
3 changed files with 10 additions and 38 deletions
|
@ -9,19 +9,14 @@
|
||||||
|
|
||||||
namespace Pterodactyl\Services\Helpers;
|
namespace Pterodactyl\Services\Helpers;
|
||||||
|
|
||||||
|
use Ramsey\Uuid\Uuid;
|
||||||
use Illuminate\Contracts\Hashing\Hasher;
|
use Illuminate\Contracts\Hashing\Hasher;
|
||||||
use Illuminate\Database\ConnectionInterface;
|
use Illuminate\Database\ConnectionInterface;
|
||||||
use Illuminate\Contracts\Config\Repository as ConfigRepository;
|
|
||||||
|
|
||||||
class TemporaryPasswordService
|
class TemporaryPasswordService
|
||||||
{
|
{
|
||||||
const HMAC_ALGO = 'sha256';
|
const HMAC_ALGO = 'sha256';
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \Illuminate\Contracts\Config\Repository
|
|
||||||
*/
|
|
||||||
protected $config;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Illuminate\Database\ConnectionInterface
|
* @var \Illuminate\Database\ConnectionInterface
|
||||||
*/
|
*/
|
||||||
|
@ -35,16 +30,11 @@ class TemporaryPasswordService
|
||||||
/**
|
/**
|
||||||
* TemporaryPasswordService constructor.
|
* TemporaryPasswordService constructor.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Contracts\Config\Repository $config
|
|
||||||
* @param \Illuminate\Database\ConnectionInterface $connection
|
* @param \Illuminate\Database\ConnectionInterface $connection
|
||||||
* @param \Illuminate\Contracts\Hashing\Hasher $hasher
|
* @param \Illuminate\Contracts\Hashing\Hasher $hasher
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(ConnectionInterface $connection, Hasher $hasher)
|
||||||
ConfigRepository $config,
|
{
|
||||||
ConnectionInterface $connection,
|
|
||||||
Hasher $hasher
|
|
||||||
) {
|
|
||||||
$this->config = $config;
|
|
||||||
$this->connection = $connection;
|
$this->connection = $connection;
|
||||||
$this->hasher = $hasher;
|
$this->hasher = $hasher;
|
||||||
}
|
}
|
||||||
|
@ -57,7 +47,7 @@ class TemporaryPasswordService
|
||||||
*/
|
*/
|
||||||
public function handle($email)
|
public function handle($email)
|
||||||
{
|
{
|
||||||
$token = hash_hmac(self::HMAC_ALGO, str_random(40), $this->config->get('app.key'));
|
$token = hash_hmac(self::HMAC_ALGO, Uuid::uuid4()->toString(), config('app.key'));
|
||||||
|
|
||||||
$this->connection->table('password_resets')->insert([
|
$this->connection->table('password_resets')->insert([
|
||||||
'email' => $email,
|
'email' => $email,
|
||||||
|
|
|
@ -10,8 +10,8 @@
|
||||||
processIsolation="false"
|
processIsolation="false"
|
||||||
stopOnFailure="false">
|
stopOnFailure="false">
|
||||||
<testsuites>
|
<testsuites>
|
||||||
<testsuite name="Feature">
|
<testsuite name="Integration">
|
||||||
<directory suffix="Test.php">./tests/Feature</directory>
|
<directory suffix="Test.php">./tests/Integration</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
<testsuite name="Unit">
|
<testsuite name="Unit">
|
||||||
<directory suffix="Test.php">./tests/Unit</directory>
|
<directory suffix="Test.php">./tests/Unit</directory>
|
||||||
|
|
|
@ -1,30 +1,17 @@
|
||||||
<?php
|
<?php
|
||||||
/*
|
|
||||||
* Pterodactyl - Panel
|
|
||||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
||||||
*
|
|
||||||
* This software is licensed under the terms of the MIT license.
|
|
||||||
* https://opensource.org/licenses/MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Tests\Unit\Services\Helpers;
|
namespace Tests\Unit\Services\Helpers;
|
||||||
|
|
||||||
use Mockery as m;
|
use Mockery as m;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
use phpmock\phpunit\PHPMock;
|
use Tests\Traits\MocksUuids;
|
||||||
use Illuminate\Contracts\Hashing\Hasher;
|
use Illuminate\Contracts\Hashing\Hasher;
|
||||||
use Illuminate\Contracts\Config\Repository;
|
|
||||||
use Illuminate\Database\ConnectionInterface;
|
use Illuminate\Database\ConnectionInterface;
|
||||||
use Pterodactyl\Services\Helpers\TemporaryPasswordService;
|
use Pterodactyl\Services\Helpers\TemporaryPasswordService;
|
||||||
|
|
||||||
class TemporaryPasswordServiceTest extends TestCase
|
class TemporaryPasswordServiceTest extends TestCase
|
||||||
{
|
{
|
||||||
use PHPMock;
|
use MocksUuids;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \Illuminate\Contracts\Config\Repository|\Mockery\Mock
|
|
||||||
*/
|
|
||||||
protected $config;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Illuminate\Database\ConnectionInterface|\Mockery\Mock
|
* @var \Illuminate\Database\ConnectionInterface|\Mockery\Mock
|
||||||
|
@ -48,11 +35,10 @@ class TemporaryPasswordServiceTest extends TestCase
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->config = m::mock(Repository::class);
|
|
||||||
$this->connection = m::mock(ConnectionInterface::class);
|
$this->connection = m::mock(ConnectionInterface::class);
|
||||||
$this->hasher = m::mock(Hasher::class);
|
$this->hasher = m::mock(Hasher::class);
|
||||||
|
|
||||||
$this->service = new TemporaryPasswordService($this->config, $this->connection, $this->hasher);
|
$this->service = new TemporaryPasswordService($this->connection, $this->hasher);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -60,11 +46,7 @@ class TemporaryPasswordServiceTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testTemporaryPasswordIsStored()
|
public function testTemporaryPasswordIsStored()
|
||||||
{
|
{
|
||||||
$this->getFunctionMock('\\Pterodactyl\\Services\\Helpers', 'str_random')
|
$token = hash_hmac(TemporaryPasswordService::HMAC_ALGO, $this->getKnownUuid(), config('app.key'));
|
||||||
->expects($this->once())->with(40)->willReturn('random_string');
|
|
||||||
|
|
||||||
$this->config->shouldReceive('get')->with('app.key')->once()->andReturn('123456');
|
|
||||||
$token = hash_hmac(TemporaryPasswordService::HMAC_ALGO, 'random_string', '123456');
|
|
||||||
|
|
||||||
$this->hasher->shouldReceive('make')->with($token)->once()->andReturn('hashed_token');
|
$this->hasher->shouldReceive('make')->with($token)->once()->andReturn('hashed_token');
|
||||||
$this->connection->shouldReceive('table')->with('password_resets')->once()->andReturnSelf();
|
$this->connection->shouldReceive('table')->with('password_resets')->once()->andReturnSelf();
|
||||||
|
|
Loading…
Reference in a new issue